Udemy Playwright: Web Automation Testing From Zero to Hero: Difference between revisions

Jump to navigation Jump to search
m
Line 305: Line 305:


=== Timeouts ===
=== Timeouts ===
* 3 layers
<nowiki>
test("timeouts", async ({ page }) => {
  //test.setTimeout(10000)
  test.slow()
  const successButton = page.locator(".bg-success")
  await successButton.click()
})</nowiki>


==== Global Timeout ====
There are three layers to timeouts
: time limit for whole test suite to run
 
==== 1. Global Timeout ====
time limit for whole test suite to run
: default: no limit
: default: no limit


====Test Timeout====
==== 2. Test Timeout====
:Within the global timeout, it is the time limit for a single test
Within the global timeout, it is the time limit for a single test
: default: 30000ms
: default: 30000ms


====Action, Navigation, Expect====
==== 3. Action, Navigation, Expect====
: Withing the global and test timeout there are the following timeouts
Within the global and test timeout there are the following timeouts
 
* Action = click(), fill(), textContent() etc
: default: no limit
 
* Navigation = page.goto(url...)
: default: no limit
 
* Expect = locator assertions
: default: 5000ms
: Note: regular expect assertions execute immediately, only locator exceptions will wait.
: You can override the expect timeout <code>await expect(element).toHaveText("some text", { timeout: 20000 })</code>


:* Action = click(), fill(), textContent() etc
====Overrides inside test case ====
:: default: no limit
Use <code>test.slow()</code> to extend timeout to 3x configured value, or <code>test.setTimeout(10000)</code>.


:* Navigation = page.goto(url...)
==== Project Timeout settings in <code>playwright.config.ts</code>====
:: default: no limit
<nowiki>
export default defineConfig({
  timeout: 10000,  // test case max run time
  globalTimeout: 60000,  // entire test run max run time
  expect:{
    timeout: 2000, // sets locator assertion timeout
  },
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    actionTimeout: 5000,
    navigationTimeout: 5000,
  },
  ...
});</nowiki>


:* Expect = locator assertions
==== Timeout settings for a whole spec.ts file ====
:: default: 5000ms
<nowiki>
:: Note: regular expect assertions execute immediately, only locator exceptions will wait.
test.beforeEach(async ({ page }, testInfo) => {
  await page.goto("http://uitestingplayground.com/ajax")
  await page.getByText("Button Triggering AJAX Request").click()
  testInfo.setTimeout(testInfo.timeout + 2000)
})</nowiki>

Navigation menu