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

Jump to navigation Jump to search
m
Line 199: Line 199:
I think I like best the last one, where you select something that looks like a heading to the user, and then go to the parent that contains the selected element, and the element you want to locate.  
I think I like best the last one, where you select something that looks like a heading to the user, and then go to the parent that contains the selected element, and the element you want to locate.  


==== x ====
=== Reusing Locators ===
Stop copying and pasting code ....
<nowiki>
  const testEmailAddress = "test@test.com"
  const basicForm = page.locator("nb-card").filter({ hasText: "Basic Form" })
  const emailField = basicForm.getByRole("textbox", { name: "Email" })
 
 
  await emailField.fill(testEmailAddress)
  await basicForm.getByRole("textbox", { name: "Password" }).fill("Welcome123")
  await basicForm.getByRole("button").click()
 
  await expect(emailField).toHaveValue(testEmailAddress)</nowiki>
 
=== Extracting Values ===

Navigation menu