forked from SeleniumHQ/docker-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Add simple Playwright parallel tests connect to autoscaling Grid…
… in K8s Signed-off-by: Viet Nguyen Duc <[email protected]>
- Loading branch information
Showing
10 changed files
with
192 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ | ||
.idea/ | ||
.vscode/ | ||
jsonReports/ | ||
package-lock.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd tests/CDPTests || true | ||
|
||
npm install | ||
npx playwright install | ||
|
||
BROWSER=${1:-"chrome"} | ||
|
||
SELENIUM_REMOTE_URL="${SELENIUM_GRID_PROTOCOL}://${SELENIUM_GRID_HOST}:${SELENIUM_GRID_PORT}" | ||
echo "SELENIUM_REMOTE_URL=${SELENIUM_REMOTE_URL}" > .env | ||
|
||
if [ -n ${SELENIUM_GRID_USERNAME} ] && [ -n ${SELENIUM_GRID_PASSWORD} ]; then | ||
BASIC_AUTH="$(echo -n "${SELENIUM_GRID_USERNAME}:${SELENIUM_GRID_PASSWORD}" | base64)" | ||
echo "SELENIUM_REMOTE_HEADERS={\"Authorization\": \"Basic ${BASIC_AUTH}\"}" >> .env | ||
fi | ||
|
||
echo "SELENIUM_REMOTE_CAPABILITIES={\"browserName\": \"${BROWSER}\"}" >> .env | ||
echo "NODE_EXTRA_CA_CERTS=${CHART_CERT_PATH}" >> .env | ||
|
||
until [ "$(curl --noproxy "*" -sk -H "Authorization: Basic ${BASIC_AUTH}" -o /dev/null -w "%{http_code}" "${SELENIUM_REMOTE_URL}/status")" = "200" ]; do | ||
echo "Waiting for Grid to be ready..." | ||
sleep 1 | ||
done | ||
|
||
npx playwright 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "CDPTests", | ||
"version": "1.47.2", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.47.2" | ||
}, | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.3.1", | ||
"express": "^4.18.2", | ||
"playwright-core": "^1.47.2" | ||
}, | ||
"description": "" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {PlaywrightTestConfig} from '@playwright/test'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
const config: PlaywrightTestConfig = { | ||
timeout: 1500000, | ||
testMatch: ["tests/*.ts"], | ||
use: { | ||
headless: false, | ||
screenshot: "on", | ||
video: "on" | ||
}, | ||
reporter: [["dot"], ["json", { | ||
outputFile: "jsonReports/jsonReport.json" | ||
}], ["html", { | ||
open: "never" | ||
}]], | ||
workers: 5 | ||
}; | ||
|
||
export default config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const {test, expect} = require('@playwright/test'); | ||
const path = require('path'); | ||
|
||
function sleep(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
test.describe.parallel('Parallel tests connect to autoscaling Grid', () => { | ||
test('test_title', async ({page}) => { | ||
await page.goto('https://the-internet.herokuapp.com'); | ||
await expect(page).toHaveTitle('The Internet'); | ||
await sleep(2); | ||
}); | ||
|
||
test('test_with_frames', async ({page}) => { | ||
await page.goto('http://the-internet.herokuapp.com/nested_frames'); | ||
const frame = page.frameLocator('frame[name="frame-top"]').frameLocator('frame[name="frame-middle"]'); | ||
await expect(frame.locator('#content')).toHaveText('MIDDLE'); | ||
await sleep(2); | ||
}); | ||
|
||
test('test_select_from_a_dropdown', async ({page}) => { | ||
await page.goto('http://the-internet.herokuapp.com/dropdown'); | ||
const dropdown = await page.locator('#dropdown'); | ||
await dropdown.selectOption({label: 'Option 1'}); | ||
const selectedOption = await dropdown.inputValue(); | ||
expect(selectedOption).toBe('1'); | ||
await sleep(2); | ||
}); | ||
|
||
test('test_visit_basic_auth_secured_page', async ({page}) => { | ||
await page.goto('http://admin:[email protected]/basic_auth'); | ||
const pageMessage = await page.locator('.example p').textContent(); | ||
expect(pageMessage.trim()).toBe('Congratulations! You must have the proper credentials.'); | ||
await sleep(2); | ||
}); | ||
|
||
test('test_download_file', async ({page}) => { | ||
await page.goto('https://the-internet.herokuapp.com/download'); | ||
const fileLink = page.locator('a', {hasText: 'some-file.txt'}); | ||
await fileLink.scrollIntoViewIfNeeded(); | ||
const [download] = await Promise.all([ | ||
page.waitForEvent('download'), | ||
fileLink.click() | ||
]); | ||
const fileName = download.suggestedFilename(); | ||
expect(fileName).toBe('some-file.txt'); | ||
await sleep(2); | ||
}); | ||
}); |
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
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