How to use startWdaSession method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source: driver.js Github

copy

Full Screen

...239 try {240 await retryInterval(15, 500, async () => {241 log.debug('Sending createSession command to WDA');242 try {243 await this.startWdaSession(this.opts.bundleId, this.opts.processArguments);244 } catch (err) {245 log.debug('Failed to create session. Retrying...');246 throw err;247 }248 });249 } catch (err) {250 log.debug(`Unable to start WebDriverAgent session: ${err.message}`);251 if (tries > WDA_STARTUP_RETRIES) throw err;252 await uninstallAndRestart();253 }254 if (typeof this.opts.preventWDAAttachments !== 'undefined') {255 await adjustWDAAttachmentsPermissions(this.opts.preventWDAAttachments ? '555' : '755');256 }257 }...

Full Screen

Full Screen

index.js

Source: index.js Github

copy

Full Screen

1console.log("##########################################");2console.log(3 `Testwa-Appium based on appium@${4 require("appium/​package.json").version5 }!\nStarting...`6);7console.log("JAVA_HOME:", process.env.JAVA_HOME);8console.log("ANDROID_HOME:", process.env.ANDROID_HOME);9console.log("##########################################");10process.env.http_proxy = "";11process.env.https_proxy = "";12const argv = require("yargs").argv;13const apkUtilsMethods = require("appium/​node_modules/​appium-adb/​build/​lib/​tools/​apk-utils");14const { install, startApp, installFromDevicePath } = apkUtilsMethods;15const xpathLocators = {16 def: {17 en: '/​/​*[@content-desc="Install"]|/​/​*[@text="Install"]',18 zh: '/​/​*[@content-desc="安装"]|/​/​*[@text="安装"]',19 retry: 320 },21 xiaomi: {22 en: '/​/​*[@content-desc="Install"]|/​/​*[@text="Install"]',23 zh: '/​/​*[@content-desc="继续安装"]|/​/​*[@text="继续安装"]'24 },25 oppo: {26 en: '/​/​*[@content-desc="Install"]|/​/​*[@text="Install"]',27 zh: '/​/​*[@content-desc="安装"]|/​/​*[@text="安装"]',28 retry: 829 },30 samsung: {31 en: '/​/​*[@content-desc="CONFIRM"]|/​/​*[@text="CONFIRM"]',32 zh: '/​/​*[@content-desc="确定"]|/​/​*[@text="确定"]'33 }34};35const getInstallXpathLocator = function (manufacturer, language) {36 let lan;37 let retry;38 if (manufacturer && xpathLocators.hasOwnProperty(manufacturer)) {39 lan = language40 ? xpathLocators[manufacturer][language]41 : xpathLocators[manufacturer].zh;42 retry = xpathLocators[manufacturer].retry43 ? xpathLocators[manufacturer].retry44 : xpathLocators.def.retry;45 return [lan, retry];46 }47 lan = language ? xpathLocators.def[language] : xpathLocators.def.zh;48 retry = xpathLocators.def.retry;49 return [lan, retry];50};51const forceInstall = async function (androidDriver) {52 console.log("##########################################");53 console.log("testwa:forceInstall");54 console.log("##########################################");55 let manufacturer = androidDriver.caps.deviceManufacturer.toLowerCase();56 let language = androidDriver.caps.language.toLowerCase();57 let [locator, retries] = getInstallXpathLocator(manufacturer, language);58 let func = async function () {59 try {60 await sleep(2000);61 let element = await androidDriver.findElOrEls("xpath", locator, false);62 await androidDriver.click(element.ELEMENT);63 } catch (err) {64 logTestwa.errorAndThrow(err.message);65 }66 };67 retry(retries, func);68};69apkUtilsMethods.install = async function () {70 console.log("##########################################");71 console.log("3.testwa:install");72 console.log("##########################################");73 /​/​unlockType:不安装工具包的标志74 if (!argv.unlockType) {75 console.log("##########################################");76 console.log("4.testwa:apkUtilsMethods.install");77 console.log("##########################################");78 const installed = install.apply(this, arguments);79 /​/​ forceInstall(androidDriver);80 return installed;81 }82};83apkUtilsMethods.startApp = async function () {84 const stdout = await startApp.apply(this, arguments);85 this.appLaunchTotalTime = stdout.match(/​TotalTime: (.*)/​)[1]86 ? +stdout.match(/​TotalTime: (.*)/​)[1]87 : "无法获取";88 console.log("##########################################");89 console.log("5.testwa:startApp", this.appLaunchTotalTime);90 console.log("##########################################");91 return stdout;92};93apkUtilsMethods.installFromDevicePath = async function () {94 console.log("##########################################");95 console.log("testwa:installFromDevicePath");96 console.log("##########################################");97 const installed = installFromDevicePath.apply(this, arguments);98 /​/​ forceInstall(androidDriver);99 return installed;100};101require("appium/​node_modules/​appium-android-driver/​build/​lib/​android-helpers.js").default.pushSettingsApp = async function () { };102const {103 UiAutomator2Server104} = require("appium/​node_modules/​appium-uiautomator2-driver/​build/​lib/​uiautomator2.js");105/​/​ .default;106const {107 XCUITestDriver108} = require("appium/​node_modules/​appium-xcuitest-driver/​build/​lib/​driver.js");109const { main } = require("appium");110const installServerApk = UiAutomator2Server.prototype.installServerApk;111const startWdaSession = XCUITestDriver.prototype.startWdaSession;112const installApp = XCUITestDriver.prototype.installApp;113XCUITestDriver.prototype.startWdaSession = async function () {114 const startTime = new Date().getTime();115 await startWdaSession.apply(this, arguments);116 this.startAppTime = new Date().getTime() - startTime;117 console.log("##########################################");118 console.log("testwa:startWdaSession", this.startAppTime);119 console.log("##########################################");120};121XCUITestDriver.prototype.installApp = async function () {122 const install = this.opts.device.install;123 this.opts.device.install = async (...args) => {124 const startTime = new Date().getTime();125 await install.apply(this, args);126 this.installAppTime = new Date().getTime() - startTime;127 console.log("##########################################");128 console.log("testwa:install ios App", this.installAppTime);129 console.log("##########################################");130 };131 return installApp.apply(this, arguments);132};133UiAutomator2Server.prototype.installServerApk = async function () {134 console.log("##########################################");135 console.log("2.testwa:installServerApk");136 console.log("##########################################");137 (await this.adb.shell(["pm", "path", "io.appium.uiautomator2.server"])) ||138 (await installServerApk.apply(this, arguments));139};140if (require.main === module) {141 main(argv).catch(e => {142 console.log("##########################################");143 console.error(e.message, "wappium 启动失败");144 console.log("##########################################");145 });146}...

