How to use this.clickWebCoords method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

ios-controller.js

Source:ios-controller.js Github

copy

Full Screen

...389 var w = res.value.width, h = res.value.height;390 var clickX = x + (w / 2);391 var clickY = y + (h / 2);392 this.curWebCoords = {x: clickX, y: clickY};393 this.clickWebCoords(function (err, res) {394 // make sure real tap actually has time to register395 setTimeout(function () {396 cb(err, res);397 }, 500);398 });399 }.bind(this));400 }.bind(this));401 }.bind(this));402};403iOSController.pushFile = function (base64Data, remotePath, cb) {404 if (this.realDevice) {405 logger.debug("Unsupported: cannot write files to physical device");406 return cb(new NotYetImplementedError(), null);407 }408 logger.debug("Pushing " + remotePath + " to iOS simulator");409 var writeFile = function (err, fullPath) {410 if (err) return cb(err);411 logger.debug("Attempting to write " + fullPath + "...");412 async.series([413 function (cb) {414 try {415 if (fs.existsSync(fullPath)) {416 logger.debug(fullPath + " already exists, deleting...");417 fs.unlinkSync(fullPath);418 }419 mkdirp.sync(path.dirname(fullPath));420 var content = new Buffer(base64Data, 'base64');421 var fd = fs.openSync(fullPath, 'w');422 fs.writeSync(fd, content, 0, content.length, 0);423 fs.closeSync(fd);424 logger.debug("Wrote " + content.length + "bytes to " + fullPath);425 cb(null);426 } catch (e) {427 cb(e);428 }429 }.bind(this)430 ], function (err) {431 logger.debug("Returning response");432 if (err) return cb(err);433 cb(null, {434 status: status.codes.Success.code435 });436 });437 };438 this._getFullPath(remotePath, writeFile);439};440/*441 * Get the full path to an iOS simulator file.442 * Calls cb(err, fullFilePath)443 * /Some/Path fetches a file relative to the root of the device's filesystem.444 * /Applications/AppName.app/Some/Path fetches a file relative to the root of that Application's .app directory, adding in the GUID.445 * So it looks something like: /Applications/GUID-GUID-GUID-GUID/Some/Path446 */447iOSController._getFullPath = function (remotePath, cb) {448 var fullPath = "";449 var v = (this.args.platformVersion || this.iOSSDKVersion);450 var simRoots = this.sim.getDirs();451 if (simRoots.length < 1) {452 return cb(new Error("Could not find simulator root for SDK version " +453 v + "; have you launched this sim before?"));454 } else if (simRoots.length > 1) {455 logger.warn("There were multiple simulator roots for version " + v + ". " +456 "We may be pulling the file from the one you're not using!");457 }458 if (simRoots.length > 1) {459 var filteredSimRoots = simRoots.filter(function (root) {460 return fs.existsSync(root + "/Applications") || // ios7461 fs.existsSync(root + "/Containers/Data/Application"); // ios8462 });463 if (filteredSimRoots.length > 0) {464 simRoots = filteredSimRoots;465 }466 }467 var basePath = simRoots[0];468 var appName = null;469 if (this.args.app) {470 var appNameRegex = new RegExp("\\" + path.sep + "(\\w+\\.app)");471 var appNameMatches = appNameRegex.exec(this.args.app);472 if (appNameMatches) {473 appName = appNameMatches[1];474 }475 }476 // de-absolutize the path477 if (isWindows()) {478 if (remotePath.indexof("://") === 1) {479 remotePath = remotePath.slice(4);480 }481 } else {482 if (remotePath.indexOf("/") === 0) {483 remotePath = remotePath.slice(1);484 }485 }486 if (remotePath.indexOf(appName) === 0) {487 logger.debug("We want an app-relative file");488 var findPath = basePath;489 if (this.args.platformVersion >= 8) {490 // the .app file appears in /Containers/Data and /Containers/Bundle both. We only want /Bundle491 findPath = path.resolve(basePath, "Containers", "Bundle");492 }493 findPath = findPath.replace(/\s/g, '\\ ');494 var findCmd = 'find ' + findPath + ' -name "' + appName + '"';495 exec(findCmd, function (err, stdout) {496 if (err) return cb(err);497 var appRoot = stdout.replace(/\n$/, '');498 var subPath = remotePath.substring(appName.length + 1);499 fullPath = path.resolve(appRoot, subPath);500 cb(null, fullPath);501 }.bind(this));502 } else {503 logger.debug("We want a sim-relative file");504 fullPath = path.resolve(basePath, remotePath);505 cb(null, fullPath);506 }507};508iOSController.pullFile = function (remotePath, cb) {509 logger.debug("Pulling " + remotePath + " from sim");510 if (this.realDevice) {511 return cb(new NotYetImplementedError(), null);512 }513 var readAndReturnFile = function (err, fullPath) {514 if (err) return cb(err);515 logger.debug("Attempting to read " + fullPath);516 fs.readFile(fullPath, {encoding: 'base64'}, function (err, data) {517 if (err) return cb(err);518 cb(null, {status: status.codes.Success.code, value: data});519 });520 };521 this._getFullPath(remotePath, readAndReturnFile);522};523iOSController.pullFolder = function (remotePath, cb) {524 logger.debug("Pulling " + remotePath + " from sim");525 if (this.realDevice) {526 return cb(new NotYetImplementedError(), null);527 }528 var bufferOnSuccess = function (buffer) {529 logger.debug("Converting in-memory zip file to base64 encoded string");530 var data = buffer.toString('base64');531 logger.debug("Returning in-memory zip file as base54 encoded string");532 cb(null, {status: status.codes.Success.code, value: data});533 };534 var bufferOnFail = function (err) {535 cb(new Error(err));536 };537 var zipAndReturnFolder = function (err, fullPath) {538 if (err) return cb(err);539 logger.debug("Adding " + fullPath + " to an in-memory zip archive");540 var zip = new AdmZip();541 zip.addLocalFolder(fullPath);542 zip.toBuffer(bufferOnSuccess, bufferOnFail);543 };544 this._getFullPath(remotePath, zipAndReturnFolder);545};546iOSController.touchLongClick = function (elementId, cb) {547 cb(new NotYetImplementedError(), null);548};549iOSController.touchDown = function (elId, x, y, cb) {550 cb(new NotYetImplementedError(), null);551};552iOSController.touchUp = function (elementId, cb) {553 cb(new NotYetImplementedError(), null);554};555iOSController.touchMove = function (elId, startX, startY, cb) {556 cb(new NotYetImplementedError(), null);557};558iOSController.toggleData = function (cb) {559 cb(new NotYetImplementedError(), null);560};561iOSController.toggleFlightMode = function (cb) {562 cb(new NotYetImplementedError(), null);563};564iOSController.toggleWiFi = function (cb) {565 cb(new NotYetImplementedError(), null);566};567iOSController.toggleLocationServices = function (cb) {568 cb(new NotYetImplementedError(), null);569};570iOSController.getStrings = function (language, stringFile, cb) {571 this.parseLocalizableStrings(language, stringFile, function () {572 var strings = this.localizableStrings;573 if (strings && strings.length >= 1) strings = strings[0];574 cb(null, {575 status: status.codes.Success.code576 , value: strings577 });578 }.bind(this));579};580iOSController.executeAtom = function (atom, args, cb, alwaysDefaultFrame) {581 var counter = this.executedAtomsCounter++;582 var frames = alwaysDefaultFrame === true ? [] : this.curWebFrames;583 this.returnedFromExecuteAtom[counter] = false;584 this.processingRemoteCmd = true;585 this.remote.executeAtom(atom, args, frames, function (err, res) {586 this.processingRemoteCmd = false;587 if (!this.returnedFromExecuteAtom[counter]) {588 this.returnedFromExecuteAtom[counter] = true;589 res = this.parseExecuteResponse(res);590 cb(err, res);591 }592 }.bind(this));593 this.lookForAlert(cb, counter, 0, 5000);594};595iOSController.executeAtomAsync = function (atom, args, responseUrl, cb) {596 var counter = this.executedAtomsCounter++;597 this.returnedFromExecuteAtom[counter] = false;598 this.processingRemoteCmd = true;599 this.asyncResponseCb = cb;600 this.remote.executeAtomAsync(atom, args, this.curWebFrames, responseUrl, function (err, res) {601 this.processingRemoteCmd = false;602 if (!this.returnedFromExecuteAtom[counter]) {603 this.returnedFromExecuteAtom[counter] = true;604 res = this.parseExecuteResponse(res);605 cb(err, res);606 }607 }.bind(this));608 this.lookForAlert(cb, counter, 0, 5000);609};610iOSController.receiveAsyncResponse = function (asyncResponse) {611 var asyncCb = this.asyncResponseCb;612 //mark returned as true to stop looking for alerts; the js is done.613 this.returnedFromExecuteAtom = true;614 if (asyncCb !== null) {615 this.parseExecuteResponse(asyncResponse, asyncCb);616 asyncCb(null, asyncResponse);617 this.asyncResponseCb = null;618 } else {619 logger.warn("Received async response when we weren't expecting one! " +620 "Response was: " + JSON.stringify(asyncResponse));621 }622};623iOSController.parseExecuteResponse = deviceCommon.parseExecuteResponse;624iOSController.parseElementResponse = deviceCommon.parseElementResponse;625iOSController.lookForAlert = function (cb, counter, looks, timeout) {626 setTimeout(function () {627 if (typeof looks === 'undefined') {628 looks = 0;629 }630 if (this.instruments !== null) {631 if (!this.returnedFromExecuteAtom[counter] && looks < 11 && !this.selectingNewPage) {632 logger.debug("atom did not return yet, checking to see if " +633 "we are blocked by an alert");634 // temporarily act like we're not processing a remote command635 // so we can proxy the alert detection functionality636 this.alertCounter++;637 this.proxy("au.alertIsPresent()", function (err, res) {638 if (res !== null) {639 if (res.value === true) {640 logger.debug("Found an alert, returning control to client");641 this.returnedFromExecuteAtom[counter] = true;642 cb(null, {643 status: status.codes.Success.code644 , value: ''645 });646 } else {647 // say we're processing remote cmd again648 looks++;649 setTimeout(this.lookForAlert(cb, counter, looks), 1000);650 }651 }652 }.bind(this));653 }654 }655 }.bind(this), timeout);656};657iOSController.clickCurrent = function (button, cb) {658 var noMoveToErr = {659 status: status.codes.UnknownError.code660 , value: "Cannot call click() before calling moveTo() to set coords"661 };662 if (this.isWebContext()) {663 if (this.curWebCoords === null) {664 return cb(null, noMoveToErr);665 }666 this.clickWebCoords(cb);667 } else {668 if (this.curCoords === null) {669 return cb(null, noMoveToErr);670 }671 this.clickCoords(this.curCoords, cb);672 }673};674iOSController.clickCoords = function (coords, cb) {675 if (this.useRobot) {676 var tapUrl = this.args.robotUrl + "/tap";677 request.post({url:tapUrl, form: {x:coords.x, y:coords.y}}, cb);678 } else {679 var opts = coords;680 opts.tapCount = 1;...

Full Screen

Full Screen

gesture.js

Source:gesture.js Github

copy

Full Screen

...31 if (this.isWebContext()) {32 if (_.isNull(this.curWebCoords)) {33 throw new errors.UnknownError('Cannot call click() before calling moveTo() to set coords');34 }35 await this.clickWebCoords();36 } else {37 if (this.curCoords === null) {38 throw new errors.UnknownError("Cannot call click() before calling moveTo() to set coords");39 }40 await this.clickCoords(this.curCoords);41 }42};43helpers.clickCoords = async function (coords) {44 if (this.opts.useRobot) {45 /* TODO */throw new errors.NotYetImplementedError();46 } else {47 let opts = coords;48 opts.tapCount = 1;49 opts.duration = 0.3;...

Full Screen

Full Screen

web.js

Source:web.js Github

copy

Full Screen

...91 let {width, height} = await this.executeAtom('get_size', [atomsElement]);92 x = x + (width / 2);93 y = y + (height / 2);94 this.curWebCoords = {x, y};95 await this.clickWebCoords();96};97extensions.clickCoords = async function (coords) {98 let {x, y} = coords;99 // tap on absolute coordinates100 await this.proxyCommand('/wda/tap/nil', 'POST', {x, y});101};102extensions.translateWebCoords = async function (coords) {103 log.debug(`Translating coordinates (${JSON.stringify(coords)}) to web coordinates`);104 // add static offset for safari in landscape mode105 let yOffset = this.opts.curOrientation === 'LANDSCAPE' ? this.landscapeWebCoordsOffset : 0;106 // add extra offset for possible extra things in the top of the page107 yOffset += await this.getExtraNativeWebTapOffset();108 coords.y += await this.getExtraTranslateWebCoordsOffset();109 // absolutize web coords...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.pause(5000);8 await browser.clickWebCoords(100, 100);9 await browser.pause(5000);10})();11driver.context("WEBVIEW_com.android.chrome");12 at JWProxy.command (/Users/xxxxxx/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:236:13)13 at processTicksAndRejections (internal/process/task_queues.js:97:5)14 at async AndroidUiautomator2Driver.callee$0$0$ (/Users/xxxxxx/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:48:7)15 at async AndroidUiautomator2Driver.callee$0$0 [as execute] (/Users/xxxxxx/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:78:19)16 at async AndroidUiautomator2Driver.callee$0$0$ (/Users/xxxxxx/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:39:7)17 at async AndroidUiautomator2Driver.callee$0$0 [as execute] (/Users/xxxxxx/node_modules/appium/node_modules/appium-android-driver/lib/commands/context.js:78:19)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const wdio = require('webdriverio');3const assert = require('assert');4(async () => {5 const browser = await remote({6 capabilities: {7 }8 })9 await browser.pause(5000);10 await browser.clickWebCoords(100, 100);11 await browser.pause(2000);12 await browser.clickWebCoords(200, 200);13 await browser.pause(2000);14 await browser.deleteSession();15})().catch(async (e) => {16 console.error(e);17 await browser.deleteSession();18});19const { remote } = require('webdriverio');20const wdio = require('webdriverio');21const assert = require('assert');22(async () => {23 const browser = await remote({24 capabilities: {25 }26 })27 await browser.pause(5000);28 await browser.clickWebCoords(100, 100);29 await browser.pause(2000);30 await browser.clickWebCoords(200, 200);31 await browser.pause(2000);32 await browser.deleteSession();33})().catch(async (e) => {34 console.error(e);35 await browser.deleteSession();36});37const { remote } = require('webdriverio');38const wdio = require('webdriverio');39const assert = require('assert');40(async () => {41 const browser = await remote({42 capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', function () {2 it('should work', async function () {3 await driver.clickWebCoords(100, 100);4 });5});6- (id)handleClickWebCoords:(FBRouteRequest *)request7{8 CGPoint point = CGPointMake([request.arguments[@"x"] doubleValue], [request.arguments[@"y"] doubleValue]);9 [FBElementUtils tapScreenPoint:point application:[FBApplication fb_activeApplication]];10 return FBResponseWithOK();11}12+ (void)tapScreenPoint:(CGPoint)point application:(FBApplication *)application13{14 [FBLogger logFmt:@"Tapping point %@", NSStringFromCGPoint(point)];15 [application tapScreenPoint:point];16}17- (void)tapScreenPoint:(CGPoint)point18{19 [FBLogger logFmt:@"Tapping point %@", NSStringFromCGPoint(point)];20 [self tapScreenPoint:point withNumTaps:1];21}22- (void)tapScreenPoint:(CGPoint)point withNumTaps:(NSUInteger)numTaps23{24 [FBLogger logFmt:@"Tapping point %@ with %lu taps", NSStringFromCGPoint(point), (unsigned long)numTaps];25 [self fb_tapScreenPoint:point withNumTaps:numTaps];26}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test Suite', function() {2 it('Test Case', function() {3 });4});5describe('Test Suite', function() {6 it('Test Case', function() {7 this.clickWebCoords(100,200);8 });9});10describe('Test Suite', function() {11 it('Test Case', function() {12 this.clickWebCoords(100,200);13 });14});

Full Screen

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