How to use driver.shake method in Appium

Best JavaScript code snippet using appium

appium.js

Source:appium.js Github

copy

Full Screen

1// #IPROMISE -----------------2require('colors');3var chai = require("chai");4var chaiAsPromised = require("chai-as-promised");5chai.use(chaiAsPromised);6global.expect = chai.expect;7var should = chai.should();8var bootAppium = require('./driver');9var resetEachTime = false;10// GLOBAL TRACKING -----------------11var rootDriver = null;12var localServer = null;13var allPassed = true;14var timeoutTime = 300000;15var resetSimulator = function(callback) {16 if (!rootDriver) {17 callback(true);18 return;19 }20 localServer.before();21 rootDriver.run(function* () {22 // wait for it to show up from appium23 var i = 0;24 while (i < 50) {25 try {26 // best-case first27 // reset data28 yield rootDriver.elementById('ResetTest').click();29 break;30 }31 catch (e) { }32 try {33 // if on crashed (red) app34 yield rootDriver.elementById('redbox-reload').click();35 }36 catch (e) { }37 try {38 // is there an alert?39 yield rootDriver.elementByName('OK').click();40 }41 catch (e) { }42 try {43 // now does it work?44 // reset data45 yield rootDriver.elementById('ResetTest').click();46 break;47 }48 catch (e) { }49 try {50 // ok, fine. shake it and click reload51 yield rootDriver.shake();52 yield rootDriver.elementById('Reload').click();53 }54 catch (e) { }55 // wait for a bit56 yield rootDriver.sleep(250);57 i++;58 }59 if (i >= 50) {60 // it's not coming back61 console.log("SIMULATOR DIED");62 callback(true);63 }64 else {65 callback(false);66 }67 });68};69var launchSimulator = function(callback) {70 bootAppium(function(options) {71 console.log("booted!")72 rootDriver = options.driver;73 realWd = options.realWd;74 wd = options.wd;75 localServer = options.localServer;76 chaiAsPromised.transferPromiseness = realWd.transferPromiseness;77 resetSimulator(callback);78 });79};80var quitSimulator = function(callback) {81 if (!rootDriver) {82 callback();83 }84 else {85 rootDriver.run(function* () {86 console.log("quitting");87 try {88 yield rootDriver.quit();89 console.log("quit");90 }91 catch(e) {92 console.log("ERROR quitting: " + e);93 }94 rootDriver = null;95 callback();96 });97 }98};99// BEFORE ENTIRE SUITE -----------------100before(function (done) {101 // console.log("before suite");102 this.timeout(timeoutTime);103 done();104});105// AFTER ENTIRE SUITE -----------------106after(function (done) {107 this.timeout(timeoutTime);108 // console.log("after suite");109 quitSimulator(function() {110 done();111 });112});113// BEFORE EACH TEST -----------------114var testCount = 0;115beforeEach(function (done) {116 this.timeout(timeoutTime);117 testCount++;118 // console.log("before each: " + testCount);119 console.log("beforeEach");120 resetSimulator(function(error) {121 if (error) {122 console.log("error; will quit");123 quitSimulator(function() {124 launchSimulator(function(error) {125 if (error) {126 throw ("unable to launch simulator");127 }128 else {129 done();130 }131 });132 });133 }134 else {135 done();136 }137 });138});139// AFTER EACH TEST -----------------140afterEach(function(done) {141 this.timeout(timeoutTime);142 console.log("afterEach");143 allPassed = allPassed && this.currentTest.state === 'passed';144 localServer.after();145 if (resetEachTime) {146 quitSimulator(function() {147 done();148 });149 }150 else {151 done();152 }153});154// EXPORT HELPER -----------------155// override "it" to remove test boilerplate156var newIt = function(name, callback) {157 it(name, function(done) {158 this.timeout(timeoutTime);159 rootDriver.run(function* () {160 yield callback(rootDriver, done)161 });162 });163};164// override "it" to remove test boilerplate165var itOnly = function(name, callback) {166 it.only(name, function(done) {167 this.timeout(timeoutTime);168 rootDriver.run(function* () {169 yield callback(rootDriver, done)170 });171 });172};173// override "it" to remove test boilerplate174var itPending = function(name, callback) {175 it.skip(name, function(done) {176 this.timeout(timeoutTime);177 rootDriver.run(function* () {178 yield callback(rootDriver, done)179 });180 });181};182export default newIt;...

Full Screen

Full Screen

autokin-mobile-steps.js

Source:autokin-mobile-steps.js Github

copy

Full Screen

1/*2 * Copyright 2018 Aries Beltran <ariesbe@icloud.com>3 * Licensed under the MIT license. See LICENSE.4 *5 * Autokin - Gherkin Mobile Steps6 */7'use strict';8const { Given, When, Then } = require('cucumber');9const { expect } = require('chai');10const { MobileBuilder } = require('./autokin-mobile');11const { Store } = require('../autokin');12Given('that I set {string} as platform with version of {string}', async (platform, version) => {13 await MobileBuilder.platform(platform, version);14});15Given('that I set {string} as device', async (deviceName) => {16 await MobileBuilder.deviceName(deviceName);17});18Given('that app is located at {string}', async (appPathOrURL) => {19 await MobileBuilder.appLocation(appPathOrURL);20});21When('I create new session on {string}', async (appiumServer) => {22 if(MobileBuilder.hasApp()) {23 await MobileBuilder.initialize(appiumServer);24 } else {25 return Promise.reject('Application location must be supplied before creating new session.');26 }27});28Then(/^I wait (.*) seconds$/, async (waitTime) => {29 await MobileBuilder.waitFor(waitTime);30});31Then('I capture mobile screen as {string}', async path => {32 await MobileBuilder.capture(path);33});34Then(/^I swipe to the (.*)$/, async direction => {35 await MobileBuilder.swipe(direction);36});37Then('I tap on element with accessibility id of {string}', async id => {38 let target = await MobileBuilder.accessibilityId(id);39 await MobileBuilder.tap(target);40});41Then('I tap on element with xpath of {string}', async id => {42 let target = await MobileBuilder.xpath(id);43 await MobileBuilder.tap(target);44});45Then(/^I tap on (.*), (.*)$/, async (x, y) => {46 await MobileBuilder.tapWithCoordinates(x, y);47});48Then('I set {string} value to element with accessibility id of {string}', async (value, id) => {49 let target = await MobileBuilder.accessibilityId(id);50 await MobileBuilder.text(target, value);51});52Then('I set {string} value to element with xpath of {string}', async (value, id) => {53 let target = await MobileBuilder.xpath(id);54 await MobileBuilder.text(target, value);55});56Then('I expect element with accessibility id of {string} has value {string}', async (id, valueExpect) => {57 let target = await MobileBuilder.accessibilityId(id);58 let value = await MobileBuilder.text(target);59 expect(value).to.eql(Store.sanitize(valueExpect));60});61Then('I expect element with xpath of {string} has value {string}', async (id, valueExpect) => {62 let target = await MobileBuilder.xpath(id);63 let value = await MobileBuilder.text(target);64 expect(value).to.eql(Store.sanitize(valueExpect));65});66Then('I expect device keyboard is visible', async () => {67 let deviceDriver = await MobileBuilder.getDriver();68 let isShown = await deviceDriver.isKeyboardShown();69 expect(isShown).to.eql(true);70});71Then('I hide device keyboard', async () => {72 let deviceDriver = await MobileBuilder.getDriver();73 await deviceDriver.hideDeviceKeyboard();74});75Then('I shake the device', async () => {76 let deviceDriver = await MobileBuilder.getDriver();77 await deviceDriver.shake();78});79Then(/^I make the app run in the background and make active after (.*) seconds$/, async (timeout) => {80 let deviceDriver = await MobileBuilder.getDriver();81 await deviceDriver.backgroundApp(MobileBuilder.resolveInt(timeout));82});83Then('I close the session', async () => {84 await MobileBuilder.closeSession();...

Full Screen

Full Screen

cuebot-phone-steps.js

Source:cuebot-phone-steps.js Github

copy

Full Screen

1/*2 * Copyright 2020 Jonathan L. Magaru <jonathan.magaru.code@gmail.com>3 * Licensed under the MIT license. See LICENSE.4 *5 * Cuebot - Gherkin Mobile Steps6 */7'use strict';8const { Given, When, Then } = require('cucumber');9const { expect } = require('chai');10const { MobileBuilder } = require('./cuebot-phone');11Given('that I set {string} as platform with version of {string}', async (platform, version) => {12 await MobileBuilder.platform(platform, version);13});14Given('that I set {string} as device', async (deviceName) => {15 await MobileBuilder.deviceName(deviceName);16});17Given('that app is located at {string}', async (appPathOrURL) => {18 await MobileBuilder.appLocation(appPathOrURL);19});20When('I create new session on {string}', async (appiumServer) => {21 if(MobileBuilder.hasApp()) {22 await MobileBuilder.initialize(appiumServer);23 } else {24 return Promise.reject('Application location must be supplied before creating new session.');25 }26});27Then(/^I wait (.*) seconds$/, async (waitTime) => {28 await MobileBuilder.waitFor(waitTime);29});30Then('I capture mobile screen as {string}', async path => {31 await MobileBuilder.capture(path);32});33Then(/^I swipe to the (.*)$/, async direction => {34 await MobileBuilder.swipe(direction);35});36Then('I tap on element with accessibility id of {string}', async id => {37 let target = await MobileBuilder.accessibilityId(id);38 await MobileBuilder.tap(target);39});40Then('I tap on element with xpath of {string}', async id => {41 let target = await MobileBuilder.xpath(id);42 await MobileBuilder.tap(target);43});44Then(/^I tap on (.*), (.*)$/, async (x, y) => {45 await MobileBuilder.tapWithCoordinates(x, y);46});47Then('I set {string} value to element with accessibility id of {string}', async (value, id) => {48 let target = await MobileBuilder.accessibilityId(id);49 await MobileBuilder.text(target, value);50});51Then('I set {string} value to element with xpath of {string}', async (value, id) => {52 let target = await MobileBuilder.xpath(id);53 await MobileBuilder.text(target, value);54});55Then('I expect element with accessibility id of {string} has value {string}', async (id, valueExpect) => {56 let target = await MobileBuilder.accessibilityId(id);57 let value = await MobileBuilder.text(target);58 expect(value).to.eql(valueExpect);59});60Then('I expect element with xpath of {string} has value {string}', async (id, valueExpect) => {61 let target = await MobileBuilder.xpath(id);62 let value = await MobileBuilder.text(target);63 expect(value).to.eql(valueExpect);64});65Then('I expect device keyboard is visible', async () => {66 let deviceDriver = await MobileBuilder.getDriver();67 let isShown = await deviceDriver.isKeyboardShown();68 expect(isShown).to.eql(true);69});70Then('I hide device keyboard', async () => {71 let deviceDriver = await MobileBuilder.getDriver();72 await deviceDriver.hideDeviceKeyboard();73});74Then('I shake the device', async () => {75 let deviceDriver = await MobileBuilder.getDriver();76 await deviceDriver.shake();77});78Then(/^I make the app run in the background and make active after (.*) seconds$/, async (timeout) => {79 let deviceDriver = await MobileBuilder.getDriver();80 await deviceDriver.backgroundApp(MobileBuilder.resolveInt(timeout));81});82Then('I close the session', async () => {83 await MobileBuilder.closeSession();...

Full Screen

Full Screen

socketHandler.js

Source:socketHandler.js Github

copy

Full Screen

1/*2'socketHandler.js' handles messages coming from the driver. It consists of3a single variable that is an object whose methods are programmatically added4to for each "configuration tab". The methods here are the "core" methods.5*/6var socketHandler = {7 'handshake' : (function(){8 return function(data) {9 console.log('socketHandler.handshake...')10 console.log(data);11 if (data.data.message.hasOwnProperty('result')) {12 if (data.data.message.result == 'success') {13 if (session_id == "") {14 session_id = data.sessionID;15 setCookie('session_id',session_id,21);16 }17 name = data.data.name;18 if (name == 'driver') {19 driver_id = data.from;20 setCookie('driver_id',driver_id,21);21 }22 if (name == 'labware') {23 labware_id = data.from;24 setCookie('labware_id',labware_id,21);25 }26 if (name == 'bootstrapper') {27 bootstrapper_id = data.from;28 setCookie('bootstrapper_id',bootstrapper_id,21);29 }30 id_url_topic = 'com.opentrons.'+session_id;31 console.log('Setting up subscribe for NEW url topic ',id_url_topic);32 globalConnection1.session.subscribe(id_url_topic, function(str) {33 try{34 console.log('message on '+id_url_topic+': '+str);35 var msg = JSON.parse(str);36 // TODO: add socketHandler here37 /* add socketHandler here */38 var msg = JSON.parse(str);39 //if(msg.type && socketHandler[msg.type]) socketHandler[msg.type](msg.data);40 //41 // socketHandler format is no longer {'type': ... , 'data': ... }42 // now it's {'name' , '' } ... TODO: run a test to confirm format and then finish this43 if (msg.type) {44 console.log('socketHandler will be called here');45 if (socketHandler[msg.type]) socketHandler[msg.type](msg);46 } else {47 console.log('error, msg missing type');48 }49 } catch(e) {50 console.log('error handling message');51 console.log(e.message);52 }53 });54 if (name == 'driver') {55 sendMessage('com.opentrons.bootstrapper_handshake',driver_id,session_id,'handshake','driver','shake','');56 if (handshake_flow.labware == false) sendMessage('com.opentrons.labware_handshake',labware_id,session_id,'handshake','labware','extend','');57 if (handshake_flow.driver == false) sendMessage('com.opentrons.driver_',labware_id,session_id,'handshake','bootstrapper','extend','');58 }59 if (name == 'labware') {60 sendMessage('com.opentrons.labware_handshake',labware_id,session_id,'handshake','labware','shake','');61 }62 if (name == 'bootstrapper') {63 sendMessage('com.opentrons.bootstrapper_handshake',bootstrapper_id,session_id,'handshake','bootstrapper','shake','');64 }65 66 }67 if (data.data.message.result == 'already_connected') {68 if (name == 'driver') {69 driver_id = data.from;70 setCookie('driver_id',driver_id,21);71 }72 if (name == 'labware') {73 labware_id = data.from;74 setCookie('labware_id',labware_id,21);75 }76 if (name == 'bootstrapper') {77 bootstrapper_id = data.from;78 setCookie('bootstrapper_id',bootstrapper_id,21);79 }80 }81 }82 }83 })(),84 'test' : (function(){85 return function(data) {86 console.log(data);87 }88 })()...

Full Screen

Full Screen

shake.js

Source:shake.js Github

copy

Full Screen

...16 * mob.shake();//Perform shake action on the device.17 */18module.exports = async function() {19 await this.helpers.assertContext(this.helpers.contextList.ios);20 await this.driver.shake();...

Full Screen

Full Screen

mobile-shake-specs.js

Source:mobile-shake-specs.js Github

copy

Full Screen

1"use strict";2var setup = require("../../../common/setup-base")3 , desired = require('../desired');4describe('uicatalog - gestures - mobile shake @skip-ios6', function () {5 var driver;6 setup(this, desired).then(function (d) { driver = d; });7 it('should not error', function (done) {8 driver.shakeDevice().nodeify(done);9 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var assert = require('assert');3var options = {4 desiredCapabilities: {5 }6};7var client = webdriverio.remote(options);8 .init()9 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)10 .click('#com.xxx.xxx:id/xxx')11 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)12 .click('#com.xxx.xxx:id/xxx')13 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)14 .click('#com.xxx.xxx:id/xxx')15 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)16 .click('#com.xxx.xxx:id/xxx')17 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)18 .click('#com.xxx.xxx:id/xxx')19 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)20 .click('#com.xxx.xxx:id/xxx')21 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)22 .click('#com.xxx.xxx:id/xxx')23 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)24 .click('#com.xxx.xxx:id/xxx')25 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)26 .click('#com.xxx.xxx:id/xxx')27 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)28 .click('#com.xxx.xxx:id/xxx')29 .waitForVisible('#com.xxx.xxx:id/xxx', 10000)30 .click('#com.xxx.xxx:id/xxx')31 .performShake()32 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var caps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(caps)7 .elementByName('ComputeSumButton')8 .click()9 .elementByName('Answer')10 .text()11 .then(function (text) {12 assert.equal(text, "10");13 })14 .sleep(5000)15 .shake()16 .sleep(5000)17 .quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium-driver');2var driver = new AppiumDriver();3driver.shake();4var AppiumDriver = require('appium-driver');5var driver = new AppiumDriver();6driver.shake();7var AppiumDriver = require('appium-driver');8var driver = new AppiumDriver();9driver.shake();10var AppiumDriver = require('appium-driver');11var driver = new AppiumDriver();12driver.shake();13var AppiumDriver = require('appium-driver');14var driver = new AppiumDriver();15driver.shake();16var AppiumDriver = require('appium-driver');17var driver = new AppiumDriver();18driver.shake();19var AppiumDriver = require('appium-driver');20var driver = new AppiumDriver();21driver.shake();22var AppiumDriver = require('appium-driver');23var driver = new AppiumDriver();24driver.shake();25var AppiumDriver = require('appium-driver');26var driver = new AppiumDriver();27driver.shake();28var AppiumDriver = require('appium-driver');29var driver = new AppiumDriver();30driver.shake();31var AppiumDriver = require('appium-driver');32var driver = new AppiumDriver();33driver.shake();34var AppiumDriver = require('appium-driver');35var driver = new AppiumDriver();36driver.shake();37var AppiumDriver = require('

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 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful