Udemy Playwright: Web Automation Testing From Zero to Hero: Difference between revisions
Jump to navigation
Jump to search
Udemy Playwright: Web Automation Testing From Zero to Hero (view source)
Revision as of 21:26, 23 May 2024
, 23 May→Timeouts
m (→Timeouts) |
m (→Timeouts) |
||
Line 305: | Line 305: | ||
=== Timeouts === | === Timeouts === | ||
<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 | ||
==== 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 | |||
: default: 30000ms | : default: 30000ms | ||
====Action, Navigation, Expect==== | ==== 3. Action, Navigation, Expect==== | ||
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> | |||
====Overrides inside test case ==== | |||
Use <code>test.slow()</code> to extend timeout to 3x configured value, or <code>test.setTimeout(10000)</code>. | |||
==== Project Timeout settings in <code>playwright.config.ts</code>==== | |||
:: | <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> | |||
==== Timeout settings for a whole spec.ts file ==== | |||
: | <nowiki> | ||
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> |