Best JavaScript code snippet using appium-xcuitest-driver
location.js
Source:location.js
...46 if (this.isSimulator()) {47 await this.opts.device.setGeolocation(`${latitude}`, `${longitude}`);48 return;49 }50 const service = await services.startSimulateLocationService(this.opts.udid);51 try {52 service.setLocation(latitude, longitude);53 } catch (e) {54 this.log.errorAndThrow(`Can't set the location on device '${this.opts.udid}'. Original error: ${e.message}`);55 } finally {56 service.close();57 }58};59/**60 * Reset the location service on real device.61 * Raises not implemented error for simulator.62 * @throws {Error} If the device is simulator, or 'resetLocation' raises an error.63 */64commands.mobileResetLocationService = async function mobileResetLocationService () {65 if (this.isSimulator()) {66 throw new errors.NotImplementedError();67 }68 const service = await services.startSimulateLocationService(this.opts.udid);69 try {70 service.resetLocation();71 } catch (err) {72 this.log.errorAndThrow(`Failed to reset the location on the device on device '${this.opts.udid}'. ` +73 `Origianl error: ${err.message}`);74 } finally {75 service.close();76 }77};78export { commands };...
location-specs.js
Source:location-specs.js
1import sinon from 'sinon';2import XCUITestDriver from '../../..';3import { services } from 'appium-ios-device';4describe('location commands', function () {5 const udid = '1234';6 const driver = new XCUITestDriver();7 const proxySpy = sinon.stub(driver, 'proxyCommand');8 afterEach(function () {9 proxySpy.reset();10 });11 describe('setLocation', function () {12 let startSimulateLocationServiceStub;13 let setLocationStub;14 beforeEach(function () {15 startSimulateLocationServiceStub = sinon.stub(services, 'startSimulateLocationService');16 let mockService = { setLocation () {}, close () {} };17 setLocationStub = sinon.stub(mockService, 'setLocation');18 startSimulateLocationServiceStub.returns(mockService);19 });20 afterEach(function () {21 startSimulateLocationServiceStub.restore();22 setLocationStub.restore();23 });24 it('should fail when location object is wrong', async function () {25 await driver.setGeoLocation({})26 .should.eventually.be.rejectedWith('Both latitude and longitude should be set');27 });28 describe('on real device', function () {29 beforeEach(function () {30 driver.opts.udid = udid;31 driver.opts.realDevice = true;32 });33 it('should use location service to set a location', async function () {34 await driver.setGeoLocation({latitude: 1.234, longitude: 2.789});35 startSimulateLocationServiceStub.calledOnce.should.be.true;36 startSimulateLocationServiceStub.firstCall.args[0].should.eql(udid);37 setLocationStub.args[0].should.eql([1.234, 2.789]);38 });39 it('should use location service to set a location with negative values', async function () {40 await driver.setGeoLocation({latitude: 1.234, longitude: -2});41 startSimulateLocationServiceStub.calledOnce.should.be.true;42 startSimulateLocationServiceStub.firstCall.args[0].should.eql(udid);43 setLocationStub.args[0].should.eql([1.234, -2]);44 });45 });46 describe('on simulator', function () {47 let deviceSetLocationSpy;48 beforeEach(function () {49 driver.opts.realDevice = false;50 deviceSetLocationSpy = sinon.spy();51 driver.opts.device = {52 setGeolocation: deviceSetLocationSpy,53 };54 });55 afterEach(function () {56 deviceSetLocationSpy.resetHistory();57 });58 it('should set string coordinates', async function () {59 await driver.setGeoLocation({latitude: '1.234', longitude: '2.789'});60 deviceSetLocationSpy.firstCall.args[0].should.eql('1.234');61 deviceSetLocationSpy.firstCall.args[1].should.eql('2.789');62 });63 it('should set number coordinates', async function () {64 await driver.setGeoLocation({latitude: 1, longitude: -2});65 deviceSetLocationSpy.firstCall.args[0].should.eql('1');66 deviceSetLocationSpy.firstCall.args[1].should.eql('-2');67 });68 });69 });...
Using AI Code Generation
1const webdriverio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7async function main () {8 let client = await webdriverio.remote(opts);9 await client.pause(5000);10 await client.startSimulateLocationService(40.7128, -74.0060, 100);11 await client.pause(5000);12 await client.stopSimulateLocationService();13 await client.pause(5000);14 await client.deleteSession();15}16main();17const webdriverio = require('webdriverio');18const assert = require('assert');19const opts = {20 capabilities: {21 }22};23async function main () {24 let client = await webdriverio.remote(opts);25 await client.pause(5000);26 await client.startSimulateLocationService(40.7128, -74.0060, 100);27 await client.pause(5000);28 await client.stopSimulateLocationService();29 await client.pause(5000);30 await client.deleteSession();31}32main();33const webdriverio = require('webdriverio');34const assert = require('
Using AI Code Generation
1await driver.services.startSimulateLocationService(location);2await driver.services.stopSimulateLocationService();3await driver.services.setDeviceOrientation(orientation);4await driver.services.setDeviceOrientation(orientation);5await driver.services.setDeviceOrientation(orientation);6await driver.services.setDeviceOrientation(orientation);7await driver.services.setDeviceOrientation(orientation);8await driver.services.setDeviceOrientation(orientation);9await driver.services.setDeviceOrientation(orientation);10await driver.services.setDeviceOrientation(orientation);11await driver.services.setDeviceOrientation(orientation);12await driver.services.setDeviceOrientation(orientation);13await driver.services.setDeviceOrientation(orientation);14await driver.services.setDeviceOrientation(orientation);15await driver.services.setDeviceOrientation(orientation);16await driver.services.setDeviceOrientation(orientation);17await driver.services.setDeviceOrientation(orientation);18await driver.services.setDeviceOrientation(orientation);19await driver.services.setDeviceOrientation(orientation);
Using AI Code Generation
1const { services } = require('appium-xcuitest-driver');2services.startSimulateLocationService(40.7128, -74.0060);3const { services } = require('appium-xcuitest-driver');4services.stopSimulateLocationService();5const { services } = require('appium-xcuitest-driver');6services.startSimulateLocationService(40.7128, -74.0060);7const { services } = require('appium-xcuitest-driver');8services.stopSimulateLocationService();9const { services } = require('appium-xcuitest-driver');10services.startSimulateLocationService(40.7128, -74.0060);11const { services } = require('appium-xcuitest-driver');12services.stopSimulateLocationService();13const { services } = require('appium-xcuitest-driver');14services.startSimulateLocationService(40.7128, -74.0060);15const { services } = require('appium-xcuitest-driver');16services.stopSimulateLocationService();17const { services } = require('appium-xcuitest-driver');18services.startSimulateLocationService(40.7128, -74.0060);19const { services } = require('appium-xc
Using AI Code Generation
1const { startSimulateLocationService } = require('appium-xcuitest-driver/lib/commands/location');2const { services } = require('appium-xcuitest-driver');3async function main() {4 const args = {5 };6 await startSimulateLocationService.call(services, args);7}8main();9const { services } = require('appium-xcuitest-driver');10async function main() {11 const args = {12 };13 await services.startSimulateLocationService(args);14}15main();16const { services } = require('appium-xcuitest-driver');17async function main() {18 const args = {19 };20 await services.startSimulateLocationService(args);21}22main();
Using AI Code Generation
1await driver.execute('mobile: services.startSimulateLocationService', {latitude: 37.33233141, longitude: -122.0312186, altitude: 100});2await driver.execute('mobile: services.stopSimulateLocationService', {});3await driver.execute('mobile: services.startSimulateLocationService', {latitude: 37.33233141, longitude: -122.0312186, altitude: 100});4await driver.execute('mobile: services.stopSimulateLocationService', {});5await driver.execute('mobile: services.startSimulateLocationService', {latitude: 37.33233141, longitude: -122.0312186, altitude: 100});6await driver.execute('mobile: services.stopSimulateLocationService', {});7await driver.execute('mobile: services.startSimulateLocationService', {latitude: 37.332
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!!