Skip to content

Commit dcfb215

Browse files
authored
Merge pull request #1 from JeeveshJ7/main
SDK changes
2 parents 7a75920 + 6502227 commit dcfb215

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed
File renamed without changes.
File renamed without changes.

sdk/ignorePlaywright.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { chromium } = require("playwright");
2+
const { expect } = require("@playwright/test");
3+
const smartuiSnapshot = require("@lambdatest/playwright-driver");
4+
5+
6+
// username: Username can be found at automation dashboard
7+
const USERNAME = process.env.LT_USERNAME || "<USERNAME>";
8+
9+
// AccessKey: AccessKey can be generated from automation dashboard or profile section
10+
const KEY = process.env.LT_ACCESS_KEY || "<ACCESS_KEY>";
11+
(async () => {
12+
const capabilities = {
13+
browserName: "Chrome",
14+
browserVersion: "latest",
15+
"LT:Options": {
16+
platform: "Windows 10",
17+
build: "Playwright SmartUI Build",
18+
name: "Playwright SmartUI Test",
19+
user: USERNAME,
20+
accessKey: KEY,
21+
network: true,
22+
video: true,
23+
console: true,
24+
},
25+
};
26+
27+
const githubURL = process.env.GITHUB_URL;
28+
if (githubURL) {
29+
capabilities["LT:Options"]["github"] = {
30+
url: githubURL,
31+
};
32+
}
33+
34+
const browser = await chromium.connect({
35+
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(
36+
JSON.stringify(capabilities)
37+
)}`,
38+
});
39+
40+
const page = await browser.newPage();
41+
42+
await page.goto("https://ipinfo.io/");
43+
options = {
44+
ignoreDOM: {
45+
xpath: ['//*[@id="__next"]/div/div/main/section[4]'],
46+
}
47+
}
48+
// Add the following command in order to take screenshot in SmartUI
49+
await smartuiSnapshot.smartuiSnapshot(page, "Ignore-ticker", options);
50+
await browser.close();
51+
})();

sdk/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "lambdatest-playwright-sample",
3+
"scripts": {
4+
"test": "node playwright-single.js",
5+
"test-smartui": "node playwright-smartui.js"
6+
},
7+
"engines": {
8+
"node": ">=12.7.0"
9+
},
10+
"devDependencies": {
11+
"@playwright/test": "^1.35.0",
12+
"playwright": "^1.35.0",
13+
"@cucumber/cucumber": "^7.3.2",
14+
"chai": "^4.3.7"
15+
},
16+
"dependencies": {
17+
"@lambdatest/playwright-driver": "^1.0.3",
18+
"@lambdatest/smartui-cli": "^2.0.6"
19+
}
20+
}

sdk/playwrightCloud.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { chromium } = require("playwright");
2+
const { expect } = require("@playwright/test");
3+
const smartuiSnapshot = require("@lambdatest/playwright-driver");
4+
5+
6+
// username: Username can be found at automation dashboard
7+
const USERNAME = process.env.LT_USERNAME || "<USERNAME>";
8+
9+
// AccessKey: AccessKey can be generated from automation dashboard or profile section
10+
const KEY = process.env.LT_ACCESS_KEY || "<ACCESS_KEY>";
11+
(async () => {
12+
const capabilities = {
13+
browserName: "Chrome",
14+
browserVersion: "latest",
15+
"LT:Options": {
16+
platform: "Windows 10",
17+
build: "Playwright SmartUI Build",
18+
name: "Playwright SmartUI Test",
19+
user: USERNAME,
20+
accessKey: KEY,
21+
network: true,
22+
video: true,
23+
console: true,
24+
},
25+
};
26+
27+
const githubURL = process.env.GITHUB_URL;
28+
if (githubURL) {
29+
capabilities["LT:Options"]["github"] = {
30+
url: githubURL,
31+
};
32+
}
33+
34+
const browser = await chromium.connect({
35+
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(
36+
JSON.stringify(capabilities)
37+
)}`,
38+
});
39+
40+
const page = await browser.newPage();
41+
42+
await page.goto("https://www.lambdatest.com");
43+
44+
// Add the following command in order to take screenshot in SmartUI
45+
await smartuiSnapshot.smartuiSnapshot(page, "LT-Home");
46+
await browser.close();
47+
})();

sdk/playwrightLocal.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { chromium } = require("playwright");
2+
const smartuiSnapshot = require("@lambdatest/playwright-driver");
3+
4+
(async () => {
5+
// Launch a local browser instance
6+
const browser = await chromium.launch({
7+
headless: false, // Set to false to see the browser UI
8+
});
9+
10+
const page = await browser.newPage();
11+
12+
// Navigate to the desired URL
13+
await page.goto("https://www.lambdatest.com");
14+
15+
// Use smartuiSnapshot to take a visual snapshot locally
16+
await smartuiSnapshot.smartuiSnapshot(page, "LT-Home");
17+
18+
// Close the browser
19+
await browser.close();
20+
})();

0 commit comments

Comments
 (0)