Created
April 4, 2024 13:42
-
-
Save rajeshdavidbabu/4aa3516f52ada7c27b8d87935c238973 to your computer and use it in GitHub Desktop.
Sample Autoplaywright Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { test, expect } from "@playwright/test"; | |
import { auto } from "auto-playwright"; | |
test("auto add items to shopping cart", async ({ page }) => { | |
test.setTimeout(120000); | |
await page.goto("https://getyourfckingsocks.com/about/"); | |
await page.waitForLoadState("domcontentloaded"); | |
// `auto` can query data | |
// In this case, the result is plain-text contents of the header | |
await auto( | |
"click on the shop link on the navigation bar", | |
{ page, test }, | |
{ debug: true } | |
); | |
await page.waitForLoadState("domcontentloaded"); | |
await auto( | |
"add product with id 5 to the cart", | |
{ page, test }, | |
{ debug: true } | |
); | |
await auto("click on the cart link", { page, test }, { debug: true }); | |
await page.waitForLoadState("domcontentloaded"); | |
const itemsInTheCart = await auto( | |
"How many items are in the cart?", | |
{ page, test }, | |
{ debug: true } | |
); | |
console.log("itemsInTheCart ", itemsInTheCart); | |
// Expect a title "to contain" a substring. | |
expect(Number(itemsInTheCart)).toBe(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment