How to use parseCapsForInnerDriver method in Appium

Best JavaScript code snippet using appium

utils-specs.js

Source:utils-specs.js Github

copy

Full Screen

...4import { BASE_CAPS, W3C_CAPS } from './helpers';5const should = chai.should();6chai.use(chaiAsPromised);7describe('utils', function () {8 describe('parseCapsForInnerDriver()', function () {9 it('should return JSONWP caps unchanged if only JSONWP caps provided', function () {10 let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(BASE_CAPS);11 desiredCaps.should.deep.equal(BASE_CAPS);12 processedJsonwpCapabilities.should.deep.equal(BASE_CAPS);13 should.not.exist(processedW3CCapabilities);14 });15 it('should return W3C caps unchanged if only W3C caps were provided', function () {16 let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(undefined, W3C_CAPS);17 desiredCaps.should.deep.equal(BASE_CAPS);18 should.not.exist(processedJsonwpCapabilities);19 processedW3CCapabilities.should.deep.equal(W3C_CAPS);20 });21 it('should return JSONWP and W3C caps if both were provided', function () {22 let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(BASE_CAPS, W3C_CAPS);23 desiredCaps.should.deep.equal(BASE_CAPS);24 processedJsonwpCapabilities.should.deep.equal(BASE_CAPS);25 processedW3CCapabilities.should.deep.equal(W3C_CAPS);26 });27 it('should include default capabilities in results', function () {28 let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(BASE_CAPS, W3C_CAPS, {}, {foo: 'bar'});29 desiredCaps.should.deep.equal({foo: 'bar', ...BASE_CAPS});30 processedJsonwpCapabilities.should.deep.equal({foo: 'bar', ...BASE_CAPS});31 processedW3CCapabilities.alwaysMatch.should.deep.equal({'appium:foo': 'bar', ...insertAppiumPrefixes(BASE_CAPS)});32 });33 it('should reject if W3C caps are not passing constraints', function () {34 (() => parseCapsForInnerDriver(undefined, W3C_CAPS, {hello: {presence: true}})).should.throw(/'hello' can't be blank/);35 });36 it('should only accept W3C caps that have passing constraints', function () {37 let w3cCaps = {38 ...W3C_CAPS,39 firstMatch: [40 {foo: 'bar'},41 {hello: 'world'},42 ],43 };44 let {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(BASE_CAPS, w3cCaps, {hello: {presence: true}});45 const expectedResult = {hello: 'world', ...BASE_CAPS};46 desiredCaps.should.deep.equal(expectedResult);47 processedJsonwpCapabilities.should.deep.equal({...BASE_CAPS});48 processedW3CCapabilities.alwaysMatch.should.deep.equal(insertAppiumPrefixes(expectedResult));49 });50 it('should add appium prefixes to W3C caps that are not standard in W3C', function () {51 parseCapsForInnerDriver(undefined, {52 alwaysMatch: {platformName: 'Fake', propertyName: 'PROP_NAME'},53 }).processedW3CCapabilities.should.deep.equal({54 alwaysMatch: {55 platformName: 'Fake',56 'appium:propertyName': 'PROP_NAME',57 },58 firstMatch: [{}],59 });60 });61 it('should fall back to MJSONWP caps if MJSONWP contains extraneous caps that aren not in W3C', function () {62 let jsonwpCaps = {63 ...BASE_CAPS,64 automationName: 'Fake',65 };66 const {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver(jsonwpCaps, {67 alwaysMatch: {platformName: 'Fake', propertyName: 'PROP_NAME'},68 });69 should.not.exist(processedW3CCapabilities);70 desiredCaps.should.eql(jsonwpCaps);71 processedJsonwpCapabilities.should.eql(jsonwpCaps);72 });73 it('should fall back to MJSONWP caps if W3C capabilities are invalid', function () {74 let w3cCapabilities = {75 alwaysMatch: {platformName: 'Fake', propertyName: 'PROP_NAME'},76 };77 let constraints = {78 deviceName: {79 presence: true,80 }81 };82 const {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities} = parseCapsForInnerDriver({...BASE_CAPS}, w3cCapabilities, constraints);83 should.not.exist(processedW3CCapabilities);84 desiredCaps.should.eql(BASE_CAPS);85 processedJsonwpCapabilities.should.eql(BASE_CAPS);86 });87 });88 describe('insertAppiumPrefixes()', function () {89 it('should apply prefixes to non-standard capabilities', function () {90 insertAppiumPrefixes({91 someCap: 'someCap',92 }).should.deep.equal({93 'appium:someCap': 'someCap',94 });95 });96 it('should not apply prefixes to standard capabilities', function () {...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1import _ from 'lodash';2import logger from './logger';3import { processCapabilities } from 'appium-base-driver';4function inspectObject (args) {5 function getValueArray (obj, indent = ' ') {6 if (!_.isObject(obj)) {7 return [obj];8 }9 let strArr = ['{'];10 for (let [arg, value] of _.toPairs(obj)) {11 if (!_.isObject(value)) {12 strArr.push(`${indent} ${arg}: ${value}`);13 } else {14 value = getValueArray(value, `${indent} `);15 strArr.push(`${indent} ${arg}: ${value.shift()}`);16 strArr.push(...value);17 }18 }19 strArr.push(`${indent}}`);20 return strArr;21 }22 for (let [arg, value] of _.toPairs(args)) {23 value = getValueArray(value);24 logger.info(` ${arg}: ${value.shift()}`);25 for (let val of value) {26 logger.info(val);27 }28 }29}30/**31 * Takes the caps that were provided in the request and translates them32 * into caps that can be used by the inner drivers.33 * @param {Object} jsonwpCaps34 * @param {Object} w3cCapabilities35 * @param {Object} constraints36 * @param {Object} defaultCapabilities37 */38function parseCapsForInnerDriver (jsonwpCaps, w3cCapabilities, constraints={}, defaultCapabilities={}) {39 // Check if the caller sent JSONWP caps, W3C caps, or both40 const hasW3CCaps = _.isPlainObject(w3cCapabilities);41 const hasJSONWPCaps = _.isPlainObject(jsonwpCaps);42 // Make copies of the capabilities that include the default capabilities43 if (hasW3CCaps) {44 w3cCapabilities = {45 ...w3cCapabilities,46 alwaysMatch: {47 ...defaultCapabilities,48 ...w3cCapabilities.alwaysMatch,49 },50 };51 }52 if (hasJSONWPCaps) {53 jsonwpCaps = {54 ...defaultCapabilities,55 ...jsonwpCaps,56 };57 }58 // Get MJSONWP caps59 let desiredCaps = {};60 let processedJsonwpCapabilities = null;61 if (hasJSONWPCaps) {62 desiredCaps = jsonwpCaps;63 processedJsonwpCapabilities = {...desiredCaps};64 }65 // Get W3C caps66 let processedW3CCapabilities = null;67 if (hasW3CCaps) {68 // Call the process capabilities algorithm to find matching caps on the W3C69 // (see: https://github.com/jlipps/simple-wd-spec#processing-capabilities)70 let matchingW3CCaps;71 try {72 matchingW3CCaps = processCapabilities(w3cCapabilities, constraints, true);73 } catch (err) {74 if (jsonwpCaps) {75 logger.warn(`Could not parse W3C capabilities: ${err.message}. Falling back to JSONWP protocol.`);76 return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities};77 } else {78 throw err;79 }80 }81 desiredCaps = matchingW3CCaps;82 // Create a new w3c capabilities payload that contains only the matching caps in `alwaysMatch`83 processedW3CCapabilities = {84 alwaysMatch: {...insertAppiumPrefixes(desiredCaps)},85 firstMatch: [{}],86 };87 // If we found extraneuous keys in JSONWP caps, fall back to JSONWP88 if (hasJSONWPCaps) {89 let differingKeys = _.difference(_.keys(jsonwpCaps), _.keys(matchingW3CCaps));90 if (!_.isEmpty(differingKeys)) {91 logger.warn(`The following capabilities were provided in the JSONWP desired capabilities that are missing ` +92 `in W3C capabilities: ${JSON.stringify(differingKeys)}. Falling back to JSONWP protocol.`);93 desiredCaps = jsonwpCaps;94 return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities: null};95 }96 }97 }98 return {desiredCaps, processedJsonwpCapabilities, processedW3CCapabilities};99}100/**101 * Takes a capabilities objects and prefixes capabilities with `appium:`102 * @param {Object} caps Desired capabilities object103 */104function insertAppiumPrefixes (caps) {105 // Standard, non-prefixed capabilities (see https://www.w3.org/TR/webdriver/#dfn-table-of-standard-capabilities)106 const STANDARD_CAPS = [107 'browserName',108 'browserVersion',109 'platformName',110 'acceptInsecureCerts',111 'pageLoadStrategy',112 'proxy',113 'setWindowRect',114 'timeouts',115 'unhandledPromptBehavior'116 ];117 let prefixedCaps = {};118 for (let [name, value] of _.toPairs(caps)) {119 if (STANDARD_CAPS.includes(name) || name.includes(':')) {120 prefixedCaps[name] = value;121 } else {122 prefixedCaps[`appium:${name}`] = value;123 }124 }125 return prefixedCaps;126}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var appiumDriver = new AppiumDriver();2appiumDriver.parseCapsForInnerDriver(caps);3var appiumDriver = new AppiumDriver();4appiumDriver.parseCapsForInnerDriver(caps);5var appiumDriver = new AppiumDriver();6appiumDriver.parseCapsForInnerDriver(caps);7var appiumDriver = new AppiumDriver();8appiumDriver.parseCapsForInnerDriver(caps);9var appiumDriver = new AppiumDriver();10appiumDriver.parseCapsForInnerDriver(caps);11var appiumDriver = new AppiumDriver();12appiumDriver.parseCapsForInnerDriver(caps);13var appiumDriver = new AppiumDriver();14appiumDriver.parseCapsForInnerDriver(caps);15var appiumDriver = new AppiumDriver();16appiumDriver.parseCapsForInnerDriver(caps);17var appiumDriver = new AppiumDriver();18appiumDriver.parseCapsForInnerDriver(caps);19var appiumDriver = new AppiumDriver();20appiumDriver.parseCapsForInnerDriver(caps);21var appiumDriver = new AppiumDriver();22appiumDriver.parseCapsForInnerDriver(caps);23var appiumDriver = new AppiumDriver();24appiumDriver.parseCapsForInnerDriver(caps);25var appiumDriver = new AppiumDriver();26appiumDriver.parseCapsForInnerDriver(caps);27var appiumDriver = new AppiumDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1const parseCapsForInnerDriver = require('appium-base-driver').parseCapsForInnerDriver;2const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);3const parseCapsForInnerDriver = require('appium-base-driver').parseCapsForInnerDriver;4const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);5const { parseCapsForInnerDriver } = require('appium-base-driver');6const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);7const { parseCapsForInnerDriver } = require('appium-base-driver');8const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);9const { parseCapsForInnerDriver } = require('appium-base-driver');10const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);11const { parseCapsForInnerDriver } = require('appium-base-driver');12const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);13const { parseCapsForInnerDriver } = require('appium-base-driver');14const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);15const { parseCapsForInnerDriver } = require('appium-base-driver');16const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);17const { parseCapsForInnerDriver } = require('appium-base-driver');18const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);19const { parseCapsForInnerDriver } = require('appium-base-driver');20const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);21const { parseCapsForInnerDriver } = require('appium-base-driver');22const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);23const { parseCapsForInnerDriver } = require('appium-base-driver');24const parsedCaps = parseCapsForInnerDriver(caps, this.capsConstraints);25const { parseCapsForInnerDriver } = require('appium

Full Screen

Using AI Code Generation

copy

Full Screen

1var caps = driver.parseCapsForInnerDriver(caps);2var caps = driver.parseCapsForInnerDriver(caps);3var caps = driver.parseCapsForInnerDriver(caps);4var caps = driver.parseCapsForInnerDriver(caps);5var caps = driver.parseCapsForInnerDriver(caps);6var caps = driver.parseCapsForInnerDriver(caps);7var caps = driver.parseCapsForInnerDriver(caps);8var caps = driver.parseCapsForInnerDriver(caps);9var caps = driver.parseCapsForInnerDriver(caps);10var caps = driver.parseCapsForInnerDriver(caps);

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium/lib/appium.js').AppiumDriver;2var appiumDriver = new AppiumDriver();3var caps = {'platformName':'iOS', 'deviceName':'iPhone Simulator', 'app':'/Users/saurabh/Desktop/HelloWorld.app'};4var innerDriver = appiumDriver.parseCapsForInnerDriver(caps);5console.log(innerDriver);6{ platformName: 'iOS',7 app: '/Users/saurabh/Desktop/HelloWorld.app' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var appiumDriver = new webdriver.Builder()3 .withCapabilities({'deviceName':'Android',4 })5 .build();6var innerDriver = appiumDriver.parseCapsForInnerDriver({'deviceName':'Android',7 });8console.log(innerDriver);9var webdriver = require('selenium-webdriver');10var androidDriver = new webdriver.Builder()11 .withCapabilities({'deviceName':'Android',12 })13 .build();14var innerDriver = androidDriver.parseCapsForInnerDriver({'deviceName':'Android',15 });16console.log(innerDriver);17var webdriver = require('selenium-webdriver');18var iosDriver = new webdriver.Builder()19 .withCapabilities({'deviceName':'iPhone Simulator',20 })21 .build();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var asserters = require('wd/lib/asserters');3var caps = require('./caps.js');4var async = require('async');5var desired = caps.parseCapsForInnerDriver({browserName: 'chrome'});6var browser = wd.promiseChainRemote('localhost', 4723);7 .init(desired)8 .elementById('i am a link')9 .click()10 .waitForElementById('i_am_an_id', asserters.isDisplayed, 10000)11 .text().should.become('I am some other page content')12 .nodeify(done);13Unhandled rejection Error: Unable to parse remote response: {"sessionId":"a5a5c5d5-5e5f-5c5d-5b5a-5a5b5c5d5e5f","status":13,"value":{"message":"unknown error: Chrome version must be >= 53.0.2785.0\n (Driver info: chromedriver=2.24.417424 (0),platform=Linux 3.13.0-103-generic x86_64)"}}14 at parseHttpResponse (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/appium-support/lib/jsonwp-proxy/proxy.js:241:13)15 at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/bluebird/js/release/util.js:16:23)16 at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/bluebird/js/release/promise.js:512:31)17 at Promise._settlePromise (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/bluebird/js/release/promise.js:569:18)18 at Promise._settlePromise0 (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/node_modules/bluebird/js/release/promise.js:614:10)19 at Promise._settlePromises (/usr/local/lib/node_modules/app

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 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