Skip to content

Commit 6904b7c

Browse files
updates
1 parent 2dd72f5 commit 6904b7c

29 files changed

+1727
-1248
lines changed

__checks__/PagetitleWrong.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const { test, expect } = require("@playwright/test");
2+
3+
test.describe("Check Page Title", () => {
4+
let page;
5+
6+
test.beforeAll(async ({ browser }) => {
7+
page = await browser.newPage();
8+
});
9+
10+
test("has title 'Compare Mortgages - Go.Compare'", async () => {
11+
const MAX_RETRIES = 3; // Retry up to 3 times
12+
let retries = 0;
13+
let success = false;
14+
15+
while (retries < MAX_RETRIES && !success) {
16+
try {
17+
console.log(`Attempt ${retries + 1}: Navigating to the page`);
18+
await page.goto("https://mortgage.gocompare.com/?utm_source=monitoring", {
19+
waitUntil: "networkidle",
20+
timeout: 60000, // Increase timeout to 60 seconds
21+
});
22+
23+
// Check for the intermediary page
24+
if (await page.locator('h1:has-text("Pardon Our Interruption")').isVisible()) {
25+
console.error("Blocked by intermediary page. Retrying...");
26+
retries++;
27+
continue;
28+
}
29+
30+
// Take a screenshot
31+
await page.screenshot({ path: `screenshot_attempt_${retries + 1}.png`, fullPage: true });
32+
33+
// Retrieve and validate the title
34+
const title = await page.title();
35+
console.log(`Page Title Retrieved: ${title}`);
36+
expect(title).toBe("Compare Mortgages - Go.Compare");
37+
success = true; // Test passed
38+
} catch (error) {
39+
console.error(`Error on attempt ${retries + 1}: ${error.message}`);
40+
retries++;
41+
}
42+
}
43+
44+
if (!success) {
45+
throw new Error("Failed to load the page or retrieve the correct title after multiple retries.");
46+
}
47+
});
48+
49+
test.afterAll(async () => {
50+
await page.close();
51+
});
52+
});

__checks__/api-mocking.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('Book has correct details', async ({ page }) => {
4+
await page.route('*/**/api/books/23', async route => {
5+
const response = await route.fetch();
6+
const json = await response.json();
7+
json.stock="10980982349082340892340"
8+
await route.fulfill({ response, json });
9+
});
10+
await page.goto('https://danube-webshop.herokuapp.com/books/23');
11+
//Removed for brevity: checks of the book's title, genre, etc.
12+
await expect(page.getByRole('button', { name: 'Add to cart' })).toBeVisible();
13+
await expect(page.locator('#app-content')).toContainText("Left in stock: 0");
14+
});

__checks__/example.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://playwright.dev/');
5+
6+
// Expect a title "to contain" a substring.
7+
await expect(page).toHaveTitle(/Playwright/);
8+
});
9+
10+
test('get started link', async ({ page }) => {
11+
await page.goto('https://playwright.dev/');
12+
13+
// Click the get started link.
14+
await page.getByRole('link', { name: 'Get started' }).click();
15+
16+
// Expects page to have a heading with the name of Installation.
17+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
18+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { expect, test } = require('@playwright/test')
2+
3+
test(`ordering a book`, async ({ browser }) => {
4+
//one Context for the user
5+
const userContext = await browser.newContext();
6+
const userPage = await userContext.newPage();
7+
const response = await userPage.goto('https://danube-webshop.herokuapp.com/books/1')
8+
9+
const adminContext = await browser.newContext();
10+
//use the admincontext to check that the book was ordered
11+
12+
// Test that the response did not fail
13+
expect(response.status(), 'should respond with correct status code').toBeLessThan(400)
14+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('intercept requests block', async ({ page }) => {
4+
// await page.route('**/*', (route) => {
5+
// return route.request().resourceType() === 'image'
6+
7+
// ? route.abort()
8+
9+
// : route.continue()
10+
11+
// })
12+
await page.goto('https://commons.wikimedia.org/wiki/Main_Page');
13+
await page.getByRole('searchbox', { name: 'Search Wikimedia Commons' }).click();
14+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).fill('egg');
15+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).press('Enter');
16+
await page.getByRole('searchbox', { name: 'Search Wikimedia Commons' }).first().click();
17+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).fill('owl');
18+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).press('Enter');
19+
await page.getByRole('searchbox', { name: 'Search Wikimedia Commons' }).first().click();
20+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).fill('Telephone booth');
21+
await page.getByRole('combobox', { name: 'Search Wikimedia Commons' }).press('Enter');
22+
await page.getByRole('link', { name: 'Telefonboks, andelslandsbyen' }).click();
23+
await page.locator('#file').getByRole('link', { name: 'File:Telefonboks,' }).click();
24+
await expect(page.getByRole('img')).toBeVisible();
25+
})