Full Screen

Full Screen

language-specs.js

Source: language-specs.js Github

copy

Full Screen

...33 };34 let driver = new XCUITestDriver(desiredCapabilities);35 let proxySpy = sinon.stub(driver, 'proxyCommand');36 driver.validateDesiredCaps(desiredCapabilities);37 await driver.startWdaSession(desiredCapabilities.bundleId, desiredCapabilities.processArguments);38 proxySpy.calledOnce.should.be.true;39 proxySpy.firstCall.args[0].should.eql('/​session');40 proxySpy.firstCall.args[1].should.eql('POST');41 proxySpy.firstCall.args[2].should.eql(expectedWDACapabilities);42 });43 });44 describe('send process args, language and locale json', function () {45 it('should send translated POST /​session request with valid desired caps to WDA', async function () {46 const processArguments = {47 args: ['a', 'b', 'c'],48 env: { 'a': 'b', 'c': 'd' }49 };50 const augmentedProcessArgumentsWithLanguage = {51 args: [52 ...processArguments.args,53 '-AppleLanguages', `(${LANGUAGE})`,54 '-NSLanguages', `(${LANGUAGE})`,55 '-AppleLocale', LOCALE,56 ],57 env: processArguments.env58 };59 const expectedWDACapabilities = {60 desiredCapabilities: {61 bundleId: 'com.test.app',62 arguments: augmentedProcessArgumentsWithLanguage.args,63 environment: processArguments.env,64 shouldWaitForQuiescence: true,65 shouldUseTestManagerForVisibilityDetection: true,66 maxTypingFrequency: 60,67 shouldUseSingletonTestManager: true,68 }69 };70 const desiredCapabilities = {71 platformName: 'iOS',72 platformVersion: '9.3',73 deviceName: 'iPhone 6',74 app: 'testapp.app',75 language: LANGUAGE,76 locale: LOCALE,77 bundleId: expectedWDACapabilities.desiredCapabilities.bundleId,78 processArguments79 };80 let driver = new XCUITestDriver(desiredCapabilities);81 let proxySpy = sinon.stub(driver, 'proxyCommand');82 driver.validateDesiredCaps(desiredCapabilities);83 await driver.startWdaSession(desiredCapabilities.bundleId, desiredCapabilities.processArguments);84 proxySpy.calledOnce.should.be.true;85 proxySpy.firstCall.args[0].should.eql('/​session');86 proxySpy.firstCall.args[1].should.eql('POST');87 proxySpy.firstCall.args[2].should.eql(expectedWDACapabilities);88 });89 });...

Full Screen

Full Screen

processargs-specs.js

Source: processargs-specs.js Github

copy

Full Screen

