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

Jump to navigation Jump to search
m
Line 1,706: Line 1,706:


=== Fixtures ===
=== Fixtures ===
* Power tool to setup the test environment
* custom fixtures extend the base test object
* you can auto load fixtures
* you can create dependencies between fixtures
* you can also specify tear down code
Update file <code>test-options.ts</code>
<nowiki>
import { test as base } from "@playwright/test"
import { PageManager } from "./page-objects/pageManager"
export type TestOptions = {
  globalsQaURL: string
  formLayoutsPage: string
  pageManager: PageManager
}
export const test = base.extend<TestOptions>({
  globalsQaURL: ["", { option: true }],
  formLayoutsPage: async ({ page }, use) => {
    await page.goto("/")
    await page.getByText("Forms").click()
    await page.getByText("Form Layouts").click()
    await use("")
    console.log('Tear Down formLayoutsPage')
  },
  // { auto: true }],
  pageManager: async ({ page, formLayoutsPage }, use) => {  // pageManager depends on formLayoutsPage
    const pm = new PageManager(page)
    await use(pm)
    console.log('Tear Down pageManager')
  },
})</nowiki>
Create new file <code>tests\testWithFictures.spec.ts</code>
<nowiki>
import { test } from "../test-options"
import { faker } from "@faker-js/faker"
//test("parameterised methods", async ({ page, formLayoutsPage }) => { // using formLayoutsPage fixture
//test("parameterised methods", async ({ page }) => {      // using {auto:true} in formLayoutsPage fixture
test("parameterised methods", async ({ pageManager }) => {  // using new pageManager fixture
  const randomFullName = faker.person.fullName()
  const randomEmail = `${randomFullName.replace(/ /g, "")}${faker.number.int(
    1000
  )}@test.com`
  await pageManager
    .onFormLayoutsPage()
    .submitUsingTheGridFormWithCredentialsAndSelectOption(
      process.env.TESTUSERNAME,
      process.env.PASSWORD,
      "Option 2"
    )
  await pageManager
    .onFormLayoutsPage()
    .submitInLineFormWithNameEmailAndCheckbox(randomFullName, randomEmail, true)
})</nowiki>
=== Project Setup and Teardown ===
=== Project Setup and Teardown ===
=== Test Tags ===
=== Test Tags ===

Navigation menu