Rayrun
← Back to Discord Forum

Await and timeout is not waiting for the default length of time

I have set the timeouts in the config file to over 30s but when i try to do an expect it is failing before the element is present. Any help would be much appreciated.

This thread is trying to answer question "Why is the 'expect' function not waiting for the timeout set in the config file?"

5 replies
import { config } from "dotenv";

config();
/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
//dotenv.config({ path: './.env' })

/**
 * See https://playwright.dev/docs/test-configuration.
 */
module.exports = defineConfig({
  testDir: "./kuvaApp/tests",
  // Timeout is shared between all tests. Each test is given 60 seconds
  timeout: 30000 * 4,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText()`
     */
    timeout: 30000,
  },
  /* Run tests in files in parallel */
  fullyParallel: false,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    headless: true,
    baseURL: process.env.URL,
    trace: "on",
    screenshot: "on",
  },
  reporter: [
    ["list"],
    ["html", { open: "never" }],
    ["junit", { outputFile: "results.xml" }],
  ],

  /* Configure projects for major browsers */
  projects: [
    {
      name: "setup",
      testDir: "./",
      testMatch: "auth-setup.js",
    },
    {
      name: "chromium",
      use: {
        ...devices["Desktop Chrome"],
        storageState: "./playwright/.auth/loginUserAuth.json"},
        testMatch: "*.ui.spec.js",
        //dependencies: ["setup"],
    },
    // Api tests are run by sending requests to the server directly from Node.js without using a browser.
    {
      name: "api_tests",
      testMatch: "*.api.spec.js",
    }```

test code

const dashboard = new dashboardPage(page)
        await dashboard.organizationDropDown.click()
        await dashboard.selectOrganization.click()
        await page.locator(".MuiPopover-root > div").first().click()
        await page
          .locator('[data-id="camera-card"]')
          .filter({ hasText: /Scanning/ }, { timeout: 40000 })
          .isVisible();
        const organizationDropDown = dashboard.organizationDropDown.textContent()
        expect(await organizationDropDown).toBe('Testing')
    })```

error: 
```Error: expect(received).toBe(expected) // Object.is equality

    Expected: "Testing"
    Received: "Cenovus"

      27 |           .isVisible();
      28 |         const organizationDropDown = dashboard.organizationDropDown.textContent()
    > 29 |         expect(await organizationDropDown).toBe('Testing')
         |                                            ^
      30 |     })
      31 |
      32 |     test.skip('available cameras are displayed', async ({ page }) => {```

toBe is not an async retrying assertion, it evaluates values instantly

I think expect timeout in config applies to playwright's retrying assertions

Related Discord Threads

TwitterGitHubLinkedIn
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.