Skip to content

Commit 875e6a5

Browse files
committed
added webview test
1 parent 051ad6c commit 875e6a5

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

playwrightwebview.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const {_android} = require("playwright");
2+
const {expect} = require("expect");
3+
4+
(async () => {
5+
const capabilities = {
6+
"LT:Options": {
7+
"platformName": "android",
8+
"deviceName": ".*",
9+
"platformVersion": "12",
10+
"isRealMobile": true,
11+
"isPwMobileWebviewTest": true,
12+
"build": "Playwright Android Webview Build",
13+
"name": "Playwright android Webview test",
14+
'user': process.env.LT_USERNAME,
15+
'accessKey': process.env.LT_ACCESS_KEY,
16+
"network": false,
17+
"video": false,
18+
"console": true,
19+
"video": true,
20+
"tunnel":false
21+
},
22+
};
23+
24+
let device = await _android.connect(`wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`);
25+
await device.shell('am force-stop org.chromium.webview_shell');
26+
await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
27+
let webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
28+
29+
console.log(`starting script execution`)
30+
console.log(`Model:: ${device.model()}, serial:: ${device.serial()}`);
31+
32+
// Fill the input box.
33+
await device.fill({
34+
res: 'org.chromium.webview_shell:id/url_field',
35+
}, 'https://duckduckgo.com');
36+
await device.press({
37+
res: 'org.chromium.webview_shell:id/url_field',
38+
}, 'Enter');
39+
40+
// Work with WebView's page as usual.
41+
const page = await webview.page();
42+
43+
let element = await page.locator("[name=\"q\"]");
44+
await element.click();
45+
await element.type("LambdaTest Blog");
46+
await element.press("Enter");
47+
const title = await page.title()
48+
49+
console.log('Page title:: ', title)
50+
// Use the expect API for assertions provided by playwright
51+
52+
53+
try {
54+
expect(title).toEqual(expect.stringContaining('LambdaTest'))
55+
// Mark the test as completed or failed
56+
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: "setTestStatus", arguments: {status: "passed", remark: "Assertions passed" },})}`);
57+
await teardown( device,webview)
58+
} catch (e) {
59+
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({action: "setTestStatus", arguments: { status: "failed", remark: e.stack }})}`);
60+
await teardown( device,webview)
61+
throw e.stack
62+
}
63+
64+
})();
65+
66+
async function teardown(device) {
67+
if (device) {
68+
console.log("Closing the device...");
69+
await device.close();
70+
}
71+
}

0 commit comments

Comments
 (0)