Best JavaScript code snippet using appium
Device.test.js
Source:Device.test.js  
1const configurationsMock = require('../configurations.mock');2const path = require('path');3const validScheme = configurationsMock.validOneDeviceAndSession;4const invalidDeviceNoBinary = configurationsMock.invalidDeviceNoBinary;5const invalidDeviceNoDeviceName = configurationsMock.invalidDeviceNoDeviceName;6describe('Device', () => {7  let fs;8  let DeviceDriverBase;9  let SimulatorDriver;10  let Device;11  let device;12  let argparse;13  let sh;14  let Client;15  let client;16  let logger;17  let logError;18  beforeEach(async () => {19    jest.mock('fs');20    jest.mock('../utils/logger');21    fs = require('fs');22    logger = require('../utils/logger');23    Device = require('./Device');24    jest.mock('../utils/sh');25    sh = require('../utils/sh');26    sh.cp = jest.fn();27    jest.mock('../client/Client');28    jest.mock('../utils/argparse');29    argparse = require('../utils/argparse');30    jest.mock('./drivers/DeviceDriverBase');31    DeviceDriverBase = require('./drivers/DeviceDriverBase');32    SimulatorDriver = require('./drivers/SimulatorDriver');33    Client = require('../client/Client');34    client = new Client(validScheme.session);35    await client.connect();36  });37  function schemeDevice(scheme, configuration) {38    const device = new Device({39      deviceConfig: scheme.configurations[configuration],40      deviceDriver: new DeviceDriverBase(client),41      sessionConfig: scheme.session,42    });43    fs.existsSync.mockReturnValue(true);44    device.deviceDriver.defaultLaunchArgsPrefix.mockReturnValue('-');45    device.deviceDriver.acquireFreeDevice.mockReturnValue('mockDeviceId');46    return device;47  }48  function validDevice() {49    return schemeDevice(validScheme, 'ios.sim.release')50  }51  it(`valid scheme, no binary, should throw`, async () => {52    device = validDevice();53    fs.existsSync.mockReturnValue(false);54    try {55      await device.prepare();56      fail('should throw')57    } catch (ex) {58      expect(ex.message).toMatch(/app binary not found at/)59    }60  });61  it(`valid scheme, no binary, should not throw`, async () => {62    device = validDevice();63    await device.prepare();64  });65  it(`prepare() with when reuse is enabled should not uninstall and install`, async () => {66    device = validDevice();67    fs.existsSync.mockReturnValue(true);68    argparse.getArgValue.mockReturnValue(true);69    await device.prepare();70    expect(device.deviceDriver.uninstallApp).not.toHaveBeenCalled();71    expect(device.deviceDriver.installApp).not.toHaveBeenCalled();72  });73  it(`launchApp() should launch app with default launch args`, async () => {74    device = validDevice();75    await device.launchApp();76    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,77      device._bundleId,78      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test"}, undefined);79  });80  it('launchApp({languageAndLocale}) should launch app with a specific language/locale', async () => {81    device = validDevice();82    const languageAndLocale = {83      language: 'es-MX',84      locale: 'es-MX'85    };86    await device.launchApp({languageAndLocale});87    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,88      device._bundleId,89      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test"}, languageAndLocale);90  });91  it(`relaunchApp()`, async () => {92    device = validDevice();93    await device.relaunchApp();94    expect(device.deviceDriver.terminate).toHaveBeenCalled();95    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,96      device._bundleId,97      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test"}, undefined);98  });99  it(`relaunchApp({newInstance: false}) should not terminate the app before launch`, async () => {100    device = validDevice();101    await device.relaunchApp({newInstance: false});102    expect(device.deviceDriver.terminate).not.toHaveBeenCalled();103  });104  it(`relaunchApp({newInstance: true}) should terminate the app before launch`, async () => {105    device = validDevice();106    await device.relaunchApp({newInstance: true});107    expect(device.deviceDriver.terminate).toHaveBeenCalled();108  });109  it(`relaunchApp() (no params) should terminate the app before launch - backwards compat`, async () => {110    device = validDevice();111    await device.relaunchApp();112    expect(device.deviceDriver.terminate).toHaveBeenCalled();113  });114  it(`relaunchApp() with delete=true`, async () => {115    device = validDevice();116    fs.existsSync.mockReturnValue(true);117    await device.relaunchApp({delete: true});118    expect(device.deviceDriver.uninstallApp).toHaveBeenCalled();119    expect(device.deviceDriver.installApp).toHaveBeenCalled();120    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,121      device._bundleId,122      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test"}, undefined);123  });124  it(`relaunchApp() without delete when reuse is enabled should not uninstall and install`, async () => {125    device = validDevice();126    argparse.getArgValue.mockReturnValue(true);127    fs.existsSync.mockReturnValue(true);128    await device.relaunchApp();129    expect(device.deviceDriver.uninstallApp).not.toHaveBeenCalled();130    expect(device.deviceDriver.installApp).not.toHaveBeenCalled();131    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,132      device._bundleId,133      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test"}, undefined);134  });135  it(`relaunchApp() with url should send the url as a param in launchParams`, async () => {136    device = await validDevice();137    await device.relaunchApp({url: `scheme://some.url`});138    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,139      device._bundleId,140      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test", "-detoxURLOverride": "scheme://some.url"}, undefined);141  });142  it(`relaunchApp() with url should send the url as a param in launchParams`, async () => {143    device = await validDevice();144    await device.relaunchApp({url: `scheme://some.url`, sourceApp: 'sourceAppBundleId'});145    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,146      device._bundleId,147      {148        "-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test", "-detoxURLOverride": "scheme://some.url", "-detoxSourceAppOverride":149        "sourceAppBundleId"150      }, undefined);151  });152  it(`launchApp() with disableTouchIndicators should send a boolean switch as a param in launchParams`, async () => {153    device = await validDevice();154    await device.launchApp({disableTouchIndicators: true});155    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,156      device._bundleId,157      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test", "-detoxDisableTouchIndicators": true}, undefined);158  });159  it(`relaunchApp() with userNofitication should send the userNotification as a param in launchParams`, async () => {160    device = validDevice();161    fs.existsSync.mockReturnValue(true);162    device.deviceDriver.createPayloadFile = jest.fn(() => 'url');163    await device.relaunchApp({userNotification: 'json'});164    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,165      device._bundleId,166      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test", "-detoxUserNotificationDataURL": "url"}, undefined);167  });168  it(`relaunchApp() with url and userNofitication should throw`, async () => {169    device = validDevice();170    try {171      await device.relaunchApp({url: "scheme://some.url", userNotification: 'notif'});172      fail('should fail');173    } catch (ex) {174      expect(ex).toBeDefined();175    }176  });177  it(`relaunchApp() with permissions should send trigger setpermissions before app starts`, async () => {178    device = await validDevice();179    await device.relaunchApp({permissions: {calendar: "YES"}});180    expect(device.deviceDriver.setPermissions).toHaveBeenCalledWith(device._deviceId,181      device._bundleId, {calendar: "YES"});182  });183  it(`launchApp({launchArgs: }) should pass to native as launch args`, async () => {184    device = validDevice();185    await device.launchApp({launchArgs: {arg1: "1", arg2: 2}});186    expect(device.deviceDriver.launchApp).toHaveBeenCalledWith(device._deviceId,187      device._bundleId,188      {"-detoxServer": "ws://localhost:8099", "-detoxSessionId": "test", "-arg1": "1", "-arg2": 2}, undefined);189  });190  it(`sendToHome() should pass to device driver`, async () => {191    device = validDevice();192    await device.sendToHome();193    expect(device.deviceDriver.sendToHome).toHaveBeenCalledTimes(1);194  });195  it(`shake() should pass to device driver`, async () => {196    device = validDevice();197    await device.shake();198    expect(device.deviceDriver.shake).toHaveBeenCalledTimes(1);199  });200  it(`terminateApp() should pass to device driver`, async () => {201    device = validDevice();202    await device.terminateApp();203    expect(device.deviceDriver.terminate).toHaveBeenCalledTimes(1);204  });205  it(`installApp() with a custom app path should use custom app path`, async () => {206    device = validDevice();207    fs.existsSync.mockReturnValue(true);208    await device.installApp('newAppPath');209    expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', undefined);210  });211  it(`installApp() with a custom test app path should use custom test app path`, async () => {212    device = validDevice();213    fs.existsSync.mockReturnValue(true);214    await device.installApp('newAppPath', 'newTestAppPath');215    expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', 'newTestAppPath');216  });217  it(`installApp() with no params should use the default path given in configuration`, async () => {218    device = validDevice();219    await device.installApp();220    expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath, device._testBinaryPath);221  });222  it(`uninstallApp() with a custom app path should use custom app path`, async () => {223    device = validDevice();224    fs.existsSync.mockReturnValue(true);225    await device.uninstallApp('newBundleId');226    expect(device.deviceDriver.uninstallApp).toHaveBeenCalledWith(device._deviceId, 'newBundleId');227  });228  it(`uninstallApp() with no params should use the default path given in configuration`, async () => {229    device = validDevice();230    await device.uninstallApp();231    expect(device.deviceDriver.uninstallApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath);232  });233  it(`shutdown() should pass to device driver`, async () => {234    device = validDevice();235    await device.shutdown();236    expect(device.deviceDriver.shutdown).toHaveBeenCalledTimes(1);237  });238  it(`openURL({url:url}) should pass to device driver`, async () => {239    device = validDevice();240    await device.openURL({url: 'url'});241    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledWith({url: 'url'});242  });243  it(`openURL(notAnObject) should pass to device driver`, async () => {244    device = validDevice();245    try {246      await device.openURL('url');247      fail('should throw');248    } catch (ex) {249      expect(ex).toBeDefined();250    }251  });252  it(`reloadReactNative() should pass to device driver`, async () => {253    device = validDevice();254    await device.reloadReactNative();255    expect(device.deviceDriver.reloadReactNative).toHaveBeenCalledTimes(1);256  });257  it(`setOrientation() should pass to device driver`, async () => {258    device = validDevice();259    await device.setOrientation('param');260    expect(device.deviceDriver.setOrientation).toHaveBeenCalledWith(device._deviceId, 'param');261  });262  it(`sendUserNotification() should pass to device driver`, async () => {263    device = validDevice();264    await device.sendUserNotification('notif');265    expect(device.deviceDriver.createPayloadFile).toHaveBeenCalledTimes(1);266    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledTimes(1);267  });268  it(`sendUserActivity() should pass to device driver`, async () => {269    device = validDevice();270    await device.sendUserActivity('notif');271    expect(device.deviceDriver.createPayloadFile).toHaveBeenCalledTimes(1);272    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledTimes(1);273  });274  it(`setLocation() should pass to device driver`, async () => {275    device = validDevice();276    await device.setLocation(30.1, 30.2);277    expect(device.deviceDriver.setLocation).toHaveBeenCalledWith(device._deviceId, '30.1', '30.2');278  });279  it(`setURLBlacklist() should pass to device driver`, async () => {280    device = validDevice();281    await device.setURLBlacklist();282    expect(device.deviceDriver.setURLBlacklist).toHaveBeenCalledTimes(1);283  });284  it(`enableSynchronization() should pass to device driver`, async () => {285    device = validDevice();286    await device.enableSynchronization();287    expect(device.deviceDriver.enableSynchronization).toHaveBeenCalledTimes(1);288  });289  it(`disableSynchronization() should pass to device driver`, async () => {290    device = validDevice();291    await device.disableSynchronization();292    expect(device.deviceDriver.disableSynchronization).toHaveBeenCalledTimes(1);293  });294  it(`resetContentAndSettings() should pass to device driver`, async () => {295    device = validDevice();296    await device.resetContentAndSettings();297    expect(device.deviceDriver.resetContentAndSettings).toHaveBeenCalledTimes(1);298  });299  it(`getPlatform() should pass to device driver`, async () => {300    device = validDevice();301    device.getPlatform();302    expect(device.deviceDriver.getPlatform).toHaveBeenCalledTimes(1);303  });304  it(`_cleanup() should pass to device driver`, async () => {305    device = validDevice();306    await device._cleanup();307    expect(device.deviceDriver.cleanup).toHaveBeenCalledTimes(1);308  });309  it(`new Device() with invalid device config (no binary) should throw`, () => {310    expect(() => new Device({311      deviceConfig: invalidDeviceNoBinary.configurations['ios.sim.release'],312      deviceDriver: new SimulatorDriver(client),313      sessionConfig: validScheme.session,314    })).toThrowErrorMatchingSnapshot();315  });316  it(`new Device() with invalid device config (no device name) should throw`, () => {317    expect(() => new Device({318      deviceConfig: invalidDeviceNoDeviceName.configurations['ios.sim.release'],319      deviceDriver: new SimulatorDriver(client),320      sessionConfig: validScheme.session,321    })).toThrowErrorMatchingSnapshot();322  });323  it(`launchApp({newInstance: false}) should check if process is in background and reopen it`, async () => {324    const processId = 1;325    device = validDevice();326    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');327    device.deviceDriver.launchApp.mockReturnValue(processId);328    await device.prepare({launchApp: true});329    await device.launchApp({newInstance: false});330    expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();331  });332  it(`launchApp({url: url}) should check if process is in background and use openURL() instead of launch args`, async () => {333    const processId = 1;334    device = validDevice();335    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');336    device.deviceDriver.launchApp.mockReturnValue(processId);337    await device.prepare({launchApp: true});338    await device.launchApp({url: 'url://me'});339    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledTimes(1);340  });341  it(`launchApp({url: url}) should check if process is in background and if not use launch args`, async () => {342    const launchParams = {url: 'url://me'};343    const processId = 1;344    const newProcessId = 2;345    device = validDevice();346    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');347    device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);348    await device.prepare();349    await device.launchApp(launchParams);350    expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();351  });352  it(`launchApp({url: url}) should check if process is in background and use openURL() instead of launch args`, async () => {353    const launchParams = {url: 'url://me'};354    const processId = 1;355    device = validDevice();356    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');357    device.deviceDriver.launchApp.mockReturnValue(processId);358    await device.prepare({launchApp: true});359    await device.launchApp(launchParams);360    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, url: 'url://me'});361  });362  it('launchApp({userActivity: userActivity}) should check if process is in background and if it is use deliverPayload', async () => {363    const launchParams = {userActivity: 'userActivity'};364    const processId = 1;365    device = validDevice();366    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');367    device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);368    device.deviceDriver.createPayloadFile = () => 'url';369    await device.prepare({launchApp: true});370    await device.launchApp(launchParams);371    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, detoxUserActivityDataURL: 'url'});372  });373  it('launchApp({userNotification: userNotification}) should check if process is in background and if it is use deliverPayload', async () => {374    const launchParams = {userNotification: 'notification'};375    const processId = 1;376    device = validDevice();377    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');378    device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);379    device.deviceDriver.createPayloadFile = () => 'url';380    await device.prepare({launchApp: true});381    await device.launchApp(launchParams);382    expect(device.deviceDriver.deliverPayload).toHaveBeenCalledTimes(1);383  });384  it(`launchApp({userNotification: userNotification}) should check if process is in background and if not use launch args`, async () => {385    const launchParams = {userNotification: 'notification'};386    const processId = 1;387    const newProcessId = 2;388    device = validDevice();389    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');390    device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);391    await device.prepare();392    await device.launchApp(launchParams);393    expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();394  });395  it(`launchApp({userNotification: userNotification, url: url}) should fail`, async () => {396    const launchParams = {userNotification: 'notification', url: 'url://me'};397    const processId = 1;398    device = validDevice();399    device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');400    device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);401    await device.prepare();402    try {403      await device.launchApp(launchParams);404      fail('should throw');405    } catch (ex) {406      expect(ex).toBeDefined();407    }408    expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();409  });410  async function launchAndTestBinaryPath(configuration) {411    const device = schemeDevice(configurationsMock.pathsTests, configuration);412    await device.prepare();413    await device.launchApp();414    return device.deviceDriver.installApp.mock.calls[0][1];415  }416  it(`should accept absolute path for binary`, async () => {417    const actualPath = await launchAndTestBinaryPath('absolutePath');418    expect(actualPath).toEqual(process.platform === 'win32' ? 'C:\\Temp\\abcdef\\123' : '/tmp/abcdef/123');419  });420  it(`should accept relative path for binary`, async () => {421    const actualPath = await launchAndTestBinaryPath('relativePath');422    expect(actualPath).toEqual(path.join(process.cwd(), 'abcdef/123'));423  });424  it(`pressBack() should be called`, async () => {425    device = validDevice();426    await device.pressBack();427    expect(device.deviceDriver.pressBack).toHaveBeenCalledWith(device._deviceId);428  });...context-e2e-specs.js
Source:context-e2e-specs.js  
...39      await driver.context(contexts[1]);40    });41    it('should be able to go into native context and interact with it after restarting app', async function () {42      await driver.closeApp();43      await driver.launchApp();44      await driver.context(NATIVE);45      await driver.elementByXPath(NATIVE_LOCATOR);46    });47    it('should be able to go into native context and interact with it after resetting app', async function () {48      await driver.resetApp();49      await driver.context(NATIVE);50      await driver.elementByXPath(NATIVE_LOCATOR);51    });52    it('should be able to go into webview context and interact with it after restarting app', async function () {53      // TODO: Fix this on TestObject. Chromedriver does not exist error54      if (process.env.TESTOBJECT_E2E_TESTS) {55        this.skip();56      }57      await driver.closeApp();58      await driver.launchApp();59      await driver.context(WEBVIEW);60      await driver.elementByXPath(WEBVIEW_LOCATOR);61    });62    it('should be able to go into webview context and interact with it after resetting app', async function () {63      // TODO: Fix this on TestObject. Chromedriver does not exist error64      if (process.env.TESTOBJECT_E2E_TESTS) {65        this.skip();66      }67      await driver.resetApp();68      await driver.context(WEBVIEW);69      await driver.elementByXPath(WEBVIEW_LOCATOR);70    });71  });72  describe('autoWebview', function () {...actionHelpers.js
Source:actionHelpers.js  
...11    static  removeApp(){12        driver.removeApp('com.stubhub.stubhub');13    }14    static launchApp() {15        driver.launchApp();16    }17    static switchToNativeContext() {18        browser.switchContext('NATIVE_APP');19    }20    static pause(seconds) {21        browser.pause(seconds * 1000);22    }23    static isVisible(locator) {24        return !!$(locator).isDisplayed();25    }26    static click(locator) {27        $(locator).click();28    }29    static waitForElement(locator, waitTimeInSeconds) {...reset-specs.js
Source:reset-specs.js  
...19    it('should successfully close an app', async function () {20      rawDriver.ready.should.be.ok;21      await driver.closeApp();22      rawDriver.ready.should.not.be.ok;23      await driver.launchApp();24      rawDriver.ready.should.be.ok;25      let els = await driver.findElements('class name', 'UIATableView');26      els.should.have.length(1);27    });28  });...appium.basics.js
Source:appium.basics.js  
...8    isChecked( element ) { return element.getAttribute('checked')}, //if checked returns true9    hideKeyboard() { return driver.hideKeyboard()},10    isKeyboardShown() { return driver.isKeyboardShown()},11    toggleAirplaneMode() { return driver.toggleAirplaneMode()},12    launchApp() { return driver.launchApp()},13    closeApp() { return driver.closeApp()},...run.appium.js
Source:run.appium.js  
...12  await driver.sleep(5000);13  await driver.quit();14});15afterEach(async () => {16  await driver.launchApp();17});18describe("Guest context", () => {19  SignIn(driver);...reset-app-between-scenarios.js
Source:reset-app-between-scenarios.js  
1const { Before, After } = require('@cucumber/cucumber');2Before(async () => {3  console.log('Launch the app');4  await driver.launchApp();5});6After(async () => {7  console.log('Close the app');8  await driver.closeApp();...base.page.js
Source:base.page.js  
1module.exports = class Page {2    static launchApp() {3     driver.launchApp();4 }...Using AI Code Generation
1driver.launchApp();2driver.closeApp();3driver.resetApp();4driver.isAppInstalled("com.android.calculator2");5driver.installApp("/Users/Downloads/calculator.apk");6driver.removeApp("com.android.calculator2");7driver.activateApp("com.android.calculator2");8driver.startActivity("com.android.calculator2", ".Calculator");9driver.backgroundApp(5);10driver.currentActivity();11driver.currentPackage();12driver.getDeviceTime();13driver.getSettings();14driver.updateSettings({ignoreUnimportantViews: true});15driver.getOrientation();16driver.setOrientation("LANDSCAPE");17driver.getGeoLocation();18driver.setGeoLocation({latitude: 40.714353, longitude: -74.005973, altitude: 1});19driver.hideKeyboard();20driver.isKeyboardShown();21driver.pressKeyCode(4);22driver.longPressKeyCode(4);23driver.pullFile("data/local/tmp/sample.txt");24driver.pullFolder("data/local/tmp");25driver.pushFile("data/local/tmp/sample.txt", "Hello World!");Using AI Code Generation
1var wd = require("wd");2var driver = wd.promiseChainRemote("localhost", 4723);3driver.init({4}).then(function() {5  return driver.elementById("com.example.test:id/button1");6}).then(function(el) {7  return el.click();8}).then(function() {9  return driver.quit();10}).done();11var wd = require("wd");12var driver = wd.promiseChainRemote("localhost", 4723);13driver.init({14}).then(function() {15  return driver.elementById("com.example.test:id/button1");16}).then(function(el) {17  return el.click();18}).then(function() {19  return driver.quit();20}).done();21var wd = require("wd");22var driver = wd.promiseChainRemote("localhost", 4723);23driver.init({24}).then(function() {25  return driver.elementById("com.example.test:id/button1");26}).then(function(el) {27  return el.click();28}).then(function() {29  return driver.quit();30}).done();31var wd = require("wd");32var driver = wd.promiseChainRemote("localhost", 4723);33driver.init({Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5    .init(desiredCaps)6    .then(function() {7        return driver.elementById("com.example.myapp:id/myButton");8    })9    .then(function(button) {10        return button.click();11    })12    .then(function() {13        return driver.elementById("com.example.myapp:id/myTextField");14    })15    .then(function(textField) {16        return textField.text();17    })18    .then(function(text) {19        assert.ok(text === "I was pressed!");20    })21    .fin(function() { return driver.quit(); })22    .done();23var wd = require('wd');24var assert = require('assert');25var desiredCaps = {26};27    .init(desiredCaps)28    .then(function() {29        return driver.startActivity({30        });31    })32    .then(function() {33        return driver.elementById("com.example.myapp:id/myButton");34    })35    .then(function(button) {36        return button.click();37    })38    .then(function() {39        return driver.elementById("com.example.myapp:id/myTextField");40    })41    .then(function(textField) {42        return textField.text();43    })44    .then(function(text) {45        assert.ok(text === "I was pressed!");46    })47    .fin(function() { return driver.quit(); })48    .done();49var wd = require('wd');50var assert = require('assert');51var desiredCaps = {52};Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var driver = wd.promiseChainRemote("localhost", 4723);4var desired = {5};6driver.init(desired)7  .then(function() {8    return driver.launchApp();9  })10  .then(function() {11  })12  .fin(function() { return driver.quit(); })13  .done();14var wd = require('wd');15var assert = require('assert');16var driver = wd.promiseChainRemote("localhost", 4723);17var desired = {18};19driver.init(desired)20  .then(function() {21    return driver.closeApp();22  })23  .then(function() {24  })25  .fin(function() { return driver.quit(); })26  .done();27var wd = require('wd');28var assert = require('assert');29var driver = wd.promiseChainRemote("localhost", 4723);30var desired = {31};32driver.init(desired)33  .then(function() {34    return driver.resetApp();35  })36  .then(function() {37  })38  .fin(function() { return driver.quit(); })39  .done();40var wd = require('wd');41var assert = require('assert');42var driver = wd.promiseChainRemote("localhost", 4723);43var desired = {44};45driver.init(desired)46  .then(function() {47    return driver.isAppInstalled("com.example.android.myapp");48  })Using AI Code Generation
1var wd = require('wd');2var assert = require("assert");3var desiredCaps = {4};5var driver = wd.promiseChainRemote("ondemand.saucelabs.com", 80, "username", "password");6driver.init(desiredCaps).then(function() {7    return driver.launchApp();8}).then(function() {9    return driver.sleep(5000);10}).then(function() {11    return driver.closeApp();12}).then(function() {13    return driver.quit();14}).done();15var wd = require('wd');16var assert = require("assert");17var desiredCaps = {18};19var driver = wd.promiseChainRemote("ondemand.saucelabs.com", 80, "username", "password");20driver.init(desiredCaps).then(function() {21    return driver.launchApp();22}).then(function() {23    return driver.sleep(5000);24}).then(function() {25    return driver.closeApp();26}).then(function() {27    return driver.quit();28}).done();29var wd = require('wd');30var assert = require("assert");31var desiredCaps = {Using AI Code Generation
1var wd = require('wd');2var chai = require('chai');3var should = chai.should();4var assert = chai.assert;5var expect = chai.expect;6var driver = wd.promiseChainRemote("localhost",4723);7var desiredCaps = {8};9driver.init(desiredCaps);10driver.sleep(3000);11driver.quit();12info: Welcome to Appium v1.4.13 (REV 7c0d9a9e7e9f8e2f1a2c6b0c6f5a6d5a1c2d1e9a)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!!
