Best JavaScript code snippet using appium-xcuitest-driver
js-wdio.js
Source:js-wdio.js
...183 codeFor_touchId (varNameIgnore, varIndexIgnore, match) {184 return `await driver.touchId(${match});`;185 }186 codeFor_toggleEnrollTouchId (varNameIgnore, varIndexIgnore, enroll) {187 return `await driver.toggleEnrollTouchId(${enroll});`;188 }189 codeFor_openNotifications () {190 return `await driver.openNotifications();`;191 }192 codeFor_getDeviceTime () {193 return `let time = await driver.getDeviceTime();`;194 }195 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {196 return `await driver.fingerprint(${fingerprintId});`;197 }198 codeFor_getSession () {199 return `let caps = await driver.session('c8db88a0-47a6-47a1-802d-164d746c06aa');`;200 }201 codeFor_setTimeouts (/*varNameIgnore, varIndexIgnore, timeoutsJson*/) {...
js-wd.js
Source:js-wd.js
...175 codeFor_touchId (varNameIgnore, varIndexIgnore, match) {176 return `await driver.touchId(${match});`;177 }178 codeFor_toggleEnrollTouchId (varNameIgnore, varIndexIgnore, enroll) {179 return `await driver.toggleEnrollTouchId(${enroll});`;180 }181 codeFor_openNotifications () {182 return `await driver.openNotifications();`;183 }184 codeFor_getDeviceTime () {185 return `let time = await driver.getDeviceTime();`;186 }187 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {188 return `await driver.fingerprint(${fingerprintId});`;189 }190 codeFor_getSession () {191 return `let caps = await driver.getSession();`;192 }193 codeFor_setTimeouts (/*varNameIgnore, varIndexIgnore, timeoutsJson*/) {...
js-oxygen.js
Source:js-oxygen.js
1import Framework from './framework';2class JsOxygenFramework extends Framework {3 get language () {4 return 'js';5 }6 wrapWithBoilerplate (code) {7 let caps = JSON.stringify(this.caps);8 let url = JSON.stringify(`${this.scheme}://${this.host}:${this.port}${this.path}`);9 return `// Requires the Oxygen HQ client library10// (npm install oxygen-cli -g)11// Then paste this into a .js file and run with:12// oxygen <file>.js13mob.init(${caps}, ${url});14${code}15`;16 }17 codeFor_findAndAssign (strategy, locator, localVar, isArray) {18 // wdio has its own way of indicating the strategy in the locator string19 switch (strategy) {20 case 'xpath': break; // xpath does not need to be updated21 case 'accessibility id': locator = `~${locator}`; break;22 case 'id': locator = `id=${locator}`; break;23 case 'name': locator = `name=${locator}`; break;24 case 'class name': locator = `css=${locator}`; break;25 case '-android uiautomator': locator = `android=${locator}`; break;26 case '-android datamatcher': locator = `android=${locator}`; break;27 case '-ios predicate string': locator = `ios=${locator}`; break;28 case '-ios class chain': locator = `ios=${locator}`; break; // TODO: Handle IOS class chain properly. Not all libs support it. Or take it out29 default: throw new Error(`Can't handle strategy ${strategy}`);30 }31 if (isArray) {32 return `let ${localVar} = mob.findElements(${JSON.stringify(locator)});`;33 } else {34 return `let ${localVar} = mob.findElement(${JSON.stringify(locator)});`;35 }36 }37 codeFor_click (varName, varIndex) {38 return `mob.click(${this.getVarName(varName, varIndex)});`;39 }40 codeFor_clear (varName, varIndex) {41 return `mob.clear(${this.getVarName(varName, varIndex)});`;42 }43 codeFor_sendKeys (varName, varIndex, text) {44 return `mob.type(${this.getVarName(varName, varIndex)}, ${JSON.stringify(text)});`;45 }46 codeFor_back () {47 return `mob.back();`;48 }49 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {50 return `mob.tap(${x}, ${y});`;51 }52 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {53 return `mob.swipeScreen(${x1}, ${y1}, ${x2}, ${y2});`;54 }55 codeFor_getCurrentActivity () {56 return `let activityName = mob.getCurrentActivity();`;57 }58 codeFor_getCurrentPackage () {59 return `let packageName = mob.getCurrentPackage();`;60 }61 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {62 return `mob.installApp('${app}');`;63 }64 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {65 return `let isAppInstalled = mob.isAppInstalled("${app}");`;66 }67 codeFor_launchApp () {68 return `mob.launchApp();`;69 }70 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {71 return `mob.driver().background(${timeout});`;72 }73 codeFor_closeApp () {74 return `mob.closeApp();`;75 }76 codeFor_resetApp () {77 return `mob.resetApp();`;78 }79 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {80 return `mob.removeApp('${app}')`;81 }82 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {83 return `let appStrings = mob.driver().getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;84 }85 codeFor_getClipboard () {86 return `let clipboardText = mob.driver().getClipboard();`;87 }88 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {89 return `mob.driver().setClipboard('${clipboardText}')`;90 }91 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {92 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;93 }94 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {95 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;96 }97 codeFor_hideDeviceKeyboard () {98 return `mob.driver().hideKeyboard();`;99 }100 codeFor_isKeyboardShown () {101 return `//isKeyboardShown not supported`;102 }103 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {104 return `mob.driver().pushFile('${pathToInstallTo}', '${fileContentString}');`;105 }106 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {107 return `let data = mob.driver().pullFile('${pathToPullFrom}');`;108 }109 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {110 return `let data = mob.driver().pullFolder('${folderToPullFrom}');`;111 }112 codeFor_toggleAirplaneMode () {113 return `mob.driver().toggleAirplaneMode();`;114 }115 codeFor_toggleData () {116 return `mob.driver().toggleData();`;117 }118 codeFor_toggleWiFi () {119 return `mob.driver().toggleWiFi();`;120 }121 codeFor_toggleLocationServices () {122 return `mob.driver().toggleLocationServices();`;123 }124 codeFor_sendSMS () {125 return `// Not supported: sendSms;`;126 }127 codeFor_gsmCall () {128 return `// Not supported: gsmCall`;129 }130 codeFor_gsmSignal () {131 return `// Not supported: gsmSignal`;132 }133 codeFor_gsmVoice () {134 return `// Not supported: gsmVoice`;135 }136 codeFor_shake () {137 return `mob.shake();`;138 }139 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {140 return `mob.driver().lock(${seconds});`;141 }142 codeFor_unlock () {143 return `mob.driver().unlock();`;144 }145 codeFor_isLocked () {146 return `let isLocked = mob.driver().isLocked();`;147 }148 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {149 return `mob.driver().rotateDevice(${x}, ${y}, ${radius}, ${rotation}, ${touchCount}, ${duration});`;150 }151 codeFor_getPerformanceData () {152 return `// Not supported: getPerformanceData`;153 }154 codeFor_getSupportedPerformanceDataTypes () {155 return `// Not supported: getSupportedPerformanceDataTypes`;156 }157 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {158 return `mob.driver().touchId(${match});`;159 }160 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {161 return `mob.driver().toggleEnrollTouchId(${enroll});`;162 }163 codeFor_openNotifications () {164 return `mob.driver().openNotifications();`;165 }166 codeFor_getDeviceTime () {167 return `let time = mob.getDeviceTime();`;168 }169 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {170 return `mob.driver().fingerPrint(${fingerprintId});`;171 }172 codeFor_sessionCapabilities () {173 return `let caps = mob.driver().capabilities;`;174 }175 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {176 return `mob.driver().setTimeout({'pageLoad': ${ms}});`;177 }178 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {179 return `mob.driver().setTimeout({'script': ${ms}});`;180 }181 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {182 return `mob.driver().setTimeout({'implicit': ${ms}});`;183 }184 codeFor_setCommandTimeout () {185 return `// Not supported: setCommandTimeout`;186 }187 codeFor_getOrientation () {188 return `let orientation = mob.driver().getOrientation();`;189 }190 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {191 return `mob.driver().setOrientation("${orientation}");`;192 }193 codeFor_getGeoLocation () {194 return `let location = mob.driver().getGeoLocation();`;195 }196 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {197 return `mob.driver().setGeoLocation({latitude: ${latitude}, longitude: ${longitude}, altitude: ${altitude}});`;198 }199 codeFor_logTypes () {200 return `let logTypes = mob.driver().getLogTypes();`;201 }202 codeFor_log (varNameIgnore, varIndexIgnore, logType) {203 return `let logs = mob.driver().getLogs('${logType}');`;204 }205 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {206 return `mob.driver().updateSettings(${settingsJson});`;207 }208 codeFor_settings () {209 return `let settings = mob.driver().getSettings();`;210 }211}212JsOxygenFramework.readableName = 'JS - Oxygen HQ';...
general-specs.js
Source:general-specs.js
...65 enrollTouchIDSpy.restore();66 });67 it('should throw exception if allowTouchIdEnroll is not set', async () => {68 optsStub.object.realDevice = false;69 await driver.toggleEnrollTouchId().should.be.rejectedWith(/enroll touchId/);70 });71 it('should be called on a Simulator', async () => {72 deviceStub.object.realDevice = false;73 deviceStub.object.allowTouchIdEnroll = true;74 await driver.toggleEnrollTouchId();75 enrollTouchIDSpy.calledOnce.should.be.true;76 });77 it('should not be called on a real device', async () => {78 deviceStub.object.realDevice = true;79 deviceStub.object.allowTouchIdEnroll = true;80 await driver.toggleEnrollTouchId().should.eventually.be.rejectedWith(/not supported/g);81 enrollTouchIDSpy.notCalled.should.be.true;82 });83 });...
touch.face.id.spec.js
Source:touch.face.id.spec.js
...7 LoginScreen.waitForIsShown();8 // If the biometry is not shown on iOS, enable it on the phone9 if (driver.isIOS && !LoginScreen.biometryButton.isDisplayed()) {10 // iOS us pretty straightforward, just enabled it11 driver.toggleEnrollTouchId(true);12 // restart the app13 restartApp();14 } else if (driver.isAndroid && !LoginScreen.biometryButton.isDisplayed()) {15 // Android is more complex, see this method16 AndroidSettings.enableBiometricLogin();17 }18 // Wait for the button to be shown19 LoginScreen.biometryButton.waitForDisplayed();20 });21 it('Should be able to login with a matching touch / face ID', () => {22 LoginScreen.biometryButton.click();23 LoginScreen.submitBiometricLogin(true);24 expect($('~test-PRODUCTS').waitForDisplayed()).toEqual(true, 'Inventory List screen was not shown');25 });...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var caps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(caps)7 .then(function() {8 return driver.toggleEnrollTouchId(true);9 })10 .then(function() {11 return driver.toggleEnrollTouchId(false);12 })13 .then(function() {14 return driver.quit();15 })16 .catch(function(err) {17 console.error('Error: ' + err);18 });19driver.touchId()20driver.toggleEnrollTouchId()21driver.setGeoLocation()22driver.getGeoLocation()23driver.setNetworkConnection()24driver.getNetworkConnection()25driver.mobileSetPasteboard()26driver.mobileGetPasteboard()27driver.mobileSimulateTouch()28driver.mobileSimulatePressure()29driver.mobileStartPerfRecord()30driver.mobileStopPerfRecord()31driver.mobilePerfGetTimingData()32driver.mobileStartRecordingScreen()33driver.mobileStopRecordingScreen()34driver.mobileShake()35driver.mobileGetAppState()36driver.mobileGetDeviceTime()37driver.mobileGetScreenshot()38driver.mobileGetPermissions()39driver.mobileSetPermissions()40driver.mobileReset()41driver.mobileSendSMS()42driver.mobileQueryAppState()43driver.mobilePerformEditorAction()44driver.mobileGetContext()45driver.mobileSetContext()46driver.mobileGetOrientation()47driver.mobileSetOrientation()48driver.mobileGetGeoLocation()49driver.mobileSetGeoLocation()50driver.mobileGetBatteryInfo()51driver.mobileGetPerformanceData()52driver.mobileGetPerformanceDataTypes()53driver.mobileGetDeviceInfo()54driver.mobileGetDisplayDensity()55driver.mobileGetDisplaySize()56driver.mobileGetClipboard()57driver.mobileSetClipboard()58driver.mobileClearClipboard()59driver.mobileFingerPrint()60driver.mobileGetAppStrings()61driver.mobileGetAppString()62driver.mobileSetURLBlacklist()63driver.mobileGetURLBlacklist()64driver.mobileSetURLWhitelist()65driver.mobileGetURLWhitelist()66driver.mobileDeleteFile()67driver.mobileDeleteDirectory()68driver.mobileListFiles()69driver.mobileListDirectories()70driver.mobileGetAppState()71driver.mobileGetDeviceTime()72driver.mobileGetScreenshot()73driver.mobileGetPermissions()74driver.mobileSetPermissions()75driver.mobileReset()
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var capabilities = {3};4 build();5driver.findElement(webdriver.By.name('q')).sendKeys('BrowserStack');6driver.findElement(webdriver.By.name('btnG')).click();7driver.getTitle().then(function(title) {8 console.log(title);9 driver.quit();10});11driver.toggleEnrollTouchId(function(err, res) {12 console.log(res);13});14driver.findElement(webdriver.By.name('q')).sendKeys('BrowserStack');15driver.findElement(webdriver.By.name('btnG')).click();16driver.getTitle().then(function(title) {17 console.log(title);18 driver.quit();19});20driver.toggleEnrollTouchId(function(err, res) {21 console.log(res);22});23driver.findElement(webdriver.By.name('q')).sendKeys('BrowserStack');24driver.findElement(webdriver.By.name('btnG')).click();25driver.getTitle().then(function(title) {26 console.log(title);27 driver.quit();28});29driver.toggleEnrollTouchId(function(err, res) {30 console.log(res);31});
Using AI Code Generation
1driver.toggleEnrollTouchId(true, function(err, res) {2 console.log(res);3});4driver.toggleEnrollTouchId(false, function(err, res) {5 console.log(res);6});7driver.toggleEnrollTouchId(true, function(err, res) {8 console.log(res);9});10driver.toggleEnrollTouchId(false, function(err, res) {11 console.log(res);12});13driver.toggleEnrollTouchId(true, function(err, res) {14 console.log(res);15});16driver.toggleEnrollTouchId(false, function(err, res) {17 console.log(res);18});19driver.toggleEnrollTouchId(true, function(err, res) {20 console.log(res);21});22driver.toggleEnrollTouchId(false, function(err, res) {23 console.log(res);24});25driver.toggleEnrollTouchId(true, function(err, res) {26 console.log(res);27});28driver.toggleEnrollTouchId(false, function(err, res) {29 console.log(res);30});31driver.toggleEnrollTouchId(true, function(err, res) {32 console.log(res);33});34driver.toggleEnrollTouchId(false, function(err, res) {35 console.log(res);36});
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const assert = chai.assert;7const should = chai.should;8const {exec} = require('child_process');9const desiredCaps = {10};11const driver = wd.promiseChainRemote('localhost', 4723);12driver.on('status', info => console.log(info));13driver.on('command', (meth, path, data) => console.log(' > ' + meth, path, data || ''));14driver.on('http', (meth, path, data) => console.log(' > ' + meth, path, data || ''));15 .init(desiredCaps)16 .setImplicitWaitTimeout(6000)17 .then(() => {18 return driver.toggleEnrollTouchId(true);19 })20 .then(() => {21 return driver.toggleEnrollTouchId(false);22 })23 .catch((err) => {24 console.log(err);25 });26driver.toggleEnrollTouchId(true)27driver.toggleEnrollTouchId(false)28driver.isTouchIdEnrolled()29driver.isTouchIdEnrolled().should.eventually.be.false30driver.isTouchIdEnrolled().should.eventually.be.true31driver.isTouchIdEnrolled().should.eventually.be.false32driver.isTouchIdEnrolled().should.eventually.be.true
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6const assert = chai.assert;7const desiredCaps = {8};9const driver = wd.promiseChainRemote('localhost', 4723);10driver.init(desiredCaps)11 .then(() => {12 return driver.toggleEnrollTouchId(true);13 })14 .then(() => {15 return driver.toggleEnrollTouchId(false);16 })17 .catch((err) => {18 console.log(err);19 });
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!!