...31 bundleId: desired.desiredCapabilities.bundleId,32 processArguments: PROCESS_ARGS_OBJECT,33 };34 driver.validateDesiredCaps(desiredWithProArgsObejct);35 await driver.startWdaSession(desiredWithProArgsObejct.bundleId, desiredWithProArgsObejct.processArguments);36 proxySpy.calledOnce.should.be.true;37 proxySpy.firstCall.args[0].should.eql('/​session');38 proxySpy.firstCall.args[1].should.eql('POST');39 proxySpy.firstCall.args[2].should.eql(desired);40 });41 });42 describe('send process args json string', () => {43 it('should send translated POST /​session request with valid desired caps to WDA', async () => {44 let desiredWithProArgsString = {45 platformName: 'iOS',46 platformVersion: '9.3',47 deviceName: 'iPhone 6',48 app: "testapp.app",49 bundleId: desired.desiredCapabilities.bundleId,50 processArguments: processArgsString,51 };52 driver.validateDesiredCaps(desiredWithProArgsString);53 await driver.startWdaSession(desiredWithProArgsString.bundleId, desiredWithProArgsString.processArguments);54 proxySpy.calledOnce.should.be.true;55 proxySpy.firstCall.args[0].should.eql('/​session');56 proxySpy.firstCall.args[1].should.eql('POST');57 proxySpy.firstCall.args[2].should.eql(desired);58 });59 });...

Full Screen

Full Screen

driver-specs.js

Source: driver-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import { settings as iosSettings } from 'appium-ios-driver';3import XCUITestDriver from '../​..';4import xcode from 'appium-xcode';5import _ from 'lodash';6import log from '../​../​lib/​logger';7const caps = {platformName: "iOS", deviceName: "iPhone 6", app: "/​foo.app"};8const anoop = async () => {};9describe('driver commands', () => {10 let driver = new XCUITestDriver();11 let proxySpy = sinon.stub(driver, 'proxyCommand');12 afterEach(() => {13 proxySpy.reset();14 });15 describe('status', () => {16 it('should send status request to WDA', async () => {17 await driver.getStatus();18 proxySpy.calledOnce.should.be.true;19 proxySpy.firstCall.args[0].should.eql('/​status');20 proxySpy.firstCall.args[1].should.eql('GET');21 });22 });23 describe('createSession', () => {24 let d;25 let sandbox;26 beforeEach(() => {27 d = new XCUITestDriver();28 sandbox = sinon.sandbox.create();29 sandbox.stub(d, "determineDevice", async () => {30 return {device: null, udid: null, realDevice: null};31 });32 sandbox.stub(d, "configureApp", anoop);33 sandbox.stub(d, "checkAppPresent", anoop);34 sandbox.stub(d, "startLogCapture", anoop);35 sandbox.stub(d, "startSim", anoop);36 sandbox.stub(d, "startWdaSession", anoop);37 sandbox.stub(d, "startWda", anoop);38 sandbox.stub(d, "extractBundleId", anoop);39 sandbox.stub(d, "installApp", anoop);40 sandbox.stub(iosSettings, "setLocale", anoop);41 sandbox.stub(iosSettings, "setPreferences", anoop);42 sandbox.stub(xcode, "getMaxIOSSDK", async () => {43 return '10.0';44 });45 });46 afterEach(() => {47 sandbox.restore();48 });49 it('should include server capabilities', async () => {50 let resCaps = await d.createSession(caps);51 resCaps[1].javascriptEnabled.should.be.true;52 });53 it('should warn', async () => {54 let warnStub = sinon.stub(log, "warn", async () => {});55 await d.createSession(_.defaults({autoAcceptAlerts: true}, caps));56 warnStub.calledTwice.should.be.true;57 _.filter(warnStub.args, (arg) => arg[0].indexOf('autoAcceptAlerts') !== -1)58 .should.have.length(1);59 warnStub.restore();60 });61 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { startWdaSession } = require('appium-xcuitest-driver/​lib/​wda');2const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');3const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');4const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');5const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');6const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');7const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');8const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');9const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');10const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');11const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');12const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');13const { startIOSSession } = require('appium-xcuitest-driver/​lib/​driver');

Full Screen

Using AI Code Generation

copy

Full Screen

1const startWdaSession = require('appium-xcuitest-driver').startWdaSession;2var wda = startWdaSession({3});4wda.on('output', (stdout, stderr) => {5 if (stdout) {6 console.log(stdout);7 }8 if (stderr) {9 console.log(stderr);10 }11});12wda.on('exit', (code, signal) => {13 console.log('WDA process exited with code', code, 'and signal', signal);14});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { startWdaSession } = require('appium-xcuitest-driver/​lib/​wda');3async function startWdaSessionTest() {4 const driver = wd.promiseChainRemote('localhost', 4723);5 try {6 await driver.init({

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Unveiling Samsung Galaxy Z Fold4 For Mobile App Testing

Hey LambdaTesters! We’ve got something special for you this week. ????

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

Fluent Interface Design Pattern in Automation Testing

Recently, I was going through some of the design patterns in Java by reading the book Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, and Kathy Sierra.

What is Selenium Grid & Advantages of Selenium Grid

Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.

How to Position Your Team for Success in Estimation

Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.

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 Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful