Best JavaScript code snippet using appium-base-driver
retry_operation.js
Source:retry_operation.js
1function RetryOperation(timeouts, options) {2 // Compatibility for the old (timeouts, retryForever) signature3 if (typeof options === 'boolean') {4 options = { forever: options };5 }6 this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));7 this._timeouts = timeouts;8 this._options = options || {};9 this._maxRetryTime = options && options.maxRetryTime || Infinity;10 this._fn = null;11 this._errors = [];12 this._attempts = 1;13 this._operationTimeout = null;14 this._operationTimeoutCb = null;15 this._timeout = null;16 this._operationStart = null;17 if (this._options.forever) {18 this._cachedTimeouts = this._timeouts.slice(0);19 }20}21module.exports = RetryOperation;22RetryOperation.prototype.reset = function() {23 this._attempts = 1;24 this._timeouts = this._originalTimeouts;25}26RetryOperation.prototype.stop = function() {27 if (this._timeout) {28 clearTimeout(this._timeout);29 }30 this._timeouts = [];31 this._cachedTimeouts = null;32};33RetryOperation.prototype.retry = function(err) {34 if (this._timeout) {35 clearTimeout(this._timeout);36 }37 if (!err) {38 return false;39 }40 var currentTime = new Date().getTime();41 if (err && currentTime - this._operationStart >= this._maxRetryTime) {42 this._errors.unshift(new Error('RetryOperation timeout occurred'));43 return false;44 }45 this._errors.push(err);46 var timeout = this._timeouts.shift();47 if (timeout === undefined) {48 if (this._cachedTimeouts) {49 // retry forever, only keep last error50 this._errors.splice(this._errors.length - 1, this._errors.length);51 this._timeouts = this._cachedTimeouts.slice(0);52 timeout = this._timeouts.shift();53 } else {54 return false;55 }56 }57 var self = this;58 var timer = setTimeout(function() {59 self._attempts++;60 if (self._operationTimeoutCb) {61 self._timeout = setTimeout(function() {62 self._operationTimeoutCb(self._attempts);63 }, self._operationTimeout);64 if (self._options.unref) {65 self._timeout.unref();66 }67 }68 self._fn(self._attempts);69 }, timeout);70 if (this._options.unref) {71 timer.unref();72 }73 return true;74};75RetryOperation.prototype.attempt = function(fn, timeoutOps) {76 this._fn = fn;77 if (timeoutOps) {78 if (timeoutOps.timeout) {79 this._operationTimeout = timeoutOps.timeout;80 }81 if (timeoutOps.cb) {82 this._operationTimeoutCb = timeoutOps.cb;83 }84 }85 var self = this;86 if (this._operationTimeoutCb) {87 this._timeout = setTimeout(function() {88 self._operationTimeoutCb();89 }, self._operationTimeout);90 }91 this._operationStart = new Date().getTime();92 this._fn(this._attempts);93};94RetryOperation.prototype.try = function(fn) {95 console.log('Using RetryOperation.try() is deprecated');96 this.attempt(fn);97};98RetryOperation.prototype.start = function(fn) {99 console.log('Using RetryOperation.start() is deprecated');100 this.attempt(fn);101};102RetryOperation.prototype.start = RetryOperation.prototype.try;103RetryOperation.prototype.errors = function() {104 return this._errors;105};106RetryOperation.prototype.attempts = function() {107 return this._attempts;108};109RetryOperation.prototype.mainError = function() {110 if (this._errors.length === 0) {111 return null;112 }113 var counts = {};114 var mainError = null;115 var mainErrorCount = 0;116 for (var i = 0; i < this._errors.length; i++) {117 var error = this._errors[i];118 var message = error.message;119 var count = (counts[message] || 0) + 1;120 counts[message] = count;121 if (count >= mainErrorCount) {122 mainError = error;123 mainErrorCount = count;124 }125 }126 return mainError;...
test-timeouts.js
Source:test-timeouts.js
1var common = require('../common');2var assert = common.assert;3var retry = require(common.dir.lib + '/retry');4(function testDefaultValues() {5 var timeouts = retry.timeouts();6 assert.equal(timeouts.length, 10);7 assert.equal(timeouts[0], 1000);8 assert.equal(timeouts[1], 2000);9 assert.equal(timeouts[2], 4000);10})();11(function testDefaultValuesWithRandomize() {12 var minTimeout = 5000;13 var timeouts = retry.timeouts({14 minTimeout: minTimeout,15 randomize: true16 });17 assert.equal(timeouts.length, 10);18 assert.ok(timeouts[0] > minTimeout);19 assert.ok(timeouts[1] > timeouts[0]);20 assert.ok(timeouts[2] > timeouts[1]);21})();22(function testPassedTimeoutsAreUsed() {23 var timeoutsArray = [1000, 2000, 3000];24 var timeouts = retry.timeouts(timeoutsArray);25 assert.deepEqual(timeouts, timeoutsArray);26 assert.notStrictEqual(timeouts, timeoutsArray);27})();28(function testTimeoutsAreWithinBoundaries() {29 var minTimeout = 1000;30 var maxTimeout = 10000;31 var timeouts = retry.timeouts({32 minTimeout: minTimeout,33 maxTimeout: maxTimeout34 });35 for (var i = 0; i < timeouts; i++) {36 assert.ok(timeouts[i] >= minTimeout);37 assert.ok(timeouts[i] <= maxTimeout);38 }39})();40(function testTimeoutsAreIncremental() {41 var timeouts = retry.timeouts();42 var lastTimeout = timeouts[0];43 for (var i = 0; i < timeouts; i++) {44 assert.ok(timeouts[i] > lastTimeout);45 lastTimeout = timeouts[i];46 }47})();48(function testTimeoutsAreIncrementalForFactorsLessThanOne() {49 var timeouts = retry.timeouts({50 retries: 3,51 factor: 0.552 });53 var expected = [250, 500, 1000];54 assert.deepEqual(expected, timeouts);55})();56(function testRetries() {57 var timeouts = retry.timeouts({retries: 2});58 assert.strictEqual(timeouts.length, 2);...
timeouts_8h.js
Source:timeouts_8h.js
1var timeouts_8h =2[3 [ "lwip_cyclic_timer", "structlwip__cyclic__timer.html", null ],4 [ "SYS_TIMEOUTS_SLEEPTIME_INFINITE", "timeouts_8h.html#a9e2b2593e709ff54c7e3c0b003f6f1b0", null ],5 [ "lwip_cyclic_timer_handler", "timeouts_8h.html#a985c5d366b62bd179195e093ffcb7ecd", null ],6 [ "sys_timeout_handler", "timeouts_8h.html#a2ab5bb8173f492563f70a519011b0ac1", null ],7 [ "sys_check_timeouts", "group__lwip__nosys.html#ga83cffdf69ab60fd0eba9d17d363f9883", null ],8 [ "sys_restart_timeouts", "timeouts_8h.html#a6913959cf264dbe876b7e7c4db1cc13e", null ],9 [ "sys_timeout", "timeouts_8h.html#a8deed391626ec8b5423998e33782d7a8", null ],10 [ "sys_timeouts_init", "timeouts_8h.html#a60f42f167f496f6f740c8df48f4dd26c", null ],11 [ "sys_timeouts_sleeptime", "timeouts_8h.html#aa9971a14a5810cfeb1efd7104cde6664", null ],12 [ "sys_untimeout", "timeouts_8h.html#adbfcaa78f4b8d71ae0d7f0bcab6f8fb6", null ],13 [ "lwip_cyclic_timers", "timeouts_8h.html#addc06ab816f051a0fe6f280972eed142", null ],14 [ "lwip_num_cyclic_timers", "timeouts_8h.html#a9d01f287a19f20b073d3a1c306ecbfcd", null ]
...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var opts = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(opts);7 .init()8 .timeouts('script', 10000)9 .timeouts('implicit', 10000)10 .timeouts('page load', 10000)11 .end();12var webdriverio = require('webdriverio');13var opts = {14 desiredCapabilities: {15 }16};17var client = webdriverio.remote(opts);18 .init()19 .timeoutsScript(10000)20 .timeoutsImplicitWait(10000)21 .timeoutsPageLoad(10000)22 .end();
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7client.init()8 .timeouts('implicit', 10000)9 .timeouts('pageLoad', 10000)10 .timeouts('script', 10000)11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17var client = webdriverio.remote(options);18client.init()19 .timeouts('implicit', 10000)20 .timeouts('pageLoad', 10000)21 .timeouts('script', 10000)22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28var client = webdriverio.remote(options);
Using AI Code Generation
1const wd = require("wd");2const chai = require("chai");3const chaiAsPromised = require("chai-as-promised");4chai.use(chaiAsPromised);5const expect = chai.expect;6const assert = chai.assert;7const should = chai.should();8describe("Test Appium Base Driver", function() {9 this.timeout(300000);10 before(function() {11 const desired = {12 };13 .init(desired)14 .setImplicitWaitTimeout(5000)15 .setAsyncScriptTimeout(20000)16 .setPageLoadTimeout(10000);17 });18 after(function() {19 return driver.quit();20 });21 it("should get timeouts", function() {22 return driver.timeouts().then(function(timeouts) {23 console.log("timeouts", timeouts);24 expect(timeouts.implicit).to.equal(5000);25 expect(timeouts.asyncScript).to.equal(20000);26 expect(timeouts.pageLoad).to.equal(10000);27 });28 });29});30const wd = require("wd");31const chai = require("chai");32const chaiAsPromised = require("chai-as-promised");33chai.use(chaiAsPromised);34const expect = chai.expect;35const assert = chai.assert;36const should = chai.should();37describe("Test Appium Base Driver", function() {38 this.timeout(300000);39 before(function() {40 const desired = {
Using AI Code Generation
1describe('Appium Base Driver', function() {2 describe('timeouts', function() {3 it('should set the implicit wait timeout', function() {4 driver.timeouts('implicit', 1000);5 });6 });7});8describe('Appium Base Driver', function() {9 describe('timeouts', function() {10 it('should set the implicit wait timeout', function() {11 driver.timeouts('implicit', 1000);12 });13 });14});15describe('Appium Base Driver', function() {16 describe('timeouts', function() {17 it('should set the implicit wait timeout', function() {18 driver.timeouts('implicit', 1000);19 });20 });21});22describe('Appium Base Driver', function() {23 describe('timeouts', function() {24 it('should set the implicit wait timeout', function() {25 driver.timeouts('implicit', 1000);26 });27 });28});29describe('Appium Base Driver', function() {30 describe('timeouts', function() {31 it('should set the implicit wait timeout', function() {32 driver.timeouts('implicit', 1000);33 });34 });35});36describe('Appium Base Driver', function() {37 describe('timeouts', function() {38 it('should set the implicit wait timeout', function() {39 driver.timeouts('implicit', 1000);40 });41 });42});43describe('Appium Base Driver', function() {44 describe('timeouts', function() {45 it('should set the implicit wait timeout', function() {46 driver.timeouts('implicit', 1000);47 });48 });49});50describe('Appium Base Driver', function() {51 describe('timeouts', function() {52 it('should set the implicit wait timeout', function() {53 driver.timeouts('implicit', 1000);54 });55 });56});57describe('
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!!