-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpuppeteerSmartUI.js
72 lines (62 loc) · 2.09 KB
/
puppeteerSmartUI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { connect } from "puppeteer";
import { expect } from "chai";
let browser, page;
(async () => {
const capabilities = {
"browserName": "Chrome",
"browserVersion": "latest",
"LT:Options": {
"platform": "Windows 10",
"build": "Puppeteer SmartUI Build",
"name": "Puppeteer SmartUI Test",
"user": process.env.LT_USERNAME,
"accessKey": process.env.LT_ACCESS_KEY,
"network": true,
"video": true,
"console": true,
"smartUIProjectName": "<projectName>", // Add the required Smart UI Project name
},
};
try {
browser = await connect({
browserWSEndpoint: `wss://cdp.lambdatest.com/puppeteer?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
});
page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080,
deviceScaleFactor: 1,
});
await page.goto("https://www.bing.com");
// Add the following command in order to take screenshot in SmartUI
await page.evaluate(_ => { }, `lambdatest_action: ${JSON.stringify({
action: "smartui.takeScreenshot",
arguments: { screenshotName: "<Your Screenshot Name>" },
})}`);
const element = await page.$("[aria-label=\"Enter your search term\"]");
await element.click();
await element.type("LambdaTest");
await page.keyboard.press("Enter");
const pageTitle = await page.title();
try {
expect(pageTitle).equal("LambdaTest - Search");
await page.evaluate(_ => { }, `lambdatest_action: ${JSON.stringify({
action: "setTestStatus",
arguments: { status: "passed", remark: "Title matched" },
})}`);
} catch (e) {
await page.evaluate(_ => { }, `lambdatest_action: ${JSON.stringify({
action: "setTestStatus",
arguments: { status: "failed", remark: e.stack },
})}`);
}
await browser.close();
} catch (e) {
await page.evaluate(_ => { }, `lambdatest_action: ${JSON.stringify({
action: "setTestStatus",
arguments: { status: "failed", remark: e.stack },
})}`);
await browser.close();
throw e;
}
})();