How to use driver.isWebContext method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

context-specs.js

Source:context-specs.js Github

copy

Full Screen

...127 });128 describe('isWebContext', function () {129 it('should return true if current context is not native', async function () {130 driver.curContext = 'current_context';131 await driver.isWebContext().should.be.true;132 });133 });134 describe('startChromedriverProxy', function () {135 beforeEach(() => {136 sandbox.stub(driver, 'onChromedriverStop');137 });138 it('should start new chromedriver session', async function () {139 await driver.startChromedriverProxy('WEBVIEW_1');140 driver.sessionChromedrivers.WEBVIEW_1.should.be.equal(driver.chromedriver);141 driver.chromedriver.start.getCall(0).args[0]142 .chromeOptions.androidDeviceSerial.should.be.equal('device_id');143 driver.chromedriver.proxyPort.should.be.equal(4444);144 driver.chromedriver.proxyReq.bind.calledWithExactly(driver.chromedriver);145 driver.proxyReqRes.should.be.equal('proxy');...

Full Screen

Full Screen

element-specs.js

Source:element-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import XCUITestDriver from '../../..';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import { withMocks, withSandbox } from 'appium-test-support';6import _ from 'lodash';7chai.should();8chai.use(chaiAsPromised);9describe('element commands', function () {10 let driver = new XCUITestDriver();11 let proxyStub = sinon.stub(driver, 'proxyCommand');12 afterEach(function () {13 proxyStub.reset();14 });15 describe('setValueImmediate', withMocks({driver}, (mocks) => {16 afterEach(function () {17 mocks.verify();18 });19 it('should call setValue', async function () {20 mocks.driver21 .expects('setValue')22 .once().withExactArgs('hello', 2).returns();23 await driver.setValueImmediate('hello', 2);24 });25 }));26 describe('getAttribute', function () {27 const elementId = 2;28 const attribute = 'enabled';29 afterEach(function () {30 proxyStub.calledOnce.should.be.true;31 });32 it('should properly parse boolean true attribute presented as integer', async function () {33 proxyStub.returns(1);34 (await driver.getAttribute(attribute, elementId)).should.eql('true');35 });36 it('should properly parse boolean false attribute presented as integer', async function () {37 proxyStub.returns(0);38 (await driver.getAttribute(attribute, elementId)).should.eql('false');39 });40 it('should properly parse integer attribute presented as string', async function () {41 proxyStub.returns('0');42 (await driver.getAttribute(attribute, elementId)).should.eql('0');43 });44 it('should properly parse boolean attribute presented as bool', async function () {45 proxyStub.returns(false);46 (await driver.getAttribute(attribute, elementId)).should.eql('false');47 });48 it('should properly parse null attribute', async function () {49 proxyStub.returns(null);50 _.isNull(await driver.getAttribute(attribute, elementId)).should.be.true;51 });52 it('should properly parse string attribute', async function () {53 proxyStub.returns('value');54 (await driver.getAttribute(attribute, elementId)).should.eql('value');55 });56 });57 describe('getAttribute - special contentSize', withSandbox({}, function (S) {58 it('should call the internal method instead of WDA', async function () {59 const getContentSizeStub = S.sandbox.stub(driver, 'getContentSize');60 getContentSizeStub.returns('foo');61 (await driver.getAttribute('contentSize', 2)).should.eql('foo');62 proxyStub.called.should.be.false;63 getContentSizeStub.calledOnce.should.be.true;64 });65 }));66 describe('getContentSize', withSandbox({}, function (S) {67 const el = {ELEMENT: '1234'};68 let getAttrStub, getRectStub, findElStub, getSizeStub, getLocationStub;69 beforeEach(function () {70 getAttrStub = S.sandbox.stub(driver, 'getAttribute');71 getRectStub = S.sandbox.stub(driver, 'getElementRect');72 findElStub = S.sandbox.stub(driver, 'findElOrEls');73 getSizeStub = S.sandbox.stub(driver, 'getSize');74 getLocationStub = S.sandbox.stub(driver, 'getLocationInView');75 });76 describe('web context', function () {77 const oldContext = driver.curContext;78 beforeEach(function () {79 driver.curContext = 'WEBVIEW';80 });81 afterEach(function () {82 driver.curContext = oldContext;83 });84 it('should throw when in a web context', async function () {85 await driver.getContentSize(el).should.eventually.be.rejectedWith(/not yet implemented/);86 });87 });88 it('should throw if trying to get contentSize of something other than table or collection', async function () {89 getAttrStub.returns('XCUIElementTypeStatusBar');90 await driver.getContentSize(el).should.eventually.be.rejectedWith(/Can't get content size for type/);91 });92 it('should simply get the rect if just one child', async function () {93 getAttrStub.returns('XCUIElementTypeTable');94 findElStub.returns([{ELEMENT: 'foo'}]);95 getRectStub.returns({x: 0, y: 0, height: 100, width: 200});96 getSizeStub.returns({height: 100, width: 200});97 getLocationStub.returns({x: 0, y: 0});98 const contentSizeObj = JSON.parse(await driver.getContentSize(el));99 contentSizeObj.should.eql({100 width: 200,101 height: 100,102 top: 0,103 left: 0,104 scrollableOffset: 100105 });106 getRectStub.calledOnce.should.be.true;107 });108 it('should get simple difference in element positions of a table', async function () {109 const el1 = {ELEMENT: 1}, el2 = {ELEMENT: 2};110 getAttrStub.returns('XCUIElementTypeTable');111 findElStub.returns([el1, el2]);112 getRectStub.withArgs(el1).returns({x: 0, y: 10, width: 50, height: 60});113 getRectStub.withArgs(el2).returns({x: 10, y: 80, width: 60, height: 100});114 getSizeStub.returns({height: 100, width: 200});115 getLocationStub.returns({x: 0, y: 0});116 const contentSizeObj = JSON.parse(await driver.getContentSize(el));117 contentSizeObj.should.eql({118 width: 200,119 height: 100,120 top: 0,121 left: 0,122 scrollableOffset: 170123 });124 getRectStub.calledTwice.should.be.true;125 });126 it('should be sensitive to row items in the case of a collection view', async function () {127 // set up a collection view with 3 rows of 2 elements.128 // give the last row just one element129 const fixtures = [130 {id: 1, x: 0, y: 0, height: 50}, {id: 2, x: 50, y: 0, height: 50},131 {id: 3, x: 0, y: 60, height: 50}, {id: 4, x: 50, y: 60, height: 50},132 {id: 5, x: 0, y: 120, height: 50}133 ];134 const scrollableOffset = 170; // 3 rows plus space between two135 getAttrStub.returns('XCUIElementTypeCollectionView');136 findElStub.returns(fixtures.map(el => ({ELEMENT: el.id})));137 for (const item of fixtures) {138 getRectStub.withArgs({ELEMENT: item.id}).returns(item);139 }140 getSizeStub.returns({height: 100, width: 200});141 getLocationStub.returns({x: 0, y: 0});142 const contentSizeObj = JSON.parse(await driver.getContentSize(el));143 contentSizeObj.should.eql({144 width: 200,145 height: 100,146 top: 0,147 left: 0,148 scrollableOffset149 });150 getRectStub.callCount.should.equal(3);151 });152 }));153 describe('setValue', function () {154 const elementId = 2;155 const expectedEndpoint = `/element/${elementId}/value`;156 const expectedMethod = 'POST';157 describe('success', function () {158 afterEach(function () {159 proxyStub.calledOnce.should.be.true;160 proxyStub.firstCall.args[0].should.eql(expectedEndpoint);161 proxyStub.firstCall.args[1].should.eql(expectedMethod);162 });163 it('should proxy string as array of characters', async function () {164 await driver.setValue('hello', elementId);165 proxyStub.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']});166 });167 it('should proxy integer as array of characters', async function () {168 await driver.setValue(1234, elementId);169 proxyStub.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']});170 });171 it('should proxy string array as array of characters', async function () {172 await driver.setValue(['hel', 'lo'], elementId);173 proxyStub.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']});174 });175 it('should proxy integer array as array of characters', async function () {176 await driver.setValue([1234], elementId);177 proxyStub.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']});178 });179 });180 describe('failure', function () {181 it('should throw invalid argument exception for null', async function () {182 await driver.setValue(null, elementId)183 .should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: 'null'/);184 });185 it('should throw invalid argument exception for object', async function () {186 await driver.setValue({hi: 'there'}, elementId)187 .should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: '{"hi":"there"}'/);188 });189 });190 });191 describe('getLocation for web elements', function () {192 let driver = new XCUITestDriver();193 const oldContext = driver.curContext;194 const webEl = {ELEMENT: '5000'};195 const fixtureXOffset = 100, fixtureYOffset = 200;196 let executeStub;197 let atomsElStub;198 let atomStub;199 let proxyStub;200 before(function () {201 executeStub = sinon.stub(driver, 'execute').returns([fixtureXOffset, fixtureYOffset]);202 atomsElStub = sinon.stub(driver, 'useAtomsElement').callsFake((el) => el);203 atomStub = sinon.stub(driver, 'executeAtom').returns({x: 0, y: 0});204 proxyStub = sinon.stub(driver, 'proxyCommand');205 });206 after(function () {207 executeStub.reset();208 atomsElStub.reset();209 atomStub.reset();210 proxyStub.reset();211 });212 beforeEach(function () {213 driver.curContext = 'fake web context';214 });215 afterEach(function () {216 driver.curContext = oldContext;217 executeStub.resetHistory();218 atomsElStub.resetHistory();219 atomStub.resetHistory();220 proxyStub.resetHistory();221 });222 it('should get location relative to scroll by default', async function () {223 const loc = await driver.getLocation(webEl);224 executeStub.calledOnce.should.be.false;225 atomStub.calledOnce.should.be.true;226 atomStub.firstCall.args[0].should.eql('get_top_left_coordinates');227 loc.x.should.equal(0);228 loc.y.should.equal(0);229 });230 it('should get location relative to document with absoluteWebLocations cap', async function () {231 driver.opts.absoluteWebLocations = true;232 const loc = await driver.getLocation(webEl);233 executeStub.calledOnce.should.be.true;234 atomStub.calledOnce.should.be.true;235 atomStub.firstCall.args[0].should.eql('get_top_left_coordinates');236 loc.x.should.equal(fixtureXOffset);237 loc.y.should.equal(fixtureYOffset);238 });239 });240 describe('getElementRect', function () {241 let driver = new XCUITestDriver();242 const elem = {ELEMENT: '5000'};243 const getNativeRectStub = sinon.stub(driver, 'getNativeRect').returns({x: 0, y: 50, width: 100, height: 200});244 const getLocationStub = sinon.stub(driver, 'getLocation').returns({x: 0, y: 50});245 const getSizeStub = sinon.stub(driver, 'getSize').returns({width: 100, height: 200});246 let isWebContextStub;247 afterEach(function () {248 getNativeRectStub.resetHistory();249 getLocationStub.resetHistory();250 getSizeStub.resetHistory();251 proxyStub.resetHistory();252 if (isWebContextStub) {253 isWebContextStub.restore();254 }255 });256 it('should get element rect in native context', async function () {257 isWebContextStub = sinon.stub(driver, 'isWebContext').returns(false);258 const rect = await driver.getElementRect(elem);259 isWebContextStub.calledOnce.should.be.true;260 getNativeRectStub.calledOnce.should.be.true;261 getLocationStub.calledOnce.should.be.false;262 getSizeStub.calledOnce.should.be.false;263 rect.x.should.eql(0);264 rect.y.should.eql(50);265 rect.width.should.eql(100);266 rect.height.should.eql(200);267 });268 it('should get element rect in Web context', async function () {269 isWebContextStub = sinon.stub(driver, 'isWebContext').returns(true);270 const rect = await driver.getElementRect(elem);271 isWebContextStub.calledOnce.should.be.true;272 getNativeRectStub.calledOnce.should.be.false;273 getLocationStub.calledOnce.should.be.true;274 getSizeStub.calledOnce.should.be.true;275 rect.x.should.eql(0);276 rect.y.should.eql(50);277 rect.width.should.eql(100);278 rect.height.should.eql(200);279 });280 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var expect = chai.expect;7var should = chai.should();8var driver = wd.promiseChainRemote('

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2driver.init({3}).then(function () {4 return driver.isWebContext();5}).then(function (isWebContext) {6 console.log('isWebContext: ', isWebContext);7}).fin(function () {8 return driver.quit();9}).done();10driver.context('WEBVIEW_1');11driver.contexts().then(function (contexts) {12 console.log('contexts: ', contexts);13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.android()).build();3driver.isWebContext().then(function(isWebContext) {4 console.log('isWebContext: ' + isWebContext);5});6driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5 .forBrowser('chrome')6 .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.quit();11driver.isWebContext().then(function(isWebContext) {12 console.log(isWebContext);13});14driver.isWebContext().then(function(isWebContext) {15 console.log(isWebContext);16});17driver.isWebContext().then(function(isWebContext) {18 console.log(isWebContext);19});20driver.isWebContext().then(function(isWebContext) {21 console.log(isWebContext);22});23driver.isWebContext().then(function(isWebContext) {24 console.log(isWebContext);25});26driver.isWebContext().then(function(isWebContext) {27 console.log(isWebContext);28});29driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const chaiString = require('chai-string');5const chaiSubset = require('chai-subset');6const AndroidDriver = require('appium-android-driver');7const { getDriver } = require('appium-base-driver');8const { withRetries } = require('appium-support');9const { retryInterval } = require('asyncbox');10chai.use(chaiAsPromised);11chai.use(chaiString);12chai.use(chaiSubset);13chai.should();14describe('AndroidDriver', function () {15 this.timeout(60000);16 let driver;17 let caps = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new AndroidDriver();2driver.isWebContext().then(function(isWebContext){3 console.log(isWebContext);4});5var driver = new IOSDriver();6driver.isWebContext().then(function(isWebContext){7 console.log(isWebContext);8});9var driver = new WindowsDriver();10driver.isWebContext().then(function(isWebContext){11 console.log(isWebContext);12});13var driver = new MacDriver();14driver.isWebContext().then(function(isWebContext){15 console.log(isWebContext);16});17var driver = new ChromeDriver();18driver.isWebContext().then(function(isWebContext){19 console.log(isWebContext);20});21var driver = new FirefoxDriver();22driver.isWebContext().then(function(isWebContext){23 console.log(isWebContext);24});25var driver = new SafariDriver();26driver.isWebContext().then(function(isWebContext){27 console.log(isWebContext);28});29var driver = new OperaDriver();30driver.isWebContext().then(function(isWebContext){31 console.log(isWebContext);32});33var driver = new EdgeDriver();34driver.isWebContext().then(function(isWebContext){35 console.log(isWebContext);36});37var driver = new InternetExplorerDriver();38driver.isWebContext().then(function(isWebContext){39 console.log(isWebContext);40});41var driver = new PhantomJSDriver();42driver.isWebContext().then(function(isWebContext){43 console.log(isWebContext);44});45var driver = new RemoteDriver();46driver.isWebContext().then(function(isWebContext){47 console.log(isWebContext);48});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful