Skip to content

Commit 13748f4

Browse files
committed
Added tests
1 parent ee6be09 commit 13748f4

13 files changed

+234
-334
lines changed

.gitignore

Lines changed: 8 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,9 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
411
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
2+
/test-results/
3+
/playwright-report/
4+
/playwright/.cache/
5+
my-report/
6+
deleteMe/
7+
allure-report
8+
allure-results
9+
deleteMe

assets/html-outputFolder.png

78.4 KB
Loading

assets/json-output.png

835 KB
Loading

assets/junit-output.png

564 KB
Loading

assets/lambdatest-script.png

418 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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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-lambdatest',
17+
/* Maximum time one test can run for. */
18+
timeout: 120 * 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: 15000
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: [
36+
['line'],
37+
['allure-playwright']
38+
],
39+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
40+
use: {
41+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
42+
actionTimeout: 0,
43+
/* Base URL to use in actions like `await page.goto('/')`. */
44+
// baseURL: 'http://localhost:3000',
45+
46+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
47+
trace: 'on-first-retry',
48+
},
49+
50+
/* Configure projects for major browsers */
51+
projects: [
52+
53+
// LambdaTest Cloud
54+
{
55+
name: 'chrome:latest:MacOS Catalina@lambdatest',
56+
use: {
57+
viewport: { width: 1920, height: 1080 }
58+
}
59+
},
60+
{
61+
name: 'chrome:latest:Windows 10@lambdatest',
62+
use: {
63+
viewport: { width: 1280, height: 720 }
64+
}
65+
},
66+
{
67+
name: 'pw-firefox:latest:Windows 10@lambdatest',
68+
use: {
69+
viewport: { width: 1280, height: 720 }
70+
}
71+
},
72+
{
73+
name: 'pw-webkit:latest:Windows 10@lambdatest',
74+
use: {
75+
viewport: { width: 1920, height: 1080 }
76+
}
77+
}
78+
],
79+
80+
};
81+
82+
module.exports = config;

0 commit comments

Comments
 (0)