__checks__/page-reuse-spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test, expect, type Page } from '@playwright/test';
2+
3+
test.describe.configure({ mode: 'serial' });
4+
5+
let page: Page;
6+
7+
test.beforeAll(async ({ browser }) => {
8+
page = await browser.newPage();
9+
});
10+
11+
test.afterAll(async () => {
12+
await page.close();
13+
});
14+
15+
test('runs first', async () => {
16+
await page.goto('https://danube-webshop.herokuapp.com/');
17+
await page.getByText('Celsius').click();
18+
await expect(page.locator('#app-content')).toContainText('Genre: scifi');
19+
});
20+
21+
test('runs second', async () => {
22+
await expect(page.locator('#app-content')).toContainText('Left in stock: 1');
23+
});
24+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { test } from '@playwright/test'
2+
3+
test('intercept response', async ({ page }) => {
4+
const mockResponseObject = [
5+
{
6+
id: 1,
7+
title: 'How to Mock a Response',
8+
author: 'A. Friend',
9+
genre: 'business',
10+
price: '0.00',
11+
rating: '★★★★★',
12+
stock: 65535
13+
}
14+
]
15+
16+
await page.route('https://danube-web.shop/api/books', (route) =>
17+
route.fulfill({
18+
19+
contentType: 'application/json',
20+
21+
body: JSON.stringify(mockResponseObject)
22+
23+
})
24+
)
25+
26+
await page.goto('https://danube-web.shop/')
27+
await page.screenshot({ path: 'screenshot.png' })
28+
})

__checks__/wait-for-modal.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('test', async ({ page }) => {
4+
await page.goto('file:///Users/nica/xibalba/checkly/examples/modalLoader.html');
5+
6+
await page.getByRole('button', { name: 'Toolbar 3' }).click();
7+
await page.evaluate('modalsReady = true')
8+
await page.getByRole('button', { name: 'Toolbar 1' }).click();
9+
await page.locator('#modal1').getByText('Close').click();
10+
});

__checks__/web-shop-login.check.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { BrowserCheck, Frequency } from 'checkly/constructs'
2+
import * as path from 'path'
3+
4+
new BrowserCheck('browser-check-1', {
5+
name: 'Browser check #1',
6+
frequency: Frequency.EVERY_10M,
7+
locations: ['us-east-1', 'eu-west-1', 'ap-southeast-1'],
8+
code: {
9+
entrypoint: path.join(__dirname, 'web-shop-login.spec.ts')
10+
}
11+
})

__checks__/web-shop-login.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.only('test', async ({ page }) => {
4+
await page.goto('https://danube-webshop.herokuapp.com/');
5+
await page.getByText('Business').click();
6+
await page.locator('a').filter({ hasText: 'Crime & Thrillers' }).click();
7+
await page.getByRole('textbox').click();
8+
await page.getByRole('textbox').fill('parry');
9+
await page.getByRole('button', { name: 'Search' }).click();
10+
await page.getByRole('button', { name: 'Log in' }).click();
11+
await page.getByRole('textbox', { name: 'Email' }).click();
12+
await page.getByRole('textbox', { name: 'Email' }).fill('nica@checklyhq.com');
13+
await page.getByRole('textbox', { name: 'Email' }).press('Tab');
14+
await page.getByRole('textbox', { name: 'Password' }).fill('12345');
15+
await page.getByRole('button', { name: 'Sign In' }).click();
16+
});

0 commit comments

Comments
 (0)