-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from HRanjan-11/sampleWebview
added webview test
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |