How to use helpers.unlock method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

android-helper-specs.js

Source:android-helper-specs.js Github

copy

Full Screen

...634        .returns(false);635      mocks.adb.expects('getApiLevel').never();636      mocks.adb.expects('startApp').never();637      mocks.adb.expects('isLockManagementSupported').never();638      await helpers.unlock(helpers, adb, {});639      mocks.adb.verify();640    });641    it('should start unlock app', async function () {642      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);643      mocks.adb.expects('shell').once().returns('');644      mocks.adb.expects('isLockManagementSupported').never();645      await helpers.unlock(helpers, adb, {});646      mocks.adb.verify();647      mocks.helpers.verify();648    });649    it('should raise an error on undefined unlockKey when unlockType is defined', async function () {650      mocks.adb.expects('isScreenLocked').once().returns(true);651      mocks.adb.expects('isLockManagementSupported').never();652      await helpers.unlock(helpers, adb, {unlockType: 'pin'}).should.be.rejected;653      mocks.adb.verify();654      mocks.unlocker.verify();655      mocks.helpers.verify();656    });657    it('should call pinUnlock if unlockType is pin', async function () {658      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);659      mocks.adb.expects('isScreenLocked').returns(false);660      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(false);661      mocks.unlocker.expects('pinUnlock').once();662      await helpers.unlock(helpers, adb, {unlockType: 'pin', unlockKey: '1111'});663      mocks.adb.verify();664      mocks.helpers.verify();665      mocks.unlocker.verify();666    });667    it('should call pinUnlock if unlockType is pinWithKeyEvent', async function () {668      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);669      mocks.adb.expects('isScreenLocked').returns(false);670      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(false);671      mocks.unlocker.expects('pinUnlockWithKeyEvent').once();672      await helpers.unlock(helpers, adb, {unlockType: 'pinWithKeyEvent', unlockKey: '1111'});673      mocks.adb.verify();674      mocks.helpers.verify();675      mocks.unlocker.verify();676    });677    it('should call fastUnlock if unlockKey is provided', async function () {678      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);679      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(true);680      mocks.helpers.expects('verifyUnlock').once();681      mocks.unlocker.expects('fastUnlock').once();682      await helpers.unlock(helpers, adb, {unlockKey: 'appium', unlockType: 'password'});683      mocks.adb.verify();684      mocks.unlocker.verify();685      mocks.helpers.verify();686    });687    it('should call passwordUnlock if unlockType is password', async function () {688      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);689      mocks.adb.expects('isScreenLocked').returns(false);690      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(false);691      mocks.unlocker.expects('passwordUnlock').once();692      await helpers.unlock(helpers, adb, {unlockType: 'password', unlockKey: 'appium'});693      mocks.adb.verify();694      mocks.helpers.verify();695      mocks.unlocker.verify();696    });697    it('should call patternUnlock if unlockType is pattern', async function () {698      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);699      mocks.adb.expects('isScreenLocked').returns(false);700      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(false);701      mocks.unlocker.expects('patternUnlock').once();702      await helpers.unlock(helpers, adb, {unlockType: 'pattern', unlockKey: '123456789'});703      mocks.adb.verify();704      mocks.helpers.verify();705    });706    it('should call fingerprintUnlock if unlockType is fingerprint', async function () {707      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);708      mocks.adb.expects('isScreenLocked').returns(false);709      mocks.adb.expects('isLockManagementSupported').never();710      mocks.unlocker.expects('fingerprintUnlock').once();711      await helpers.unlock(helpers, adb, {unlockType: 'fingerprint', unlockKey: '1111'});712      mocks.adb.verify();713      mocks.unlocker.verify();714    });715    it('should throw an error is api is lower than 23 and trying to use fingerprintUnlock', async function () {716      mocks.adb.expects('isScreenLocked').onCall(0).returns(true);717      mocks.adb.expects('isScreenLocked').returns(false);718      mocks.adb.expects('isLockManagementSupported').onCall(0).returns(false);719      mocks.adb.expects('getApiLevel').once().returns(21);720      await helpers.unlock(helpers, adb, {unlockType: 'fingerprint', unlockKey: '1111'}).should.eventually721        .be.rejectedWith('Fingerprint');722      mocks.helpers.verify();723    });724  }));725  describe('initDevice', withMocks({helpers, adb}, (mocks) => {726    it('should init device', async function () {727      const opts = {language: 'en', locale: 'us', localeScript: 'Script'};728      mocks.adb.expects('waitForDevice').once();729      mocks.adb.expects('startLogcat').once();730      mocks.helpers.expects('pushSettingsApp').once();731      mocks.helpers.expects('ensureDeviceLocale').withExactArgs(adb, opts.language, opts.locale, opts.localeScript).once();732      mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once();733      await helpers.initDevice(adb, opts);734      mocks.helpers.verify();...

Full Screen

Full Screen

browserElementTestHelpers.js

Source:browserElementTestHelpers.js Github

copy

Full Screen

1/* Any copyright is dedicated to the public domain.2   http://creativecommons.org/publicdomain/zero/1.0/ */3// Helpers for managing the browser frame preferences.4"use strict";5function _getPath() {6  return window.location.pathname7               .substring(0, window.location.pathname.lastIndexOf('/'))8               .replace("/priority", "");9}10const browserElementTestHelpers = {11  _getBoolPref: function(pref) {12    try {13      return SpecialPowers.getBoolPref(pref);14    }15    catch (e) {16      return undefined;17    }18  },19  _setPref: function(pref, value) {20    this.lockTestReady();21    if (value !== undefined && value !== null) {22      SpecialPowers.pushPrefEnv({'set': [[pref, value]]}, this.unlockTestReady.bind(this));23    } else {24      SpecialPowers.pushPrefEnv({'clear': [[pref]]}, this.unlockTestReady.bind(this));25    }26  },27  _testReadyLockCount: 0,28  _firedTestReady: false,29  lockTestReady: function() {30    this._testReadyLockCount++;31  },32  unlockTestReady: function() {33    this._testReadyLockCount--;34    if (this._testReadyLockCount == 0 && !this._firedTestReady) {35      this._firedTestReady = true;36      dispatchEvent(new Event("testready"));37    }38  },39  enableProcessPriorityManager: function() {40    this._setPref('dom.ipc.processPriorityManager.testMode', true);41    this._setPref('dom.ipc.processPriorityManager.enabled', true);42  },43  setEnabledPref: function(value) {44    this._setPref('dom.mozBrowserFramesEnabled', value);45  },46  getOOPByDefaultPref: function() {47    return this._getBoolPref("dom.ipc.browser_frames.oop_by_default");48  },49  addPermission: function() {50    SpecialPowers.addPermission("browser", true, document);51    this.tempPermissions.push(location.href)52  },53  removeAllTempPermissions: function() {54    for(var i = 0; i < this.tempPermissions.length; i++) {55      SpecialPowers.removePermission("browser", this.tempPermissions[i]);56    }57  },58  addPermissionForUrl: function(url) {59    SpecialPowers.addPermission("browser", true, url);60    this.tempPermissions.push(url);61  },62  'tempPermissions': [],63  // Some basically-empty pages from different domains you can load.64  'emptyPage1': 'http://example.com' + _getPath() + '/file_empty.html',65  'emptyPage2': 'http://example.org' + _getPath() + '/file_empty.html',66  'emptyPage3': 'http://test1.example.org' + _getPath() + '/file_empty.html',67  'focusPage': 'http://example.org' + _getPath() + '/file_focus.html',68};69// Set some prefs:70//71//  * browser.pageThumbs.enabled: false72//73//    Disable tab view; it seriously messes us up.74//75//  * dom.ipc.browser_frames.oop_by_default76//77//    Enable or disable OOP-by-default depending on the test's filename.  You78//    can still force OOP on or off with <iframe mozbrowser remote=true/false>,79//    at least until bug 756376 lands.80//81//  * dom.ipc.tabs.disabled: false82//83//    Allow us to create OOP frames.  Even if they're not the default, some84//    "in-process" tests create OOP frames.85//86//  * network.disable.ipc.security: true87//88//    Disable the networking security checks; our test harness just tests89//    browser elements without sticking them in apps, and the security checks90//    dislike that.91//92//    Unfortunately setting network.disable.ipc.security to false before the93//    child process(es) created by this test have shut down can cause us to94//    assert and kill the child process.  That doesn't cause the tests to fail,95//    but it's still scary looking.  So we just set the pref to true and never96//    pop that value.  We'll rely on the tests which test IPC security to set97//    it to false.98(function() {99  var oop = location.pathname.indexOf('_inproc_') == -1;100  browserElementTestHelpers.lockTestReady();101  SpecialPowers.setBoolPref("network.disable.ipc.security", true);102  SpecialPowers.pushPrefEnv({set: [["browser.pageThumbs.enabled", false],103                                   ["dom.ipc.browser_frames.oop_by_default", oop],104                                   ["dom.ipc.tabs.disabled", false]]},105                            browserElementTestHelpers.unlockTestReady.bind(browserElementTestHelpers));106})();107addEventListener('unload', function() {108  browserElementTestHelpers.removeAllTempPermissions();109});110// Wait for the load event before unlocking the test-ready event.111browserElementTestHelpers.lockTestReady();112addEventListener('load', function() {113  SimpleTest.executeSoon(browserElementTestHelpers.unlockTestReady.bind(browserElementTestHelpers));...

Full Screen

Full Screen

register-currency.js

Source:register-currency.js Github

copy

Full Screen

1/*!2 * Hubii Nahmii3 *4 * Copyright (C) 2017-2019 Hubii AS5 */6const TransferControllerManager = artifacts.require('TransferControllerManager');7const helpers = require('../common/helpers.js');8module.exports = async (callback) => {9    const network = helpers.parseNetworkArg();10    const deployerAccount = helpers.parseDeployerArg();11    const contractAddress = helpers.parseAddressArg('contract');12    const standard = helpers.parseStringArg('standard');13    if (!helpers.isTestNetwork(network))14        helpers.unlockAddress(web3, deployerAccount, helpers.parsePasswordArg(), 14400);15    try {16        const instance = await TransferControllerManager.deployed();17        if ('0x' != await instance.transferController(contractAddress, ''))18            console.log(`Contract ${contractAddress} is already registered`);19        else {20            await instance.registerCurrency(contractAddress, standard);21            if ('0x' != await instance.transferController(contractAddress, ''))22                console.log(`Contract ${contractAddress} successfully registered as standard ${standard}`);23            else24                console.log(`Unable to register ${contractAddress} as standard ${standard}`);25        }26        callback();27    } catch (err) {28        callback(err);29    } finally {30        if (!helpers.isTestNetwork(network))31            helpers.lockAddress(web3, deployerAccount);32    }...

Full Screen

Full Screen

transfer-nahmii-tokens.js

Source:transfer-nahmii-tokens.js Github

copy

Full Screen

1/*!2 * Hubii Nahmii3 *4 * Copyright (C) 2017-2019 Hubii AS5 */6const NahmiiToken = artifacts.require('NahmiiToken');7const helpers = require('../common/helpers.js');8// -----------------------------------------------------------------------------------------------------------------9module.exports = async (callback) => {10    let deployerAccount;11    const testNetwork = false;12    deployerAccount = helpers.parseDeployerArg();13    if (!testNetwork)14        helpers.unlockAddress(web3, deployerAccount, helpers.parsePasswordArg(), 14400);15    try {16        const instance = await NahmiiToken.at('0x65905e653b750bCB8f903374Bc93cbd8E2E71B71');17        await instance.addMinter('0x630FAEe42B6D418C909958C9590235F082c88136');18        await instance.transfer('0x630FAEe42B6D418C909958C9590235F082c88136', new web3.BigNumber('120e24'));19        console.log(`Balance of token holder: ${(await instance.balanceOf('0x630FAEe42B6D418C909958C9590235F082c88136')).toString()}`);20    }21    catch (err) {22        if (!testNetwork)23            helpers.lockAddress(web3, deployerAccount);24        callback();25        throw err;26    }27    if (!testNetwork)28        helpers.lockAddress(web3, deployerAccount);...

Full Screen

Full Screen

add-signer.js

Source:add-signer.js Github

copy

Full Screen

1/*!2 * Hubii Nahmii3 *4 * Copyright (C) 2017-2019 Hubii AS5 */6const SignerManager = artifacts.require('SignerManager');7const helpers = require('../common/helpers.js');8module.exports = async (callback) => {9    const network = helpers.parseNetworkArg();10    const deployerAccount = helpers.parseDeployerArg();11    const signerAccount = helpers.parseAddressArg('signer');12    if (!helpers.isTestNetwork(network))13        helpers.unlockAddress(web3, deployerAccount, helpers.parsePasswordArg(), 14400);14    try {15        const instance = await SignerManager.deployed();16        if (await instance.isSigner(signerAccount))17            console.log(`Signer ${signerAccount} is already registered with SignerManager at ${SignerManager.address}`);18        else {19            await instance.registerSigner(signerAccount);20            if (await instance.isSigner(signerAccount))21                console.log(`Signer ${signerAccount} registered with SignerManager at ${SignerManager.address}`);22        }23        callback();24    } catch (err) {25        callback(err);26    } finally {27        if (!helpers.isTestNetwork(network))28            helpers.lockAddress(web3, deployerAccount);29    }...

Full Screen

Full Screen

UnlockAccountMethodTest.js

Source:UnlockAccountMethodTest.js Github

copy

Full Screen

1import {formatters} from 'susyweb-core-helpers';2import UnlockAccountMethod from '../../../../src/methods/personal/UnlockAccountMethod';3import AbstractMethod from '../../../../lib/methods/AbstractMethod';4// Mocks5jest.mock('susyweb-core-helpers');6/**7 * UnlockAccountMethod test8 */9describe('UnlockAccountMethodTest', () => {10    let method;11    beforeEach(() => {12        method = new UnlockAccountMethod(null, formatters, {});13    });14    it('constructor check', () => {15        expect(method).toBeInstanceOf(AbstractMethod);16        expect(method.rpcMethod).toEqual('personal_unlockAccount');17        expect(method.parametersAmount).toEqual(3);18        expect(method.utils).toEqual(null);19        expect(method.formatters).toEqual(formatters);20    });21    it('beforeExecution should call inputSignFormatter and inputAddressFormatter', () => {22        method.parameters = ['0x0'];23        formatters.inputAddressFormatter.mockReturnValueOnce('0x00');24        method.beforeExecution();25        expect(formatters.inputAddressFormatter).toHaveBeenCalledWith('0x0');26        expect(method.parameters[0]).toEqual('0x00');27    });...

Full Screen

Full Screen

deploy-testerc20.js

Source:deploy-testerc20.js Github

copy

Full Screen

1/*!2 * Hubii Nahmii3 *4 * Copyright (C) 2017-2019 Hubii AS5 */6const TestERC20 = artifacts.require('TestERC20');7const helpers = require('../common/helpers.js');8const debug = require('debug')('deploy_testerc20');9// A script for the deployment of the TestERC20 contract.10//11// This script may be run as follows:12//13//    DEBUG=deploy_testerc20 npm run exec:deploy_testerc20 -- --network ganache --deployer 0xc31Eb6E317054A79bb5E442D686CB9b225670c1D14module.exports = async (callback) => {15    const network = helpers.parseNetworkArg();16    const deployerAccount = helpers.parseDeployerArg();17    if (!helpers.isTestNetwork(network))18        helpers.unlockAddress(web3, deployerAccount, helpers.parsePasswordArg(), 14400);19    try {20        const instance = await TestERC20.new({from: deployerAccount});21        debug(`Deployed TestERC20 at ${await instance.address}`);22        callback();23    } catch (err) {24        callback(err);25    } finally {26        if (!helpers.isTestNetwork(network))27            helpers.lockAddress(web3, deployerAccount);28    }...

Full Screen

Full Screen

msg_fragebogen.js

Source:msg_fragebogen.js Github

copy

Full Screen

1Template.msgFragebogen.helpers({2	unlockEnd() {3		let unixTime = Session.get(UNLOCK_END);4		return new Date(unixTime).getDate() + "." + new Date(unixTime).getMonth()5		+ ", " + new Date(unixTime).getHours() + ":" + new Date(unixTime).getMinutes() + " Uhr";6	}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var expect = chai.expect;7var should = chai.should();8var AndroidDriver = require('appium-android-driver');9var helpers = require('appium-android-driver/lib/helpers.js');10var server = require('appium-android-driver/lib/server.js');11var B = require('bluebird');12var _ = require('lodash');13var wd = require('wd');14var path = require('path');15var fs = require('fs');16var PORT = 4723;17var desired = {18};19var driver = wd.promiseChainRemote('localhost', PORT);20driver.init(desired).then(function () {21  return driver.unlock();22}).then(function () {23  console.log('unlocked');24}).fin(function () {25  return driver.quit();26}).done();27'use strict';28var _ = require('lodash');29var wd = require('wd');30var logger = require('./logger.js').get('appium');31var errors = require('./errors.js');32var helpers = {};33helpers.unlock = function (driver) {34  logger.debug("Unlocking screen");35    .isLocked()36    .then(function (isLocked) {37      if (isLocked) {38        logger.debug("Screen is locked, trying to unlock");39        return driver.unlock();40      }41    });42};43module.exports = helpers;44'use strict';45var _ = require('lodash');46var wd = require('wd');47var logger = require('./logger.js').get('appium');48var errors = require('./errors.js');49var helpers = require('./helpers.js');50var server = {};51server.start = function (opts) {52  var driver = wd.promiseChainRemote(opts.address, opts.port);

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var appium = require('appium');3var helpers = require('appium-android-driver').androidHelpers;4var driver = new webdriver.Builder()5    .forBrowser('chrome')6    .build();7helpers.unlock(driver, "1234");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var helpers = require('appium-android-driver').androidHelpers;4var desired = {5};6var driver = wd.promiseChainRemote('localhost', 4723);7  .init(desired)8  .then(function () {9    return helpers.unlock(driver);10  })11  .then(function () {12    return driver.sleep(3000);13  })14  .then(function () {15    return driver.quit();16  })17  .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var desiredCaps = {3};4var driver = wd.promiseChainRemote('localhost', 4723);5driver.init(desiredCaps).then(function () {6  return driver.unlock();7}).then(function () {8  return driver.sleep(10000);9}).then(function () {10  return driver.quit();11}).done();12var wd = require('wd');13var desiredCaps = {14};15var driver = wd.promiseChainRemote('localhost', 4723);16driver.init(desiredCaps).then(function () {17  return driver.unlock();18}).then(function () {19  return driver.sleep(10000);20}).then(function () {21  return driver.quit();22}).done();23var wd = require('wd');24var desiredCaps = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var AndroidDriver = require('appium-android-driver').AndroidDriver;4var androidDriver = new AndroidDriver();5var desired = {6};7var driver = wd.promiseChainRemote('localhost', 4723);8  .init(desired)9  .then(function () {10    return androidDriver.unlock();11  })12  .then(function () {13  })14  .fin(function () {15    return driver.quit();16  })17  .done();18[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}19[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}20[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"OK, shutting down","status":0}21[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"1"}}

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 Android Driver 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