Skip to content

Commit c792fd7

Browse files
authored
Add files via upload
1 parent 0bb2115 commit c792fd7

19 files changed

+821
-2
lines changed

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# playwright-lambdatest-javascript
2-
This is Test Automation framework designed using Playwright, and JavaScript to execute on LambdaTest
1+
---
2+
# Playwright and LambdaTest Setup Guide
3+
---
4+
5+
## Features of this framework
6+
* Playwright Expect (Assertions)
7+
* [Reporting: Allure](https://www.npmjs.com/package/allure-playwright)
8+
* [Cloud Integration: LambdaTest](https://www.lambdatest.com/)
9+
10+
## Getting started
11+
12+
### Pre-requisites
13+
* Download and install Node.js
14+
* Download and install any Text Editor like Visual Code/Sublime/Brackets
15+
16+
### Setup Visual Code
17+
* Install GitLens Extension from the Marketplace: `GitLens — Git supercharged by GitKraken https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens`
18+
* Go to Visual Code Preference > Setting and search `formatOnSave` and enable/ON it.
19+
20+
### Setup Scripts
21+
* Clone the repository into a folder
22+
* Go to Project root directory and install Dependency: `npm install`
23+
* All the dependencies from package.json would be installed in node_modules folder.
24+
25+
## How to Run Test Locally
26+
* Go to the Project root directory and run command: `npm test`
27+
28+
### How to view default Playwright HTML report
29+
* Go to the Project root directory: `./playwright-report/index.html`
30+
31+
### Playwright Default HTML Test Report
32+
![Playwright Default HTML Test Report](./assets/html-test-report.PNG?raw=true "Playwright Default HTML Test Report")
33+
34+
### How to view Allure HTML report
35+
* Go to the Project root directory and run command: `npm run allure-report`
36+
* Go to the Project root directory: `./allure-report/index.html`
37+
38+
### Allure Test Report
39+
![Allure Test Report](./assets/allure-test-report.PNG?raw=true "Allure Test Report")
40+
41+
![Allure Test Report Expanded View](./assets/allure-test-report-expanded-view.PNG?raw=true "Allure Test Report Expanded View")
42+
43+
## How to Run Test on LambdaTest Cloud
44+
* Go to Project root directory and run command: `npm run lambdatest`
45+
46+
### Terminal Test Result
47+
![Terminal Test Result](./assets/terminal-lt.PNG?raw=true "Terminal Test Result")
48+
49+
### LambdaTest Cloud Results
50+
![LambdaTest Cloud Results](./assets/lambdatest-results.PNG?raw=true "LambdaTest Cloud Results")
51+
52+
![LambdaTest Cloud Results Expanded View](./assets/lambdatest-results-expanded-view.PNG?raw=true "LambdaTest Cloud Results Expanded View")
119 KB
Loading

assets/allure-test-report.PNG

101 KB
Loading

assets/html-test-report.PNG

108 KB
Loading
139 KB
Loading

assets/lambdatest-results.PNG

153 KB
Loading

assets/terminal-lt.PNG

19.9 KB
Loading

lambdatest-setup.js

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

lambdatest.config.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// @ts-check
2+
const { devices } = require('@playwright/test');
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
11+
/**
12+
* @see https://playwright.dev/docs/test-configuration
13+
* @type {import('@playwright/test').PlaywrightTestConfig}
14+
*/
15+
const config = {
16+
testDir: './tests',
17+
/* Maximum time one test can run for. */
18+
timeout: 30 * 1000,
19+
expect: {
20+
/**
21+
* Maximum time expect() should wait for the condition to be met.
22+
* For example in `await expect(locator).toHaveText();`
23+
*/
24+
timeout: 5000
25+
},
26+
/* Run tests in files in parallel */
27+
fullyParallel: true,
28+
/* Fail the build on CI if you accidentally left test.only in the source code. */
29+
forbidOnly: !!process.env.CI,
30+
/* Retry on CI only */
31+
retries: process.env.CI ? 2 : 0,
32+
/* Opt out of parallel tests on CI. */
33+
workers: process.env.CI ? 1 : undefined,
34+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
35+
reporter: 'html',
36+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
37+
use: {
38+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
39+
actionTimeout: 0,
40+
/* Base URL to use in actions like `await page.goto('/')`. */
41+
// baseURL: 'http://localhost:3000',
42+
43+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
44+
trace: 'on-first-retry',
45+
},
46+
47+
/* Configure projects for major browsers */
48+
projects: [
49+
50+
// LambdaTest Cloud
51+
{
52+
name: 'chrome:latest:MacOS Catalina@lambdatest',
53+
use: {
54+
viewport: { width: 1920, height: 1080 }
55+
}
56+
},
57+
{
58+
name: 'chrome:latest:Windows 10@lambdatest',
59+
use: {
60+
viewport: { width: 1280, height: 720 }
61+
}
62+
},
63+
{
64+
name: 'MicrosoftEdge:latest:Windows 10@lambdatest',
65+
use: {
66+
...devices['iPhone 12 Pro Max']
67+
}
68+
},
69+
{
70+
name: 'pw-firefox:latest:Windows 10@lambdatest',
71+
use: {
72+
viewport: { width: 1280, height: 720 }
73+
}
74+
},
75+
{
76+
name: 'pw-webkit:latest:Windows 10@lambdatest',
77+
use: {
78+
viewport: { width: 1920, height: 1080 }
79+
}
80+
}
81+
],
82+
83+
};
84+
85+
module.exports = config;

0 commit comments

Comments
 (0)