Skip to content

Commit d117024

Browse files
authored
Merge pull request #121 from HRanjan-11/main
added sample repo for merge test
2 parents e666705 + ca01428 commit d117024

File tree

8 files changed

+295
-0
lines changed

8 files changed

+295
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing Playwright with JS on LambdaTest
2+
3+
## Setup
4+
* Clone the repo. Run `cd playwright-test-js`
5+
* Install dependencies. Run `npm install`
6+
7+
## Running your tests
8+
- To run a single test, run
9+
```npm run test```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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, _android } = require('playwright')
8+
const cp = require('child_process');
9+
const playwrightClientVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];
10+
11+
async function setupBrowser() {
12+
13+
const lambdatestCapabilities = {
14+
// Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
15+
'browserName': 'Chrome',
16+
'browserVersion': 'latest',
17+
'LT:Options': {
18+
19+
'video': true,
20+
'console': true,
21+
'tunnel': false, // Add tunnel configuration if testing locally hosted webpage
22+
'tunnelName': '', // Optional
23+
'idleTimeout': 1800,
24+
'user': process.env.LT_USERNAME,
25+
'accessKey': process.env.LT_ACCESS_KEY,
26+
'useSpecificBundleVersion': true,
27+
'platform': 'MacOs Ventura',
28+
'build': 'Playwright JS Build - Desktop',
29+
'name': 'Playwright Test',
30+
'network': false,
31+
}
32+
}
33+
let device, context, browser, ltPage;
34+
browser = await chromium.connect(`wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(lambdatestCapabilities))}`)
35+
ltPage = await browser.newPage()
36+
return ltPage;
37+
}
38+
39+
module.exports = { setupBrowser };
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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, _android } = require('playwright')
8+
const cp = require('child_process');
9+
const playwrightClientVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];
10+
11+
async function setupBrowser() {
12+
13+
const lambdatestCapabilities = {
14+
'LT:Options': {
15+
'video': true,
16+
'console': true,
17+
'tunnel': false, // Add tunnel configuration if testing locally hosted webpage
18+
'tunnelName': '', // Optional
19+
'idleTimeout': 1800,
20+
21+
'user': process.env.LT_USERNAME,
22+
'accessKey': process.env.LT_ACCESS_KEY,
23+
'useSpecificBundleVersion': true,
24+
'deviceName':".*",
25+
'platformVersion':".*",
26+
'platformName':'android',
27+
'build': 'Playwright JS Build - Mobile',
28+
'name': 'Playwright Test',
29+
'network': false,
30+
'isRealMobile': true,
31+
}
32+
}
33+
let device, context, browser, ltPage;
34+
35+
device = await _android.connect(`wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(lambdatestCapabilities))}`);
36+
37+
await device.shell("am force-stop com.android.chrome");
38+
39+
context = await device.launchBrowser();
40+
41+
context.setDefaultTimeout(51000);
42+
ltPage = await context.newPage();
43+
return ltPage;
44+
}
45+
46+
module.exports = { setupBrowser };
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "playwright-test-suite",
3+
"version": "1.0.0",
4+
"author": "LambdaTest",
5+
"engines": {
6+
"node": ">=12.0.0"
7+
},
8+
"description": "Sample project to run playwright tests using playwright runner on LambdaTest platform",
9+
"scripts": {
10+
"test": "npx playwright test --config=./playwright.config.js",
11+
"testAndroid": "npx playwright test --config=./playwrightAndroid.config.js"
12+
},
13+
"devDependencies": {
14+
"@playwright/test": "1.42.1"
15+
},
16+
"dependencies": {
17+
"playwright": "1.42.1"
18+
}
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { devices } = require('@playwright/test')
2+
3+
// Playwright config to run tests on LambdaTest platform and local
4+
const config = {
5+
testDir: 'tests',
6+
testMatch: '**/*.spec.js',
7+
timeout: 120000,
8+
workers: 5,
9+
use: {
10+
},
11+
projects: [
12+
// -- LambdaTest Config --
13+
// name in the format: browserName:browserVersion:platform@lambdatest
14+
// Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
15+
// Use additional configuration options provided by Playwright if required: https://playwright.dev/docs/api/class-testconfig
16+
{
17+
name: 'chrome:latest:MacOs Monterey@lambdatest',
18+
use: {
19+
viewport: { width: 1280, height: 720 }
20+
}
21+
}
22+
]
23+
}
24+
25+
module.exports = config
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { devices } = require('@playwright/test')
2+
3+
// Playwright config to run tests on LambdaTest platform and local
4+
const config = {
5+
testDir: 'tests',
6+
testMatch: '**/*.spec.js',
7+
timeout: 120000,
8+
workers: 4,
9+
projects: [
10+
// -- LambdaTest Config --
11+
// name in the format: deviceName:platformVersion:platformName@lambdatest
12+
// Use additional configuration options provided by Playwright if required: https://playwright.dev/docs/api/class-testconfig
13+
{
14+
name: '.*:.*:android@lambdatest',
15+
use: {}
16+
}
17+
]
18+
}
19+
20+
module.exports = config
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const { test, expect } = require('@playwright/test');
2+
const { setupBrowser } = require('../lambdatest-mobile-setup')
3+
const { chromium, _android } = require('playwright');
4+
5+
// test.describe.configure({ mode: 'parallel' });
6+
7+
test.describe('Group 1', () => {
8+
let browser;
9+
let context;
10+
let page;
11+
let device;
12+
let testInfoGlobal;
13+
14+
test.beforeAll(async () => {
15+
16+
page = await setupBrowser();
17+
});
18+
19+
test.afterAll(async () => {
20+
21+
if (testInfoGlobal) {
22+
const testStatus = {
23+
action: 'setTestStatus',
24+
arguments: {
25+
status: testInfoGlobal.status,
26+
remark: testInfoGlobal.error?.stack || testInfoGlobal.error?.message,
27+
}
28+
}
29+
await page.evaluate(() => {},
30+
`lambdatest_action: ${JSON.stringify(testStatus)}`)
31+
}
32+
33+
await page?.close();
34+
await context?.close();
35+
await browser?.close();
36+
await device?.close();
37+
});
38+
39+
40+
test('test 1 Search LambdaTest on DuckDuckGo', async ({},testInfo) => {
41+
testInfoGlobal = testInfo;
42+
await page.goto('https://duckduckgo.com')
43+
let element = await page.locator("[name=\"q\"]");
44+
await element.click();
45+
await element.type("LambdaTest");
46+
await element.press("Enter");
47+
const title = await page.title()
48+
49+
50+
console.log('Page title:: ', title)
51+
// Use the expect API for assertions provided by playwright
52+
expect(title).toEqual(expect.stringContaining('LambdaTest'))
53+
})
54+
55+
test('test 2 Search LambdaTest on DuckDuckGo', async ({},testInfo) => {
56+
testInfoGlobal = testInfo;
57+
await page.goto('https://duckduckgo.com')
58+
let element = await page.locator("[name=\"q\"]");
59+
await element.click();
60+
await element.type("LambdaTest");
61+
await element.press("Enter");
62+
const title = await page.title()
63+
64+
65+
console.log('Page title:: ', title)
66+
// Use the expect API for assertions provided by playwright
67+
expect(title).toEqual(expect.stringContaining('LambdaTest'))
68+
})
69+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const { test, expect } = require('@playwright/test');
2+
const { chromium } = require('playwright');
3+
const { setupBrowser } = require('../lambdatest-desktop-setup')
4+
5+
// test.describe.configure({ mode: 'parallel' });
6+
7+
test.describe('Group 1', () => {
8+
let browser;
9+
let context;
10+
let page;
11+
let device;
12+
let testInfoGlobal;
13+
14+
test.beforeAll(async () => {
15+
16+
page = await setupBrowser();
17+
});
18+
19+
test.afterAll(async () => {
20+
if (testInfoGlobal) {
21+
const testStatus = {
22+
action: 'setTestStatus',
23+
arguments: {
24+
status: testInfoGlobal.status,
25+
remark: testInfoGlobal.error?.stack || testInfoGlobal.error?.message,
26+
}
27+
}
28+
await page.evaluate(() => {},
29+
`lambdatest_action: ${JSON.stringify(testStatus)}`)
30+
}
31+
32+
await page?.close();
33+
await context?.close();
34+
await browser?.close();
35+
await device?.close();
36+
});
37+
38+
39+
test('test 1 Search LambdaTest on DuckDuckGo', async ({},testInfo) => {
40+
testInfoGlobal = testInfo;
41+
await page.goto('https://duckduckgo.com')
42+
let element = await page.locator("[name=\"q\"]");
43+
await element.click();
44+
await element.type("LambdaTest");
45+
await element.press("Enter");
46+
const title = await page.title()
47+
48+
49+
console.log('Page title:: ', title)
50+
// Use the expect API for assertions provided by playwright
51+
expect(title).toEqual(expect.stringContaining('LambdaTest'))
52+
})
53+
54+
test('test 2 Search LambdaTest on DuckDuckGo', async ({},testInfo) => {
55+
testInfoGlobal = testInfo;
56+
await page.goto('https://duckduckgo.com')
57+
let element = await page.locator("[name=\"q\"]");
58+
await element.click();
59+
await element.type("LambdaTest");
60+
await element.press("Enter");
61+
const title = await page.title()
62+
63+
64+
console.log('Page title:: ', title)
65+
// Use the expect API for assertions provided by playwright
66+
expect(title).toEqual(expect.stringContaining('LambdaTest'))
67+
})
68+
});

0 commit comments

Comments
 (0)