Best JavaScript code snippet using appium-android-driver
context-specs.js
Source:context-specs.js
...41 });42 describe('getCurrentContext', function () {43 it('should return current context', async function () {44 driver.curContext = 'current_context';45 await driver.getCurrentContext().should.become('current_context');46 });47 it('should return NATIVE_APP if no context is set', async function () {48 driver.curContext = null;49 await driver.getCurrentContext().should.become(NATIVE_WIN);50 });51 });52 describe('getContexts', function () {53 it('should get Chromium context where appropriate', async function () {54 sandbox.stub(webviewHelpers, 'getWebViewsMapping');55 driver = new AndroidDriver({browserName: 'Chrome'});56 expect(await driver.getContexts()).to.include(CHROMIUM_WIN);57 webviewHelpers.getWebViewsMapping.calledOnce.should.be.true;58 });59 it('should use ADB to figure out which webviews are available', async function () {60 sandbox.stub(webviewHelpers, 'parseWebviewNames').returns(['DEFAULT', 'VW', 'ANOTHER']);61 sandbox.stub(webviewHelpers, 'getWebViewsMapping');62 expect(await driver.getContexts()).to.not.include(CHROMIUM_WIN);63 webviewHelpers.parseWebviewNames.calledOnce.should.be.true;...
basic-specs.js
Source:basic-specs.js
...11 const driver = setup(this, desired).driver;12 describe('context', function () {13 it('getting current context should work initially', async function () {14 await B.delay(500);15 (await driver.getCurrentContext()).should.be.ok;16 });17 });18 describe('implicit wait', function () {19 it('should set the implicit wait for finding web elements', async function () {20 await driver.implicitWait(7 * 1000);21 let before = new Date().getTime() / 1000;22 let hasThrown = false;23 /**24 * we have to use try catch to actually halt the process here25 */26 try {27 await driver.findElement('tag name', 'notgonnabethere');28 } catch (e) {29 hasThrown = true;...
CommonUtilities.js
Source:CommonUtilities.js
...103 });104 };105106 this.switchAppContext = function (context) {107 return browser.driver.getCurrentContext().then(function (currentContext) {108 console.log("******* Current context is: " + currentContext);109 browser.driver.selectContext(context).then(function () {110 browser.driver.getCurrentContext().then(function (newContext) {111 console.log("******* Switched context to: " + newContext);112 return newContext;113 });114 });115 });116 };117118 this.acceptAlertIfExists = function() {119 browser.wait(expCondn.alertIsPresent(), 3000).catch(function(){console.log("alert not found")});120 browser.driver.switchTo().alert().accept().catch(function(){console.log("alert found")});121 };122123 /**124 * Sets the picker wheel to the value specified.
...
webview-browser-tester-e2e-specs.js
Source:webview-browser-tester-e2e-specs.js
...46 it('should start android session using webview browser tester', async () => {47 // await driver.setUrl('http://google.com');48 await driver.setUrl(`http://${HOST}:${PORT}/test/guinea-pig`);49 // make sure we are in the right context50 await driver.getCurrentContext().should.eventually.eql("CHROMIUM");51 let el = await driver.findElOrEls('id', 'i am a link', false);52 await driver.click(el.ELEMENT);53 el = await driver.findElOrEls('id', 'I am another page title', false);54 el.should.exist;55 });...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!