Best JavaScript code snippet using appium-xcuitest-driver
sandbox.js
Source:sandbox.js
1/**2 * DDNæ²ç3 * wangxm 2019-06-194 */5import { spawn } from 'child_process'6import path from 'path'7class Sandbox {8 constructor (context, appId, callback) {9 this._context = context10 this._appId = appId11 this._appPath = path.join(this._context.config.dappsDir, appId)12 this._callback = callback13 this._sandboxVM = path.join(__dirname, 'safe-shell.js')14 this._cb = {}15 this._process = null16 }17 _invokCallback (type, data) {18 if (typeof (this._callback) === 'function') {19 this._callback(type, data)20 }21 }22 run (args) {23 if (this._process === null) {24 let params = [this._sandboxVM, this._appPath]25 params = params.concat(args)26 this._process = spawn('node', params, {27 cwd: this._appPath,28 stdio: ['pipe', 'pipe', 'pipe', 'ipc']29 // detached: false,30 // shell: os.platform() === "win32" ? "cmd.exe" : "/bin/sh"31 })32 this._process.on('error', (err) => {33 this._context.logger.error(`Dapp[${this._appId}] fail: ${err.message}`)34 this._invokCallback('error', err)35 })36 this._process.on('message', (msg) => {37 this._handleMessage(msg)38 this._invokCallback('message', msg)39 })40 this._process.on('close', (code) => {41 const info = `Dapp[${this._appId}] exit` + (code ? `: ${code}` : '.')42 this._context.logger.info(info)43 this._invokCallback('close', code)44 })45 this._process.stdout.on('data', (data) => {46 this._context.logger.info(`Dapp stdout[${this._appId}]: ${data}`)47 this._invokCallback('stdout_data', data)48 })49 this._process.stderr.on('data', (data) => {50 this._context.logger.error(`Dapp stderr[${this._appId}]: ${data}`)51 this._invokCallback('stderr_data', data)52 })53 }54 return this._process55 }56 stop () {57 if (this._process !== null && !this._process.killed) {58 try {59 this._process.disconnect()60 } catch (err) {61 ;62 }63 this._process.kill()64 this._process = null65 }66 }67 /**68 * åæ²çç¨åºå起请æ±69 * @param {*} req70 * @param {*} cb71 */72 request (req, cb) {73 if (req &&74 typeof (req.method) === 'string' &&75 typeof (req.path) === 'string' &&76 typeof (cb) === 'function') {77 req.seq = Math.round(Math.random() * 1000000)78 this._cb[`${req.method}_${req.path}_${req.seq}`] = cb79 if (this._process &&80 typeof (this._process.send) === 'function') {81 this._process.send(req)82 }83 }84 }85 /**86 * å¤çæ²çç¨åºè¿åçæ¶æ¯87 * @param {*} msg88 */89 _handleMessage (msg) {90 if (msg &&91 typeof (msg.method) === 'string' &&92 typeof (msg.path) === 'string' &&93 typeof (msg.seq) === 'number' &&94 (msg.result || msg.error)) {95 const key = `${msg.method}_${msg.path}_${msg.seq}`96 if (typeof (this._cb[key]) === 'function') {97 this._cb[key](msg.error, msg.result)98 }99 }100 }101}...
dynamodb.js
Source:dynamodb.js
...81 return;82 });83};84DynamoDBCLIWrapper.prototype.stop = function stop() {85 this._process.stop();...
redis.js
Source:redis.js
...75 return;76 });77};78RedisCLIWrapper.prototype.stop = function stop() {79 this._process.stop();...
cassandra.js
Source:cassandra.js
...75 return;76 });77};78CassandraCLIWrapper.prototype.stop = function stop() {79 this._process.stop();...
index.js
Source:index.js
...24 signal = SIGKILL;25 }26 if (this._process !== null) {27 async.clearTimeout(this._timerId);28 this._process.stop(signal);29 this._process = null;30 this._hasStarted = false;31 }32}33Process.prototype.restart = function() {34 stop();35 start();36}37Process.prototype.isAlive = function() {38 if (this._process !== null) {39 return this._process.isAlive() && this.getPid() != -1;40 }41 return false;42}...
PythonProcess.js
Source:PythonProcess.js
...25 }26 }27 stop() {28 if (!this._process) return;29 this._process.stop();30 this._process = null;31 }32 onReceiveMessage(handler) {33 this._receiveMessageHandlers.push(handler);34 }35 _handleProcessMessage = (msg) => {36 this._receiveMessageHandlers.forEach((handler) => {37 handler(msg);38 })39 }...
moch.js
Source:moch.js
1var Q = require('q');2var Instance = function(instance) {3 if (!(this instanceof Instance)) return new Instance(instance);4 this.info = instance;5};6Instance.prototype.getStatus = function() {7 var deferred = Q.defer();8 deferred.resolve(this.info.status);9 return deferred.promise;10};11Instance.prototype._process = function(status, resolve) {12 var deferred = Q.defer();13 if (this.info.status === status) {14 deferred.reject(new Error('instance already ' + resolve));15 } else {16 this.info.status = status;17 deferred.resolve(resolve);18 }19 return deferred.promise;20};21Instance.prototype.start = function() {22 return this._process('start', 'started');23};24Instance.prototype.stop = function() {25 return this._process('stop', 'stopped');26};27Instance.prototype.pause = function() {28 return this._process('pause', 'paused');29};30Instance.prototype.unpause = function() {31 return this._process('unpause', 'unpaused');32};33Instance.prototype.terminate = function() {34 return this._process('terminate', 'terminated');35};...
TaskQueue.js
Source:TaskQueue.js
1// @flow2export type Task<T> = {3 handler: () => T,4 resolve: T => void,5 reject: Error => void,6};7export class TaskQueue {8 _jobs: Array<Task<any>> = [];9 _running: boolean = false;10 addJob<E>(handler: () => E): Promise<E> {11 return new Promise((resolve: E => void, reject) => {12 this._jobs.push({handler, resolve, reject});13 this._process();14 });15 }16 start = () => {17 this._running = true;18 this._process();19 };20 stop = () => {21 this._running = false;22 };23 _process = () => {24 while (this._running && this._jobs.length) {25 const task = this._jobs.shift();26 try {27 const result = task.handler();28 task.resolve(result);29 } catch (e) {30 task.reject(e);31 }32 }33 };34}...
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 },5};6const client = wdio.remote(opts);7const app = client.$('~appname');8const element = app.$('~elementname');9(async () => {10 await client.init();11 await element.click();12 await client.pause(1000);13 await client._process.stop();14 await client.deleteSession();15})();
Using AI Code Generation
1const wdio = require('webdriverio');2const chai = require('chai');3const expect = chai.expect;4const assert = chai.assert;5const should = chai.should();6const driver = wdio.remote({7 capabilities: {8 }9});10driver.init().then(() => {11 console.log('App launched');12 driver.setImplicitTimeout(10000);13 driver.pause(5000);14 console.log('Pausing for 5 seconds');15 driver._process.stop();16 console.log('App closed');17});18const wdio = require('webdriverio');19const chai = require('chai');20const expect = chai.expect;21const assert = chai.assert;22const should = chai.should();23const driver = wdio.remote({24 capabilities: {25 }26});27driver.init().then(() => {28 console.log('App launched');29 driver.setImplicitTimeout(10000);30 driver.pause(5000);31 console.log('Pausing for 5 seconds');32 driver._process.stop();33 console.log('App closed');34});35const wdio = require('webdriverio');36const chai = require('chai');37const expect = chai.expect;38const assert = chai.assert;39const should = chai.should();40const driver = wdio.remote({
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var request = require('request');5var fs = require('fs');6var path = require('path');7var process = require('process');8var desired = {9};10 .init(desired)11 .then(function () {12 return driver.setImplicitWaitTimeout(5000);13 })14 .then(function () {15 return driver.elementByAccessibilityId('MyApp');16 })17 .then(function (el) {18 return el.click();19 })20 .then(function () {21 return driver.setImplicitWaitTimeout(5000);22 })23 .then(function () {24 return driver.elementByAccessibilityId('MyApp');25 })26 .then(function (el) {27 return el.click();28 })29 .then(function () {30 return driver.setImplicitWaitTimeout(5000);31 })32 .then(function () {33 return driver.elementByAccessibilityId('MyApp');34 })35 .then(function (el) {36 return el.click();37 })38 .then(function () {39 return driver.setImplicitWaitTimeout(5000);40 })41 .then(function () {42 return driver.elementByAccessibilityId('MyApp');43 })44 .then(function (el) {45 return el.click();46 })47 .then(function () {48 return driver.setImplicitWaitTimeout(5000);49 })50 .then(function () {51 return driver.elementByAccessibilityId('MyApp');52 })53 .then(function (el) {54 return el.click();55 })56 .then(function () {57 return driver.setImplicitWaitTimeout(5000);58 })59 .then(function () {60 return driver.elementByAccessibilityId('MyApp');61 })62 .then(function (el) {63 return el.click();64 })65 .then(function () {66 return driver.setImplicitWaitTimeout(5000);67 })68 .then(function () {69 return driver.elementByAccessibilityId('MyApp');70 })
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!!