forked from anti-work/shortest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.test.ts
63 lines (57 loc) · 2.01 KB
/
google.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { shortest } from "@antiwork/shortest";
shortest.beforeAll(async ({ page }) => {
await page.goto("https://google.com");
const acceptButton = await page.$("[aria-label='Accept all']");
if (acceptButton) await acceptButton.click();
});
shortest.afterAll(async ({ page }) => {
const context = page.context();
await context.clearCookies();
});
shortest.beforeEach(async ({ page }) => {
await page.goto("https://google.com");
await page.waitForSelector("[aria-label='Search']");
});
// Basic search test with callback
shortest(
"Perform a Google search for 'shortest test framework'",
async ({ page }) => {
await page.getByLabel("Search").click();
await page.keyboard.type("shortest test framework");
await page.keyboard.press("Enter");
},
);
// Test with error handling and custom assertions
shortest("Test Google's error handling for invalid searches", {
searchQueries: ["@#$%^&*", "≈∆˚¬≤µµ˜∫", ""],
})
.expect("Enter special characters and verify error handling")
.expect("Check error message visibility", async ({ page }) => {
const errorMsg = await page
.getByRole("heading", { level: 1 })
.textContent();
expect(errorMsg).toContain("did not match any documents");
});
// Advanced search with multiple steps and payload
shortest("Test Google's advanced search features", {
searchParams: {
query: "javascript testing",
exactPhrase: "end to end testing",
excludeWords: "selenium",
fileType: "pdf",
lastUpdate: "past year",
},
})
.expect("Access advanced search")
.expect("Fill advanced search form with payload data")
.expect("Verify search results match criteria", async ({ page }) => {
const results = await page.$$(".g");
for (const result of results.slice(0, 5)) {
const text = (await result.textContent()) || "";
expect(text.toLowerCase()).toContain("pdf");
}
})
.after(async ({ page }) => {
await page.goto("https://google.com/preferences");
await page.getByRole("button", { name: "Reset" }).click();
});