Best JavaScript code snippet using appium-xcuitest-driver
Timer.js
Source:Timer.js
1// Timer.js v3.4.02(function() {3 //---------------------------------------------------------------------------4 // â
Timerã¯ã©ã¹ ä¸è¬ã¿ã¤ãã¼(çµéæéã®è¡¨ç¤º/èªåæ£çå¤å®ç¨)5 //---------------------------------------------------------------------------6 var timerInterval = 100; /* ã¿ã¤ãã¼å²ãè¾¼ã¿éé */7 ui.timer = {8 /* ã¡ã³ãå¤æ° */9 TID: null /* ã¿ã¤ãã¼ID */,10 current: 0 /* ç¾å¨ã®getTime()åå¾å¤(ããªç§) */,11 /* çµéæé表示ç¨å¤æ° */12 bseconds: 0 /* ååã©ãã«ã«è¡¨ç¤ºããæé(ç§æ°) */,13 timerEL: null /* çµéæé表示ç¨è¦ç´ */,14 /* èªåæ£çå¤å®ç¨å¤æ° */15 worstACtime: 0 /* æ£çå¤å®ã«ããã£ãæéã®ææªå¤(ããªç§) */,16 nextACtime: 0 /* 次ã«èªåæ£çå¤å®ã«ã¼ãã³ã«å
¥ããã¨ãå¯è½ã«ãªãæé */,17 //---------------------------------------------------------------------------18 // tm.reset() ã¿ã¤ãã¼ã®ã«ã¦ã³ãã0ã«ãã¦ãã¹ã¿ã¼ããã19 // tm.start() update()é¢æ°ã200msééã§å¼ã³åºã20 // tm.update() 200msåä½ã§å¼ã³åºãããé¢æ°21 //---------------------------------------------------------------------------22 init: function() {23 this.worstACtime = 0;24 this.timerEL = document.getElementById("timerpanel");25 this.showtime(0);26 },27 start: function() {28 var self = this;29 if (!!this.TID) {30 return;31 }32 ui.puzzle.resetTime();33 this.update();34 this.TID = setInterval(function() {35 self.update();36 }, timerInterval);37 },38 stop: function() {39 if (!this.TID) {40 return;41 }42 clearInterval(this.TID);43 this.TID = null;44 },45 update: function() {46 this.current = pzpr.util.currentTime();47 if (ui.puzzle.playeronly) {48 this.updatetime();49 }50 if (ui.menuconfig.get("autocheck_once")) {51 var mode = ui.menuconfig.get("autocheck_mode");52 this.autocheck(mode === "guarded");53 }54 },55 //---------------------------------------------------------------------------56 // tm.updatetime() ç§æ°ã®è¡¨ç¤ºãè¡ã57 // tm.label() çµéæéã«è¡¨ç¤ºããæååãè¿ã58 //---------------------------------------------------------------------------59 showtime: function(seconds) {60 var hours = (seconds / 3600) | 0;61 var minutes = ((seconds / 60) | 0) - hours * 60;62 seconds = seconds - minutes * 60 - hours * 3600;63 if (minutes < 10) {64 minutes = "0" + minutes;65 }66 if (seconds < 10) {67 seconds = "0" + seconds;68 }69 this.timerEL.innerHTML = [70 this.label(),71 !!hours ? hours + ":" : "",72 minutes,73 ":",74 seconds75 ].join("");76 },77 updatetime: function() {78 var seconds = (ui.puzzle.getTime() / 1000) | 0;79 if (this.bseconds === seconds) {80 return;81 }82 this.showtime(seconds);83 this.bseconds = seconds;84 },85 label: function() {86 return ui.selectStr("çµéæéï¼", "Time: ");87 },88 //---------------------------------------------------------------------------89 // tm.autocheck() èªåæ£è§£å¤å®ãå¼ã³åºã90 //---------------------------------------------------------------------------91 autocheck: function(guarded) {92 var puzzle = ui.puzzle;93 if (94 this.current > this.nextACtime &&95 puzzle.playmode &&96 !puzzle.checker.inCheck &&97 puzzle.board.trialstage === 0 &&98 !puzzle.getConfig("variant")99 ) {100 var check = puzzle.check(false);101 if (check.complete && (!guarded || !check.undecided)) {102 ui.timer.stop();103 puzzle.mouse.mousereset();104 ui.menuconfig.set("autocheck_once", false);105 if (ui.callbackComplete) {106 ui.callbackComplete(puzzle, check);107 }108 ui.notify.alert("æ£è§£ã§ãï¼", "Complete!");109 return;110 }111 this.worstACtime = Math.max(112 this.worstACtime,113 pzpr.util.currentTime() - this.current114 );115 this.nextACtime =116 this.current +117 (this.worstACtime < 250118 ? this.worstACtime * 4 + 120119 : this.worstACtime * 2 + 620);120 }121 }122 };123 //---------------------------------------------------------------------------124 // â
UndoTimerã¯ã©ã¹ Undo/Redoç¨ã¿ã¤ãã¼125 //---------------------------------------------------------------------------126 var undoTimerInterval = 25 /* ã¿ã¤ãã¼å²ãè¾¼ã¿éé */,127 execWaitTime = 300; /* 1åç®ã«waitãå¤ãå
¥ããããã®å¤ */128 ui.undotimer = {129 /* ã¡ã³ãå¤æ° */130 TID: null /* ã¿ã¤ãã¼ID */,131 inUNDO: false /* Undoå®è¡ä¸ */,132 inREDO: false /* Redoå®è¡ä¸ */,133 //---------------------------------------------------------------------------134 // ut.reset() ã¿ã¤ãã¼ãã¹ã¿ã¼ããã135 //---------------------------------------------------------------------------136 reset: function() {137 this.stop();138 },139 //---------------------------------------------------------------------------140 // ut.startUndo() Undoéå§å
±éå¦ç141 // ut.startRedo() Redoéå§å
±éå¦ç142 // ut.stopUndo() Undoåæ¢å
±éå¦ç143 // ut.stopRedo() Redoåæ¢å
±éå¦ç144 //---------------------------------------------------------------------------145 startUndo: function() {146 if (!(this.inUNDO || this.inREDO)) {147 this.inUNDO = true;148 this.proc();149 }150 },151 startRedo: function() {152 if (!(this.inREDO || this.inUNDO)) {153 this.inREDO = true;154 this.proc();155 }156 },157 stopUndo: function() {158 if (this.inUNDO) {159 this.inUNDO = false;160 this.proc();161 }162 },163 stopRedo: function() {164 if (this.inREDO) {165 this.inREDO = false;166 this.proc();167 }168 },169 //---------------------------------------------------------------------------170 // ut.start() Undo/Redoå¼ã³åºããéå§ãã171 // ut.stop() Undo/Redoå¼ã³åºããçµäºãã172 //---------------------------------------------------------------------------173 start: function() {174 var self = this;175 function handler() {176 self.proc();177 }178 function inithandler() {179 clearInterval(self.TID);180 self.TID = setInterval(handler, undoTimerInterval);181 }182 this.TID = setInterval(inithandler, execWaitTime);183 this.exec();184 },185 stop: function() {186 this.inUNDO = false;187 this.inREDO = false;188 clearInterval(this.TID);189 this.TID = null;190 },191 //---------------------------------------------------------------------------192 // ut.proc() Undo/Redoå¼ã³åºããå®è¡ãã193 // ut.exec() Undo/Redoé¢æ°ãå¼ã³åºã194 //---------------------------------------------------------------------------195 proc: function() {196 if ((this.inUNDO || this.inREDO) && !this.TID) {197 this.start();198 } else if (!(this.inUNDO || this.inREDO) && !!this.TID) {199 this.stop();200 } else if (!!this.TID) {201 this.exec();202 }203 },204 exec: function() {205 if (!this.checknextprop()) {206 this.stop();207 } else if (this.inUNDO) {208 ui.puzzle.undo();209 } else if (this.inREDO) {210 ui.puzzle.redo();211 }212 },213 //---------------------------------------------------------------------------214 // ut.checknextprop() 次ã«Undo/Redoãã§ãããã©ããã®å¤å®ãè¡ã215 //---------------------------------------------------------------------------216 checknextprop: function() {217 var opemgr = ui.puzzle.opemgr;218 var isenable =219 (this.inUNDO && opemgr.enableUndo) ||220 (this.inREDO && opemgr.enableRedo);221 return isenable;222 }223 };...
winappdriver.js
Source:winappdriver.js
...75 this.emit(WinAppDriver.EVENT_ERROR, e);76 // just because we had an error doesn't mean the winappdriver process77 // finished; we should clean up if necessary78 if (processIsAlive) {79 await this.proc.stop();80 }81 log.errorAndThrow(e);82 }83 } 84 sessionId () {85 if (this.state !== WinAppDriver.STATE_ONLINE) {86 return null;87 }88 return this.jwproxy.sessionId;89 }90 async waitForOnline () {91 // TODO WAD doesn't support the status command correctly, so just return92 // true for now93 return true;94 // we need to make sure WAD hasn't crashed95 /*96 let winappdriverStopped = false;97 await retryInterval(20, 200, async () => {98 if (this.state === WinAppDriver.STATE_STOPPED) {99 // we are either stopped or stopping, so something went wrong100 winappdriverStopped = true;101 return;102 }103 await this.getStatus();104 });105 if (winappdriverStopped) {106 throw new Error('WinAppDriver crashed during startup.');107 }*/108 }109 async getStatus () {110 return await this.jwproxy.command('/status', 'GET');111 }112 async startSession (caps) {113 this.proxyReqRes = this.jwproxy.proxyReqRes.bind(this.jwproxy);114 await this.jwproxy.command('/session', 'POST', {desiredCapabilities: caps});115 }116 async stop (emitStates = true) {117 if (emitStates) {118 this.changeState(WinAppDriver.STATE_STOPPING);119 }120 try {121 if (this.proc) {122 await this.proc.stop();123 }124 if (emitStates) {125 this.changeState(WinAppDriver.STATE_STOPPED);126 }127 } catch (e) {128 log.error(e);129 }130 }131 changeState (state) {132 this.state = state;133 log.debug(`WinAppDriver changed state to '${state}'`);134 this.emit(WinAppDriver.EVENT_CHANGED, {state});135 }136 async sendCommand (url, method, body) {...
appium-for-mac.js
Source:appium-for-mac.js
...53 this.emit(AppiumForMac.EVENT_ERROR, e);54 // just because we had an error doesn't mean the winappdriver process55 // finished; we should clean up if necessary56 if (processIsAlive) {57 await this.proc.stop();58 }59 log.errorAndThrow(e);60 }61 }62 sessionId () {63 if (this.state !== AppiumForMac.STATE_ONLINE) {64 return null;65 }66 return this.jwproxy.sessionId;67 }68 async waitForOnline () { // eslint-disable-line require-await69 // TODO: Actually check via HTTP70 return true;71 }72 async getStatus () {73 return await this.sendCommand('/status', 'GET');74 }75 async startSession (caps) {76 this.proxyReqRes = this.jwproxy.proxyReqRes.bind(this.jwproxy);77 await this.sendCommand('/session', 'POST', {desiredCapabilities: caps});78 }79 async stop () {80 try {81 if (this.proc) {82 await this.proc.stop();83 }84 } catch (e) {85 log.error(e);86 }87 }88 async sendCommand (url, method, body) {89 let res;90 // need to cover over A4M's bad handling of responses, which sometimes91 // don't have 'value' properties92 try {93 res = await this.jwproxy.command(url, method, body);94 } catch (e) {95 if (e.message.indexOf('Did not get a valid response object') === -1 ||96 e.message.indexOf('value') !== -1) {...
ios-simulator-log.js
Source:ios-simulator-log.js
...86 return;87 }88 log.debug('Stopping iOS log capture');89 try {90 await this.proc.stop('SIGTERM', 1000);91 } catch (e) {92 if (!this.proc.isRunning) {93 return;94 }95 logger.warn('Cannot stop log capture process. Sending SIGKILL...');96 await this.proc.stop('SIGKILL');97 }98 }99 get isCapturing () {100 return this.proc && this.proc.isRunning;101 }102 onOutput (logRow, prefix = '') {103 const logs = _.cloneDeep(logRow.split('\n'));104 for (const logLine of logs) {105 if (!logLine) continue; // eslint-disable-line curly106 this.broadcast(logLine);107 if (this.showLogs) {108 const space = prefix.length > 0 ? ' ' : '';109 log.info(`[IOS_SYSLOG_ROW${space}${prefix}] ${logLine}`);110 }...
uiautomator.js
Source:uiautomator.js
...45 } catch (e) {46 this.emit(UiAutomator.EVENT_ERROR, e);47 if (processIsAlive) {48 await this.killUiAutomatorOnDevice();49 await this.proc.stop();50 }51 log.errorAndThrow(e);52 }53 }54 async shutdown () {55 log.debug('Shutting down UiAutomator');56 if (this.state !== UiAutomator.STATE_STOPPED) {57 this.changeState(UiAutomator.STATE_STOPPING);58 await this.proc.stop();59 }60 await this.killUiAutomatorOnDevice();61 this.changeState(UiAutomator.STATE_STOPPED);62 }63 parseJarNameFromPath (binaryPath) {64 let reTest = /.*(\/|\\)(.*\.jar)/.exec(binaryPath);65 if (!reTest) {66 throw new Error(`Unable to parse jar name from ${binaryPath}`);67 }68 let jarName = reTest[2];69 log.debug(`Found jar name: '${jarName}'`);70 return jarName;71 }72 changeState (state) {...
appium-for-awtk.js
Source:appium-for-awtk.js
...39 }40 async stop () {41 try {42 if (this.proc) {43 await this.proc.stop();44 }45 } catch (e) {46 log.error(e);47 }48 }49 async sendCommand (url, method, body) {50 let res;51 // need to cover over A4A's bad handling of responses, which sometimes52 // don't have 'value' properties53 try {54 res = await this.jwproxy.command(url, method, body);55 } catch (e) {56 if (e.message.indexOf('Did not get a valid response object') === -1 ||57 e.message.indexOf('value') !== -1) {...
logcat.js
Source:logcat.js
...72 log.debug("Logcat already stopped");73 return;74 }75 this.proc.removeAllListeners('exit');76 await this.proc.stop();77 this.proc = null;78 }79 getLogs () {80 let logs = this.logsSinceLastRequest;81 this.logsSinceLastRequest = [];82 return logs;83 }84 getAllLogs () {85 return this.logs;86 }87}...
codecept-ctrl.js
Source:codecept-ctrl.js
1const path = require('path')2const spawn = require('child_process').spawn3const exec = require('child_process').exec4class CodeceptCtrl {5 constructor (environment, device, port) {6 // TODO Mix in process environment???7 this.env = {8 NODE_ENV: environment,9 DEVICE: device,10 PORT: port11 }12 this.cmd = 'node'13 this.cmd_opts = [14 './node_modules/codeceptjs/bin/codecept.js',15 'run',16 '--reporter', path.join(__dirname, './testbook-reporter.js').replace(/\\/g, '\\\\'),17 '-c',18 'codecept.conf.js',19 '-o',20 this.codeceptOptions,21 '--sort',22 '--debug' // Debug is of no use since using a custom reporter will disable all other output23 // '--grep', '@UserConvert'24 ]25 this.proc = undefined26 }27 /**28 * Add custom helpers by overriding the codeceptjs config on command line29 */30 get codeceptOptions () {31 // TODO: Override/ Add webdriver port per device32 return JSON.stringify({33 helpers: {34 WebDriverIO: {35 port: this.env.PORT36 },37 ScreenshotHelper: {38 require: path.join(__dirname, './helpers/screenshot-helper.js').replace(/\\/g, '\\\\')39 },40 MetaHelper: {41 require: path.join(__dirname, './helpers/meta-helper.js').replace(/\\/g, '\\\\')42 },43 ErrorHelper: {44 require: path.join(__dirname, './helpers/error-helper.js').replace(/\\/g, '\\\\')45 }46 }47 })48 }49 start () {50 console.log(`Running codeceptjs`, this.cmd, this.cmd_opts)51 this.proc = spawn(this.cmd, this.cmd_opts, {52 detached: true,53 env: Object.assign({}, process.env, this.env)54 })55 return this.proc56 }57 stop () {58 const os = require('os')59 const ps = require('process')60 if (os.platform() === 'win32') {61 exec('taskkill /pid ' + this.proc.pid + ' /T /F')62 } else {63 ps.kill(this.proc.pid)64 }65 }66}...
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6const caps = {7};8describe('Test', function () {9 this.timeout(60000);10 before(async function () {11 await this.proc.init(caps);12 });13 after(async function () {14 await this.proc.stop();15 });16 it('should work', async function () {17 this.proc.should.exist;18 });19});20const wd = require('wd');21const chai = require('chai');22const chaiAsPromised = require('chai-as-promised');23chai.use(chaiAsPromised);24chai.should();25const caps = {26};27describe('Test', function () {28 this.timeout(60000);29 before(async function () {30 await this.proc.init(caps);31 });32 after(async function () {33 await this.proc.closeApp();34 });35 it('should work', async function () {36 this.proc.should.exist;37 });38});39const wd = require('wd');40const chai = require('chai');41const chaiAsPromised = require('chai-as-promised');42chai.use(chaiAsPromised);43chai.should();44const caps = {45};46describe('Test', function () {47 this.timeout(60000);48 before(async function () {49 await this.proc.init(caps);50 });51 after(async function () {
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 },5};6const client = wdio.remote(opts);7client.init();8client.pause(3000);9client.stop();10client.end();
Using AI Code Generation
1this.proc.stop('SIGKILL');2this.proc.stop('SIGKILL');3this.proc.stop('SIGKILL');4this.proc.stop('SIGKILL');5this.proc.stop('SIGKILL');6this.proc.stop('SIGKILL');7this.proc.stop('SIGKILL');8this.proc.stop('SIGKILL');9this.proc.stop('SIGKILL');10this.proc.stop('SIGKILL');11this.proc.stop('SIGKILL');12this.proc.stop('SIGKILL');13this.proc.stop('SIGKILL');14this.proc.stop('SIGKILL');15this.proc.stop('SIGKILL');16this.proc.stop('SIGKILL');17this.proc.stop('SIGKILL');18this.proc.stop('SIGKILL');19this.proc.stop('SIGKILL');20this.proc.stop('SIGKILL');21this.proc.stop('SIGKILL');22this.proc.stop('SIGKILL');
Using AI Code Generation
1commands.stop = async function () {2 if (this.isRealDevice()) {3 log.debug('Stopping currently running simulator');4 await this.proc.stop('xcrun', ['simctl', 'shutdown', this.opts.device.udid]);5 }6};7proc.stop = async function (cmd, args, opts = {}) {8 await exec(cmd, args, _.defaults({killSignal: 'SIGTERM'}, opts));9};10async function exec (cmd, args, opts = {}) {11 const proc = new SubProcess(cmd, args, opts);12 try {13 await proc.start(0);14 await proc.stop();15 } finally {16 if (proc.isRunning) {17 log.debug(`Process '${cmd} ${args}' didn't end after ${opts.timeout}ms. ` +18 `Sending it SIGTERM`);19 await proc.stop('SIGTERM');20 if (proc.isRunning) {21 log.debug(`Process '${cmd} ${args}' didn't end after SIGTERM. ` +22 `Sending it SIGKILL`);23 await proc.stop('SIGKILL');24 }25 }26 }27}28async function exec (cmd, args, opts = {}) {29 const proc = new SubProcess(cmd, args, opts);30 try {31 await proc.start(0);32 await proc.stop();33 } finally {34 if (proc.isRunning) {35 log.debug(`Process '${cmd} ${args}' didn't end after ${opts.timeout}ms. ` +36 `Sending it SIGTERM`);37 await proc.stop('SIGTERM');38 if (proc.isRunning) {39 log.debug(`Process '${cmd} ${args}' didn't end after SIGTERM. ` +40 `Sending it SIGKILL`);41 await proc.stop('SIGKILL');42 }43 }44 }45}46class SubProcess {47 constructor (cmd, args, opts = {}) {48 this.cmd = cmd;49 this.args = args;50 this.opts = opts;51 this.proc = null;52 this.onOutput = null;53 this.onStderr = null;
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!!