How to use checkNodeOk method in Appium

Best JavaScript code snippet using appium

config-specs.js

Source:config-specs.js Github

copy

Full Screen

1// transpile:mocha2import _ from 'lodash';3import chai from 'chai';4import sinon from 'sinon';5import chaiAsPromised from 'chai-as-promised';6import { getGitRev, getAppiumConfig, checkNodeOk, warnNodeDeprecations,7         getNonDefaultArgs, getDeprecatedArgs, validateServerArgs,8         validateTmpDir, showConfig, checkValidPort } from '../lib/config';9import getParser from '../lib/parser';10import logger from '../lib/logger';11let should = chai.should();12chai.use(chaiAsPromised);13describe('Config', () => {14  describe('getGitRev', () => {15    it('should get a reasonable git revision', async () => {16      let rev = await getGitRev();17      rev.should.be.a('string');18      rev.length.should.be.equal(40);19      rev.match(/[0-9a-f]+/i)[0].should.eql(rev);20    });21  });22  describe('Appium config', () => {23    describe('getAppiumConfig', () => {24      it('should get a configuration object', async () => {25        let config = await getAppiumConfig();26        config.should.be.an('object');27        should.exist(config['git-sha']);28        should.exist(config.built);29        should.exist(config.version);30      });31    });32    describe('showConfig', () => {33      before(() => {34        sinon.spy(console, "log");35      });36      it('should log the config to console', async () => {37        let config = await getAppiumConfig();38        await showConfig();39        console.log.calledOnce.should.be.true;  // eslint-disable-line no-console40        console.log.getCall(0).args[0].should.contain(JSON.stringify(config)); // eslint-disable-line no-console41      });42    });43  });44  describe('node.js config', () => {45    let _process = process;46    before(() => {47      // need to be able to write to process.version48      // but also to have access to process methods49      // so copy them over to a writable object50      let tempProcess = {};51      for (let [prop, value] of _.toPairs(process)) {52        tempProcess[prop] = value;53      }54      process = tempProcess;55    });56    after(() => {57      process = _process;58    });59    describe('checkNodeOk', () => {60      it('should fail if node is below 4', () => {61        process.version = 'v4.4.7';62        checkNodeOk.should.throw();63        process.version = 'v0.9.12';64        checkNodeOk.should.throw();65        process.version = 'v0.1';66        checkNodeOk.should.throw();67        process.version = 'v0.10.36';68        checkNodeOk.should.throw();69        process.version = 'v0.12.14';70        checkNodeOk.should.throw();71      });72      it('should succeed if node is 5+', () => {73        process.version = 'v5.7.0';74        checkNodeOk.should.not.throw();75      });76      it('should succeed if node is 6+', () => {77        process.version = 'v6.3.1';78        checkNodeOk.should.not.throw();79      });80      it('should succeed if node is 7+', () => {81        process.version = 'v7.1.1';82        checkNodeOk.should.not.throw();83      });84      it('should succeed if node is 8+', () => {85        process.version = 'v8.1.2';86        checkNodeOk.should.not.throw();87      });88    });89    describe('warnNodeDeprecations', () => {90      let spy;91      before(() => {92        spy = sinon.spy(logger, "warn");93      });94      beforeEach(() => {95        spy.reset();96      });97      it('should log a warning if node is below 4', () => {98        process.version = 'v0.9.12';99        warnNodeDeprecations();100        logger.warn.callCount.should.equal(1);101      });102      it('should log a warning if node is 0.12', () => {103        process.version = 'v0.12.0';104        warnNodeDeprecations();105        logger.warn.callCount.should.equal(1);106      });107      it('should not log a warning if node is 4+', () => {108        process.version = 'v4.4.7';109        warnNodeDeprecations();110        logger.warn.callCount.should.equal(0);111      });112      it('should not log a warning if node is 5+', () => {113        process.version = 'v5.7.0';114        warnNodeDeprecations();115        logger.warn.callCount.should.equal(0);116      });117      it('should not log a warning if node is 6+', () => {118        process.version = 'v6.3.1';119        warnNodeDeprecations();120        logger.warn.callCount.should.equal(0);121      });122    });123  });124  describe('server arguments', () => {125    let parser = getParser();126    parser.debug = true; // throw instead of exit on error; pass as option instead?127    let args = {};128    beforeEach(() => {129      // give all the defaults130      for (let rawArg of parser.rawArgs) {131        args[rawArg[1].dest] = rawArg[1].defaultValue;132      }133    });134    describe('getNonDefaultArgs', () => {135      it('should show none if we have all the defaults', () => {136        let nonDefaultArgs = getNonDefaultArgs(parser, args);137        _.keys(nonDefaultArgs).length.should.equal(0);138      });139      it('should catch a non-default argument', () => {140        args.isolateSimDevice = true;141        let nonDefaultArgs = getNonDefaultArgs(parser, args);142        _.keys(nonDefaultArgs).length.should.equal(1);143        should.exist(nonDefaultArgs.isolateSimDevice);144      });145    });146    describe('getDeprecatedArgs', () => {147      it('should show none if we have no deprecated arguments', () => {148        let deprecatedArgs = getDeprecatedArgs(parser, args);149        _.keys(deprecatedArgs).length.should.equal(0);150      });151      it('should catch a deprecated argument', () => {152        args.showIOSLog = true;153        let deprecatedArgs = getDeprecatedArgs(parser, args);154        _.keys(deprecatedArgs).length.should.equal(1);155        should.exist(deprecatedArgs['--show-ios-log']);156      });157      it('should catch a non-boolean deprecated argument', () => {158        args.calendarFormat = 'orwellian';159        let deprecatedArgs = getDeprecatedArgs(parser, args);160        _.keys(deprecatedArgs).length.should.equal(1);161        should.exist(deprecatedArgs['--calendar-format']);162      });163    });164  });165  describe('checkValidPort', () => {166    it('should be false for port too high', () => {167      checkValidPort(65536).should.be.false;168    });169    it('should be false for port too low', () => {170      checkValidPort(0).should.be.false;171    });172    it('should be true for port 1', () => {173      checkValidPort(1).should.be.true;174    });175    it('should be true for port 65535', () => {176      checkValidPort(65535).should.be.true;177    });178  });179  describe('validateTmpDir', () => {180    it('should fail to use a tmp dir with incorrect permissions', async () => {181      validateTmpDir('/private/if_you_run_with_sudo_this_wont_fail').should.be.rejectedWith(/could not ensure/);182    });183    it('should fail to use an undefined tmp dir', async () => {184      validateTmpDir().should.be.rejectedWith(/could not ensure/);185    });186    it('should be able to use a tmp dir with correct permissions', async () => {187      validateTmpDir('/tmp/test_tmp_dir/with/any/number/of/levels').should.not.be.rejected;188    });189  });190  describe('parsing args with empty argv[1]', () => {191    let argv1;192    before(() => {193      argv1 = process.argv[1];194    });195    after(() => {196      process.argv[1] = argv1;197    });198    it('should not fail if process.argv[1] is undefined', () => {199      process.argv[1] = undefined;200      let args = getParser();201      args.prog.should.be.equal('Appium');202    });203    it('should set "prog" to process.argv[1]', () => {204      process.argv[1] = 'Hello World';205      let args = getParser();206      args.prog.should.be.equal('Hello World');207    });208  });209  describe('validateServerArgs', () => {210    let parser = getParser();211    parser.debug = true; // throw instead of exit on error; pass as option instead?212    const defaultArgs = {};213    // give all the defaults214    for (let rawArg of parser.rawArgs) {215      defaultArgs[rawArg[1].dest] = rawArg[1].defaultValue;216    }217    let args = {};218    beforeEach(() => {219      args = _.clone(defaultArgs);220    });221    describe('mutually exclusive server arguments', () => {222      describe('noReset and fullReset', () => {223        it('should not allow both', () => {224          (() => {225            args.noReset = args.fullReset = true;226            validateServerArgs(parser, args);227          }).should.throw();228        });229        it('should allow noReset', () => {230          (() => {231            args.noReset = true;232            validateServerArgs(parser, args);233          }).should.not.throw();234        });235        it('should allow fullReset', () => {236          (() => {237            args.fullReset = true;238            validateServerArgs(parser, args);239          }).should.not.throw();240        });241      });242      describe('ipa and safari', () => {243        it('should not allow both', () => {244          (() => {245            args.ipa = args.safari = true;246            validateServerArgs(parser, args);247          }).should.throw();248        });249        it('should allow ipa', () => {250          (() => {251            args.ipa = true;252            validateServerArgs(parser, args);253          }).should.not.throw();254        });255        it('should allow safari', () => {256          (() => {257            args.safari = true;258            validateServerArgs(parser, args);259          }).should.not.throw();260        });261      });262      describe('app and safari', () => {263        it('should not allow both', () => {264          (() => {265            args.app = args.safari = true;266            validateServerArgs(parser, args);267          }).should.throw();268        });269        it('should allow app', () => {270          (() => {271            args.app = true;272            validateServerArgs(parser, args);273          }).should.not.throw();274        });275      });276      describe('forceIphone and forceIpad', () => {277        it('should not allow both', () => {278          (() => {279            args.forceIphone = args.forceIpad = true;280            validateServerArgs(parser, args);281          }).should.throw();282        });283        it('should allow forceIphone', () => {284          (() => {285            args.forceIphone = true;286            validateServerArgs(parser, args);287          }).should.not.throw();288        });289        it('should allow forceIpad', () => {290          (() => {291            args.forceIpad = true;292            validateServerArgs(parser, args);293          }).should.not.throw();294        });295      });296      describe('deviceName and defaultDevice', () => {297        it('should not allow both', () => {298          (() => {299            args.deviceName = args.defaultDevice = true;300            validateServerArgs(parser, args);301          }).should.throw();302        });303        it('should allow deviceName', () => {304          (() => {305            args.deviceName = true;306            validateServerArgs(parser, args);307          }).should.not.throw();308        });309        it('should allow defaultDevice', () => {310          (() => {311            args.defaultDevice = true;312            validateServerArgs(parser, args);313          }).should.not.throw();314        });315      });316    });317    describe('validated arguments', () => {318      // checking ports is already done.319      // the only argument left is `backendRetries`320      describe('backendRetries', () => {321        it('should fail with value less than 0', () => {322          args.backendRetries = -1;323          (() => {validateServerArgs(parser, args);}).should.throw();324        });325        it('should succeed with value of 0', () => {326          args.backendRetries = 0;327          (() => {validateServerArgs(parser, args);}).should.not.throw();328        });329        it('should succeed with value above 0', () => {330          args.backendRetries = 100;331          (() => {validateServerArgs(parser, args);}).should.not.throw();332        });333      });334    });335  });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium-js').AppiumDriver;2var driver = new AppiumDriver();3driver.checkNodeOk(function(err, res) {4  if (err) {5    console.log(err);6  } else {7    console.log(res);8  }9});10   Licensed under the Apache License, Version 2.0 (the "License");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var driver = wd.remote("ondemand.saucelabs.com", 80, "SAUCE_USERNAME", "SAUCE_ACCESS_KEY");6driver.init(desired, function() {7    driver.title(function(err, title) {8      assert.ok(~title.indexOf('Google'));9      driver.quit();10    });11  });12});13desiredCapabilities: {14}15desiredCapabilities: {16}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumDriver } = require('@appium/base-driver');2const { AndroidDriver } = require('appium-android-driver');3const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');4const { AndroidUiautomator2Server } = require('appium-uiautomator2-server');5const { AndroidBootstrap } = require('appium-android-bootstrap');6const { AndroidEmulator } = require('appium-android-emulator');7const adb = new ADB();8const bootstrap = new AndroidBootstrap();9const uiautomator2Server = new AndroidUiautomator2Server();10const emulator = new AndroidEmulator();11const driver = new AndroidUiautomator2Driver();12const appiumDriver = new AppiumDriver();13(async () => {14  try {15    await adb.getApiLevel();16    await adb.getEmulatorPort();17    await adb.getConnectedDevices();18    await adb.getRunningAVD();19    await adb.getRunningAVDWithRetry();20    await adb.forwardPort(8200, 8200);21    await adb.killAllEmulators();22    await adb.killEmulator();23    await adb.launchAVD(avdName, avdArgs, language, locale, avdLaunchTimeout);24    await adb.launchAVDWithRetry(avdName, avdArgs, language, locale, avdLaunchTimeout);25    await adb.isDeviceConnected();26    await adb.isEmulatorConnected();27    await adb.isEmulatorRunning();28    await adb.isLockScreenEnabled();29    await adb.isScreenLocked();30    await adb.isSoftKeyboardPresent();31    await adb.portForwardingRemoveAll();32    await adb.reboot();33    await adb.root();34    await adb.screenOn();35    await adb.sendTelnetCommand();36    await adb.setDeviceId();37    await adb.setEmulatorPort();38    await adb.setIME();39    await adb.startLogcat();40    await adb.stopLogcat();41    await adb.unlock();42    await adb.uninstallApk(apk);43    await adb.waitForDevice();44    await adb.waitForEmulator();45    await adb.waitForEmulatorConnected(60000);46    await adb.waitForEmulatorReady(60000);47    await adb.waitForDeviceAvailable();48    await adb.waitForDeviceNotAvailable();49    await adb.waitForNotBusy(60000);50    await adb.waitForNotPresent();

