Skip to content

Commit 21bbc6e

Browse files
authored
Add files via upload
0 parents  commit 21bbc6e

40 files changed

+9356
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# WebdriverIO Assertions Demo Setup Guide
3+
---
4+
5+
## Features of this framework
6+
* Expect in WebdriverIO (Assertions)
7+
* [Cloud Integration: LambdaTest](http://www.lambdatest.com?fp_ref=md-moeen-ajaz40)
8+
9+
## Getting started
10+
11+
### Pre-requisites
12+
* Download and install Node.js
13+
* Download and install any Text Editor like Visual Code/Sublime/Brackets
14+
15+
### Setup Visual Code - optional
16+
* Install GitLens Extension from the Marketplace: `GitLens — Git supercharged by GitKraken https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens`
17+
* Install Material Icon Theme Extension from the Marketplace: `Material Icon Theme by Philipp Kief https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme`
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 run wdio`
27+
28+
## How to Run Single Spec Locally
29+
* Go to the Project root directory and run command: `npm run wdio wdio.conf.js --spec ./test/specs/to-have-url.e2e.js`
30+
31+
### How to view default Playwright HTML report
32+
* Go to the Project root directory: `./playwright-report/index.html`
33+
34+
### Playwright Default HTML Test Report
35+
![Playwright Default HTML Test Report](./assets/html-test-report.PNG?raw=true "Playwright Default HTML Test Report")
36+
37+
## How to Run Test on LambdaTest Cloud
38+
* Go to Project root directory and run command: `npm run lambdatest`
39+
40+
### Terminal Test Result
41+
![Terminal Test Result](./assets/terminal-lt.PNG?raw=true "Terminal Test Result")
42+
43+
### LambdaTest Cloud Results
44+
![LambdaTest Cloud Results](./assets/lambdatest-results.PNG?raw=true "LambdaTest Cloud Results")
45+
46+
![LambdaTest Cloud Results Expanded View](./assets/lambdatest-results-expanded-view.PNG?raw=true "LambdaTest Cloud Results Expanded View")

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+
})

0 commit comments

Comments
 (0)