Skip to content

Commit 4184e9a

Browse files
author
nginx
committed
Pre OSS commit
1 parent b94559a commit 4184e9a

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

playwright.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default defineConfig({
2525
},
2626
],
2727
use: {
28+
// Base URL to use in actions like `await page.goto('/')`.
29+
baseURL: 'https://docs.nginx.com',
2830
// Set Geolocation to Cork, Ireland
2931
geolocation: { longitude: -8.486316, latitude: 51.896893 },
3032
permissions: ['geolocation'],

tests/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Place to store constant values.
3+
*/
4+
export const TIMEOUT = 4000

tests/search.spec.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
import { test, expect, type Page } from '@playwright/test';
2-
3-
async function handleConsentPopup(page: Page) {
4-
const consentContent = page.locator('#truste-consent-content');
5-
const isConsentContentVisibile = await consentContent.isVisible();
6-
if(isConsentContentVisibile) {
7-
const consentButton = page.locator('#truste-consent-required');
8-
expect(consentButton).toBeVisible();
9-
await consentButton.click();
10-
}
11-
}
12-
13-
let sleep = ms => new Promise(r => setTimeout(r, ms));
14-
let waitFor = async function waitFor(f){
15-
while(!f()) await sleep(4000);
16-
return f();
17-
};
18-
1+
import { test, expect} from '@playwright/test';
2+
import { handleConsentPopup, waitFor } from '../tests/utils/commonUtils.ts'
3+
194
test.describe("Testing search page", () => {
205
test('Searchbar is visible', async ({ page }) => {
21-
await page.goto("https://docs.nginx.com");
6+
await page.goto('/');
227
await waitFor(() => handleConsentPopup(page));
238

249
const searchBox = page.locator('#searchbox');
@@ -29,12 +14,12 @@ test.describe("Testing search page", () => {
2914
await page.keyboard.insertText(searchValue);
3015
await page.keyboard.press('Enter');
3116

32-
await page.waitForURL(`https://docs.nginx.com/search.html#q=${searchValue}&sort=relevancy`);
17+
await page.waitForURL(`/search.html#q=${searchValue}&sort=relevancy`);
3318
expect(await page.locator('div h1').innerHTML()).toBe('Search Results');
3419
});
3520

3621
test('Search page returns results without error', async ({ page }) => {
37-
await page.goto("https://docs.nginx.com/search.html#q=proxy&sort=relevancy");
22+
await page.goto(`/search.html#q=proxy&sort=relevancy`);
3823
await waitFor(() => handleConsentPopup(page));
3924

4025
await page.waitForSelector('div.coveo-result-list-container');

tests/utils/commonUtils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, type Page } from '@playwright/test';
2+
import { TIMEOUT } from '../../tests/constants.ts';
3+
4+
// THE GDPR Consent button appears when test is run from EU locations. This handles that popup.
5+
export async function handleConsentPopup(page: Page) {
6+
const consentContent = page.locator('#truste-consent-content');
7+
const isConsentContentVisibile = await consentContent.isVisible();
8+
if(isConsentContentVisibile) {
9+
const consentButton = page.locator('#truste-consent-required');
10+
expect(consentButton).toBeVisible();
11+
await consentButton.click();
12+
}
13+
}
14+
15+
let sleep = ms => new Promise(r => setTimeout(r, ms));
16+
export let waitFor = async function waitFor(f, ftimeout=TIMEOUT){
17+
while(!f()) await sleep(ftimeout);
18+
return f();
19+
};

0 commit comments

Comments
 (0)