-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathplaywrightwebview.js
71 lines (60 loc) · 2.33 KB
/
playwrightwebview.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
const {_android} = require("playwright");
const {expect} = require("expect");
(async () => {
const capabilities = {
"LT:Options": {
"platformName": "android",
"deviceName": ".*",
"platformVersion": "12",
"isRealMobile": true,
"isPwMobileWebviewTest": true,
"build": "Playwright Android Webview Build",
"name": "Playwright android Webview test",
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
"network": false,
"video": false,
"console": true,
"video": true,
"tunnel":false
},
};
let device = await _android.connect(`wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`);
await device.shell('am force-stop org.chromium.webview_shell');
await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
let webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
console.log(`starting script execution`)
console.log(`Model:: ${device.model()}, serial:: ${device.serial()}`);
// Fill the input box.
await device.fill({
res: 'org.chromium.webview_shell:id/url_field',
}, 'https://duckduckgo.com');
await device.press({
res: 'org.chromium.webview_shell:id/url_field',
}, 'Enter');
// Work with WebView's page as usual.
const page = await webview.page();
let element = await page.locator("[name=\"q\"]");
await element.click();
await element.type("LambdaTest Blog");
await element.press("Enter");
const title = await page.title()
console.log('Page title:: ', title)
// Use the expect API for assertions provided by playwright
try {
expect(title).toEqual(expect.stringContaining('LambdaTest'))
// Mark the test as completed or failed
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: "setTestStatus", arguments: {status: "passed", remark: "Assertions passed" },})}`);
await teardown( device,webview)
} catch (e) {
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({action: "setTestStatus", arguments: { status: "failed", remark: e.stack }})}`);
await teardown( device,webview)
throw e.stack
}
})();
async function teardown(device) {
if (device) {
console.log("Closing the device...");
await device.close();
}
}