Full Screen

Using AI Code Generation

copy

Full Screen

1const AppiumServer = require('./appiumserver');2const appiumServer = new AppiumServer();3appiumServer.checkNodeOk().then((result) => {4    console.log(result);5}).catch((err) => {6    console.log(err);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var appium = require('wd').promiseChainRemote('localhost', 4723);4  .init({5  })6  .then(function() {7    return appium.setImplicitWaitTimeout(5000);8  })9  .then(function() {10  })11  .then(function(el) {12    return el.click();13  })14  .then(function() {15  })16  .then(function(el) {17    return el.click();18  })19  .then(function() {20  })21  .then(function(el) {22    return el.click();23  })24  .fin(function() { return appium.quit(); })25  .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require("wd");2var driver = wd.promiseChainRemote("localhost", 4723);3driver.init({browserName:'chrome', app:'safari'});4driver.checkNodeOk();5driver.quit();6var wd = require("wd");7var driver = wd.promiseChainRemote("localhost", 4723);8driver.init({browserName:'chrome', app:'safari'});9driver.checkAppPresent("com.apple.mobilesafari");10driver.quit();11var wd = require("wd");12var driver = wd.promiseChainRemote("localhost", 4723);13driver.init({browserName:'chrome', app:'safari'});14driver.checkAppNotPresent("com.apple.mobilesafari");15driver.quit();16var wd = require("wd");17var driver = wd.promiseChainRemote("localhost", 4723);18driver.init({browserName:'chrome', app:'safari'});19driver.checkAlertPresent();20driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { AppiumDriver } from '../AppiumDriver';2import { checkNodeOk } from '../AppiumDriver';3const driver = new AppiumDriver();4(async () => {5  await driver.checkNodeOk();6})();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var driver = wd.remote("localhost", 4723);4driver.init({browserName:'chrome'}, function() {5    driver.checkNodeOk(function(err, data) {6        console.log(data);7    });8});

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