Skip to content

Commit b5d6852

Browse files
committed
Updated tests, added LambdaTest support
1 parent ddc2c09 commit b5d6852

File tree

9 files changed

+168
-106
lines changed

9 files changed

+168
-106
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
allure-results/
22
allure-report/
33
node_modules/
4-
/test-results/
5-
/playwright-report/
6-
/playwright/.cache/
4+
test-results/
5+
playwright-report/
6+
playwright/.cache/

e2e-tests/page-objects/pages/CartPage.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

e2e-tests/page-objects/pages/HomePage.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

e2e-tests/page-objects/pages/SearchPage.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

lambdatest-setup.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Add the file in your test suite to run tests on LambdaTest.
3+
* Import `test` object from this file in the tests.
4+
*/
5+
const base = require('@playwright/test')
6+
const path = require('path')
7+
const { chromium } = require('playwright')
8+
const cp = require('child_process');
9+
const playwrightClientVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];
10+
11+
// LambdaTest capabilities
12+
const capabilities = {
13+
'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
14+
'browserVersion': 'latest',
15+
'LT:Options': {
16+
'platform': 'Windows 10',
17+
'build': 'Playwright Build',
18+
'name': 'Playwright Test',
19+
'user': process.env.LT_USERNAME,
20+
'accessKey': process.env.LT_ACCESS_KEY,
21+
'network': true,
22+
'video': true,
23+
'console': true,
24+
'tunnel': false, // Add tunnel configuration if testing locally hosted webpage
25+
'tunnelName': '', // Optional
26+
'geoLocation': '', // country code can be fetched from https://www.lambdatest.com/capabilities-generator/
27+
'playwrightClientVersion': playwrightClientVersion
28+
}
29+
}
30+
31+
// Patching the capabilities dynamically according to the project name.
32+
const modifyCapabilities = (configName, testName) => {
33+
let config = configName.split('@lambdatest')[0]
34+
let [browserName, browserVersion, platform] = config.split(':')
35+
capabilities.browserName = browserName ? browserName : capabilities.browserName
36+
capabilities.browserVersion = browserVersion ? browserVersion : capabilities.browserVersion
37+
capabilities['LT:Options']['platform'] = platform ? platform : capabilities['LT:Options']['platform']
38+
capabilities['LT:Options']['name'] = testName
39+
}
40+
41+
const getErrorMessage = (obj, keys) => keys.reduce((obj, key) => (typeof obj == 'object' ? obj[key] : undefined), obj)
42+
43+
exports.test = base.test.extend({
44+
page: async ({ page, playwright }, use, testInfo) => {
45+
// Configure LambdaTest platform for cross-browser testing
46+
let fileName = testInfo.file.split(path.sep).pop()
47+
if (testInfo.project.name.match(/lambdatest/)) {
48+
modifyCapabilities(testInfo.project.name, `${testInfo.title} - ${fileName}`)
49+
50+
const browser = await chromium.connect({
51+
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
52+
})
53+
54+
const ltPage = await browser.newPage(testInfo.project.use)
55+
await use(ltPage)
56+
57+
const testStatus = {
58+
action: 'setTestStatus',
59+
arguments: {
60+
status: testInfo.status,
61+
remark: getErrorMessage(testInfo, ['error', 'message'])
62+
}
63+
}
64+
await ltPage.evaluate(() => { },
65+
`lambdatest_action: ${JSON.stringify(testStatus)}`)
66+
await ltPage.close()
67+
await browser.close()
68+
} else {
69+
// Run tests in local in case of local config provided
70+
await use(page)
71+
}
72+
}
73+
})

lt.config.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { devices } = require('@playwright/test')
2+
3+
// Playwright config to run tests on LambdaTest platform and local
4+
const config = {
5+
testDir: 'e2e-tests',
6+
testMatch: '**/*.spec.js',
7+
timeout: 60000,
8+
use: {},
9+
projects: [
10+
// -- LambdaTest Config --
11+
// name in the format: browserName:browserVersion:platform@lambdatest
12+
// Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
13+
// Use additional configuration options provided by Playwright if required: https://playwright.dev/docs/api/class-testconfig
14+
{
15+
name: 'chrome:latest:MacOS Catalina@lambdatest',
16+
use: {
17+
viewport: { width: 1920, height: 1080 }
18+
}
19+
},
20+
{
21+
name: 'chrome:latest:Windows 10@lambdatest',
22+
use: {
23+
viewport: { width: 1280, height: 720 }
24+
}
25+
},
26+
{
27+
name: 'MicrosoftEdge:90:Windows 10@lambdatest',
28+
use: {
29+
...devices['iPhone 12 Pro Max']
30+
}
31+
},
32+
{
33+
name: 'pw-firefox:latest:Windows 10@lambdatest',
34+
use: {
35+
viewport: { width: 1280, height: 720 }
36+
}
37+
},
38+
{
39+
name: 'pw-webkit:latest:Windows 10@lambdatest',
40+
use: {
41+
viewport: { width: 1920, height: 1080 }
42+
}
43+
}
44+
45+
]
46+
}
47+
48+
module.exports = config

