Best JavaScript code snippet using appium-xcuitest-driver
gesture-specs.js
Source:gesture-specs.js
...318 x: '100',319 y: '300'320 }321 };322 const coords = await driver.getCoordinates(gesture);323 coords.areOffsets.should.be.true;324 coords.x.should.be.within(100, 101);325 coords.y.should.be.within(300, 301);326 });327 it('should properly parse coordinates if they are presented as numeric values', async () => {328 const gesture = {329 action: 'press',330 options: {331 x: 100.5,332 y: 300333 }334 };335 const coords = await driver.getCoordinates(gesture);336 coords.areOffsets.should.be.false;337 coords.x.should.be.within(100, 101);338 coords.y.should.be.within(300, 301);339 });340 it('should throw an exception if coordinates cannot be parsed', async () => {341 const gesture = {342 action: 'moveTo',343 options: {344 x: 'a',345 y: 300346 }347 };348 try {349 await driver.getCoordinates(gesture);350 sinon.assert.fail('An exception is expected to be thrown');351 } catch (e) {352 // this is expected353 }354 });355 });356 });...
funcLib.js
Source:funcLib.js
1//Start JQuery2$(document).ready(function () {3 //info dropdown4 $(".drop1").on("click", function () {5 $(".EmrgPhones").fadeIn();6 });7 $(".CloseEmrgPhones").on("click", function () {8 $(".EmrgPhones").hide();9 });10 $(".drop2").on("click", function () {11 $(".ContactRtes").fadeIn();12 });13 $(".CloseContactRtes").on("click", function () {14 $(".ContactRtes").hide();15 });16 $(".drop3").on("click", function () {17 $(".AboutRTES").fadeIn();18 });19 $(".CloseAboutRTES").on("click", function () {20 $(".AboutRTES").hide();21 });22 $(".reportLabelHeadClose").on("click", function () {23 $(".opRepLabelJs").hide();24 });25 //Settings drop down26 $(".opt1").on("click", function () {27 $(".settingsGui").fadeIn();28 });29 $(".CloseSettings").on("click", function () {30 $(".settingsGui").hide();31 });32 //Message Notification33 $(".CloseMsgNotif").on("click", function () {34 $(".msgANorifGui").hide();35 });36});37//System loading control38function loadControl() {39 40 $(window).on('load', function () { $("#spinner").fadeOut('slow'); });41 42}43//Start search Javascript//44//operator - for users by ID45function searchIdJs() {46 var input, filter, table, tr, td, i;47 input = document.getElementById("myInput");48 filter = input.value.toUpperCase();49 table = document.getElementById("myTable");50 tr = table.getElementsByTagName("tr");51 for (i = 0; i < tr.length; i++) {52 td = tr[i].getElementsByTagName("td")[0]; // first column53 if (td) {54 if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {55 tr[i].style.display = "";56 } else {57 tr[i].style.display = "none";58 }59 }60 }61}62//operator - for users by name63function searchNameJs() {64 var input, filter, table, tr, td, i;65 input = document.getElementById("myInput2");66 filter = input.value.toUpperCase();67 table = document.getElementById("myTable");68 tr = table.getElementsByTagName("tr");69 for (i = 0; i < tr.length; i++) {70 td = tr[i].getElementsByTagName("td")[1]; // second column71 if (td) {72 if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {73 tr[i].style.display = "";74 } else {75 tr[i].style.display = "none";76 }77 }78 }79}80//operator - for reports by report ID81function searchAllReportsByIdJs() {82 var input, filter, table, tr, td, i;83 input = document.getElementById("repInput1");84 filter = input.value.toUpperCase();85 table = document.getElementById("allReportsTable");86 tr = table.getElementsByTagName("tr");87 for (i = 0; i < tr.length; i++) {88 td = tr[i].getElementsByTagName("td")[0]; // first column89 if (td) {90 if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {91 tr[i].style.display = "";92 } else {93 tr[i].style.display = "none";94 }95 }96 }97}98//operator - for reports by Client ID99function searchAllReportsByClientIdJs() {100 var input, filter, table, tr, td, i;101 input = document.getElementById("repInput2");102 filter = input.value.toUpperCase();103 table = document.getElementById("allReportsTable");104 tr = table.getElementsByTagName("tr");105 for (i = 0; i < tr.length; i++) {106 td = tr[i].getElementsByTagName("td")[3]; // 3rd column107 if (td) {108 if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {109 tr[i].style.display = "";110 } else {111 tr[i].style.display = "none";112 }113 }114 }115}116//END search Javascript//117/////////////////////////////////////////118//operator js functions119var refresh;120var flag1 = 0;121function closeViewOpNotif() {122 $('#operatorNotification').hide();123}124function setRefreshes() {125 $("#opsContain").show();126 flag = 1; // flag for: if the user in operations room, interval should be activated127 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec128}129function stopRefresh() {130 clearInterval(refresh);131}132function returnRefresh() {133 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec134}135//location dropdown refreshes136var flagLoc = 0;137function stopRefreshLoc() {138 clearInterval(refresh);139 flagLoc = 1;140}141function returnRefreshLoc() {142 if (flagLoc != 1)143 {144 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec145 }146 147}148function hideOperations() {149 $("#opsContain").hide();150}151function hideClosedRepNotif() {152 $('#opsRoomNotif').hide();153}154function closeViewComment() { //also used in operations room - auto refresh155 $('#commentContainer').hide();156 if(flag==1) //if the user if in operations room, interval should be activated157 {158 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec159 }160}161function closeView3() {162 $('#editUserContainer').hide();163}164function closeView() {165 $('#messageContainer').hide();166}167function closeViewRep() {168 $('#opRepDetailsContainer').hide();169 if (flag == 1) //if the user is in operations room, interval should be activated170 {171 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec172 }173}174function closeView2() {175 $('#userDetailsContainer').hide();176}177function closeViewDriversDetails() {178 $('#DriversLocationContainer').hide();179 if (flag == 1) //if the user in operations room, interval should be activated180 {181 refresh = setInterval(function () { $('#opsContain').load('/operator/GetOperationsRoom'); }, 3000); // every 3 sec182 }183 flagLoc = 0;184}185//END operator js functions186//////////////////////////////////////////////187//Location Functions188var publicLatLng;189var publicLat;190var publicLng;191var driverFlag = 0;192var driverAddress = "Init22.."; //for driver tracking193function getLocation() { // get the Lat & Lng coordinates194 navigator.geolocation.getCurrentPosition(function (pos) {195 var lat = pos.coords.latitude;196 var lng = pos.coords.longitude;197 publicLatLng = lat + ", " + lng;198 publicLat = lat;199 publicLng = lng;200 if (lat != null) {201 document.getElementById("gpsIconOff").style.display = "none";202 document.getElementById("gpsIconOn").style.display = "inline";203 204 }205 206 });207 208}209function turnongps() { // Main turn on gps function210 var val = document.getElementById("gpsIconOn");211 if (val.style.display == 'none') {212 window.alert('Please turn on your gps!');213 }214}215var geocoder;216var infowindow;217// main location init function218function initMap() {219 getLocation();220 geocoder = new google.maps.Geocoder; //google API geocoder istance221 infowindow = new google.maps.InfoWindow;222 document.getElementById('submit').addEventListener('click', function () {223 224 geocodeLatLng(geocoder, infowindow);225 });226 227}228function geocodeLatLng(geocoder, infowindow) { //GeoCode Function229 var input = publicLatLng;230 document.getElementById('lat').value = publicLat;231 document.getElementById('lng').value = publicLng;232 var latlngStr = input.split(',', 2);233 var latlng = { lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1]) };234 geocoder.geocode({ 'location': latlng }, function (results, status) {235 if (status === 'OK') {236 if (results[1]) {237 document.getElementById('location1').value = results[0].formatted_address;238 infowindow.setContent(results[0].formatted_address);239 } else {240 window.alert('No results found');241 }242 } else {243 window.alert('Geocoder failed due to: ' + status);244 }245 });246}247var address = "Yarka, Israel"; //TEST248function setDestinationCoordeinates() { // Bind function249 var addr = document.getElementById('fieldReport2').value;250 addressToLocation(addr);251}252function addressToLocation(addr) { // convert text address to coordinates253 var geocoder = new google.maps.Geocoder();254 geocoder.geocode(255 {256 address: addr257 },258 function (results, status) {259 var resultLocations = [];260 if (status == google.maps.GeocoderStatus.OK) {261 if (results) {262 var numOfResults = results.length;263 for (var i = 0; i < numOfResults; i++) {264 var result = results[i];265 document.getElementById('latDest').value = result.geometry.location.lat();266 document.getElementById('lngDest').value = result.geometry.location.lng();267 resultLocations.push(268 {269 text: result.formatted_address,270 addressStr: result.formatted_address,271 location: result.geometry.location272 }273 );274 };275 }276 } else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {277 // address not found278 alert("address not found");279 }280 }281 );282}283//END Location Service Functions284//////////////////////////////////285// Truck Driver functions286var counter = 0;287var refreshTasks;288function driverAppSetRefreshes() { //Set refreshes interval of truck driver application289 $("#tasksContain").show();290 truckFlag = 1;291 refreshTasks = setInterval(function () {292 $('#tasksContain').load('/truckDriver/GetTasksList');293 document.getElementById("appWorking").style.color = "#3DFA23";294 }, 5000); // every 5 sec295 intervalGetLatLng = setInterval(function () {296 updateDriverLatLng();297 document.getElementById("appWorking").style.color = "#E5E735";298 }, 7000); // every 7 sec, update the driver location299}300function driverAppStop() { //Stop refresh intervals301 clearInterval(refreshTasks);302 clearInterval(intervalGetLatLng);303}304function restartApp() { //Function to reload driver application in case of gps failure305 location.reload();306}307function updateDriverLatLng() { //dynamic update - driver coordinates - AJAX308 309 if (publicLat == undefined) {310 driverAppStop();311 document.getElementById("reportNotif2").style.display = "inline";312 document.getElementById("myTable10").style.display = "none";313 document.getElementById("appWorking").style.color = "#FA2323"; 314 document.getElementById("restartDriverApp").style.display = "inline";315 }316 else {317 $.ajax({318 url: '/truckDriver/getCoordinates',319 type: 'POST',320 data: { latForm: publicLat, lngForm: publicLng, truckAddress: driverAddress },321 success: function (data) {322 document.getElementById("appWorking").style.color = "#3DFA23";323 },324 error: function () {325 document.getElementById("appWorking").style.color = "#FA2323";326 }327 });328 }329}330//buttons control331function tasksStopRefresh() {332 clearInterval(refreshTasks);333 clearInterval(intervalGetLatLng);334}335function closeTasksInfoPartial() {336 $('#TasksInfoPartialContainer').hide();337 if (truckFlag == 1) //if the user in driver app, interval should be activated338 {339 refreshTasks = setInterval(function () {340 $('#tasksContain').load('/truckDriver/GetTasksList');341 document.getElementById("appWorking").style.color = "#3DFA23";342 }, 5000); // every 5 sec343 intervalGetLatLng = setInterval(function () { updateDriverLatLng(); }, 7000); // every 7 sec, update the driver location344 }345}346// END Truck Driver functions347//Truck drivers Algorithm - bind client with server - AJAX348function redirectToServer(finalDriverId, finalReportId, finaldistance, priority1, priority2, priority3, priority4, priority5, priority6, priority1Role, priority2Role, priority3Role, priority4Role, priority5Role, priority6Role) { //send results to server side & redirect to main client view when algorithm done349 $.ajax({350 url: '/client/algorithmFunc',351 type: 'POST',352 data: { driverId: finalDriverId, reportId: finalReportId, distance: finaldistance, prior1: priority1, prior2: priority2, prior3: priority3, prior4: priority4, prior5: priority5, prior6: priority6, prior1Role: priority1Role, prior2Role: priority2Role, prior3Role: priority3Role, prior4Role: priority4Role, prior5Role: priority5Role, prior6Role: priority6Role },353 success: function (data) {354 alert("Tow truck driver assigned successfully!");355 document.getElementById("redirectBack").style.display = "inline";356 },357 error: function () {358 alert("Error: bufferView - Server ajax comunication failed.");359 }360 });361}...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getCoordinates().then(function (coords) {7 console.log(coords);8});9driver.quit();
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const { assert } = chai;5chai.use(chaiAsPromised);6async function main() {7 await driver.init({
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var assert = require('assert');3var By = webdriver.By;4var until = webdriver.until;5var driver = new webdriver.Builder()6 .forBrowser('iOS')7 .withCapabilities({8 })9 .build();10driver.getCoordinates('name', 'username').then(function(result) {11 console.log(result);12});13driver.quit();
Using AI Code Generation
1var driver = new webdriver.Builder()2 .withCapabilities({3 })4 .build();5 .then(function () {6 driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');7 driver.findElement(webdriver.By.name('btnG')).click();8 driver.wait(until.titleIs('webdriver - Google Search'), 1000);9 })10 .then(function () {11 driver.executeScript('mobile: getCoordinates', {element: driver.findElement(webdriver.By.name('q'))})12 .then(function (coords) {13 console.log(coords);14 });15 })16 .then(function () {17 driver.quit();18 });
Using AI Code Generation
1var webdriverio = require('webdriverio');2var assert = require('assert');3var options = {4 desiredCapabilities: {5 }6};7var client = webdriverio.remote(options);8 .init()9 .element('accessibility id', 'TestApp')10 .then(function(element) {11 return client.getCoordinates(element.value.ELEMENT);12 })13 .then(function(coordinates) {14 console.log(coordinates);15 })16 .end();17var webdriverio = require('webdriverio');18var assert = require('assert');19var options = {20 desiredCapabilities: {21 }22};23var client = webdriverio.remote(options);24 .init()25 .element('accessibility id', 'TestApp')26 .then(function(element) {27 return client.getCoordinates(element.value.ELEMENT);28 })29 .then(function(coordinates) {30 console.log(coordinates);31 })32 .end();33getOrientation: function ()
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!!