← Back to Discord Forum

How to I change global expect timeout in playwright

Can you please help me how to I change global expect timeout in playwright ?

This thread is trying to answer question "How to change global expect timeout in Playwright when using it with Cucumber and JavaScript?"

12 replies

Yes, in the playwright.config.ts. You can configure it like this expect: { timeout: 30000 //global timeout in ms }


using playwright + cucumber + JavaScript flavour. Is above code work ?

it won't because there's no playwright config file for cucumber

and you won't be able to set default if jest expect does not provide such option

Thanks! How to configure global timeout option if it is playwright + cucumber + JavaScript flavour ?

This is the cucumber.conf.js file I have: const { Before, BeforeAll, After, AfterAll, setDefaultTimeout, Status } = require("@cucumber/cucumber") require('dotenv').config() let setBrowser = process.env.setBrowser setDefaultTimeout(60000)

use above setDefaultTimeout in cucumber.conf.js and this will set timeout default to 60 secs in all files

yes, but this sets out the timeout for the cucumber step. It does not impact each PW action.

I did not find an option, best is to file a feature request

is there a way to configure timeout to find a locator with page.locator() ?


page.locator doesn't find the locator


you need to call await page.locator(...).<something>() to actually do something with the locator


and those functions (e.g. fill(), click() etc) all take an optional timeout parameter


Configuring Global Expect Timeout in Playwright

You can easily adjust the global expect timeout in Playwright when working with Cucumber and JavaScript. This is done by modifying the playwright.config.ts file in your project.

First, find or create the playwright.config.ts file in your project's root directory.

Next, import the necessary modules:

import { defineConfig } from '@playwright/test';

Then, you'll want to export a default configuration object using defineConfig(). This is where you can set various properties for your tests. To specifically change the global expect timeout, add an expect property and set its timeout value to your desired duration in milliseconds:

export default defineConfig({
  expect: {
    timeout: 10000 // Set your desired timeout value here (e.g., 10 seconds)

This sets a new global timeout for all assertions made using Playwright's expect functions. The example above sets it to 10 seconds (10000 milliseconds), but feel free to adjust this value as needed.

Once you've made these changes, save and close the playwright.config.ts file. Now, whenever you use Playwright's expect functions in your Cucumber tests, they will follow this new global timeout setting.

Remember, if an assertion takes longer than the specified duration to complete, it will result in a test failure. So, adjust the value according to your needs. If you need more specific guidance, don't hesitate to consult the official documentation or community resources.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.