lt.single.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { devices } = require('@playwright/test')
2+
3+
// Playwright config to run tests on LambdaTest platform and local
4+
const config = {
5+
testDir: 'e2e-tests',
6+
testMatch: '**/*.spec.js',
7+
timeout: 60000,
8+
use: {},
9+
projects: [
10+
// -- LambdaTest Config --
11+
// name in the format: browserName:browserVersion:platform@lambdatest
12+
// Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
13+
// Use additional configuration options provided by Playwright if required: https://playwright.dev/docs/api/class-testconfig
14+
{
15+
name: 'chrome:latest:Windows 10@lambdatest',
16+
use: {
17+
viewport: { width: 1280, height: 720 }
18+
}
19+
}
20+
]
21+
}
22+
23+
module.exports = config

package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@
44
"description": "This is Test Automation framework designed using Playwright, and JavaScript",
55
"main": "index.js",
66
"scripts": {
7-
"clean": "rimraf allure-results/ && rimraf allure-report/",
7+
"clean": "rimraf allure-results/ && rimraf allure-report/ && rimraf playwright-report/",
88
"test": "playwright test",
99
"headedTest": "playwright test --headed",
1010
"single-test-file": "npm run clean && playwright test cart.spec.js --reporter=line",
11-
"test-line-reporter": "npm run clean && playwright test -c e2e.config.js --reporter=line",
12-
"e2e": "npm run clean && playwright test -c e2e.config.js --reporter=line,./my-awesome-reporter.js,allure-playwright",
11+
"test-list-reporter": "npm run clean && playwright test cart.spec.js --reporter=list",
12+
"test-line-reporter": "npm run clean && playwright test cart.spec.js --reporter=line",
13+
"test-dot-reporter": "npm run clean && playwright test cart.spec.js --reporter=dot",
14+
"test-html-reporter": "npm run clean && playwright test cart.spec.js --reporter=html",
15+
"test-json-reporter": "npm run clean && playwright test cart.spec.js --reporter=json",
16+
"test-junit-reporter": "npm run clean && playwright test cart.spec.js --reporter=junit",
17+
"e2e": "npm run clean && playwright test -c e2e.config.js",
18+
"e2e-commandline-reporter": "npm run clean && playwright test -c e2e.config.js --reporter=line,./my-awesome-reporter.js,allure-playwright",
19+
"single-test-on-lt": "npx playwright test --config=./lt.single.config.js",
20+
"parallel-test-on-lt": "npx playwright test --config=./lt.config.js",
1321
"allure-report": "npx allure generate ./allure-results && allure open",
1422
"prettierCI": "npx prettier --check ./e2e-tests",
1523
"prettierWrite": "npx prettier --write ./e2e-tests"
1624
},
25+
"engines": {
26+
"node": ">=12.0.0"
27+
},
1728
"keywords": [],
18-
"author": "",
29+
"author": "Code with MMAK",
1930
"devDependencies": {
2031
"@playwright/test": "^1.29.1",
2132
"allure-commandline": "^2.20.1",

playwright.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const config = {
3030
workers: process.env.CI ? 1 : undefined,
3131
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
3232
// reporter: 'html',
33-
reporter: [
34-
['html'],
35-
['list'],
36-
['./my-awesome-reporter.js'],
37-
['allure-playwright', { outputFolder: 'allure-results' }]
38-
],
33+
// reporter: [
34+
// ['html'],
35+
// ['list'],
36+
// ['./my-awesome-reporter.js'],
37+
// ['allure-playwright', { outputFolder: 'allure-results' }]
38+
// ],
3939

4040
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
4141
use: {

0 commit comments

Comments
 (0)