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

Jump to navigation Jump to search
m
Line 254: Line 254:
   await basicFormButton.click()</nowiki>
   await basicFormButton.click()</nowiki>


=== Auto Waiting ===
=== Auto-waiting ===
* [https://playwright.dev/docs/actionability Playwright docs]
 
There are some different wait topologies
 
some auto-wait for 30s by default (but configurable
 
expect() waits for only 5s
 
some do not wait at all
 
and there's a bunch of alternative waitFor methods, eg. wait for a response to an API call
 
<nowiki>
test.beforeEach(async ({ page }) => {
  await page.goto("http://uitestingplayground.com/ajax")
  await page.getByText("Button Triggering AJAX Request").click()
})
 
test("Auto Waiting", async ({ page }) => {
  const successButton = page.locator(".bg-success")
 
  //  const text = await successButton.textContent()  // waits automatically (upto default 30s)
  //  expect(text).toEqual('Data loaded with AJAX get request.')
 
  //  await successButton.waitFor({state: 'attached'}) // waits upto default 30s
  //  const text2 = await successButton.allTextContents() // fails doesn't wait by itself (must use waitFor(...))
  //  expect(text2).toContain('Data loaded with AJAX get request.')
 
  await expect(successButton).toHaveText("Data loaded with AJAX get request.", {
    timeout: 20000,
  }) // waits default  upto 5s, unless overridden
})
 
test("alternative waits", async ({ page }) => {
  const successButton = page.locator(".bg-success")
 
  // wait for element
  //await page.waitForSelector(".bg-success")
 
  // wait for particular response
  //await page.waitForResponse('http://uitestingplayground.com/ajaxdata')
 
  // wait for network calls to be completed (NOT RECOMMENDED)
  await page.waitForLoadState("networkidle")
 
  const text2 = await successButton.allTextContents()
  expect(text2).toContain("Data loaded with AJAX get request.")
})</nowiki>
 
=== Timeouts ===

Navigation menu