How to use helpers.ensureDeviceLocale 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

...144 describe('ensureDeviceLocale', withMocks({adb}, (mocks) => {145 it('should call setDeviceLanguageCountry', async function () {146 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('en', 'US', null).once();147 mocks.adb.expects('ensureCurrentLocale').withExactArgs('en', 'US', null).once().returns(true);148 await helpers.ensureDeviceLocale(adb, 'en', 'US');149 mocks.adb.verify();150 });151 it('should call setDeviceLanguageCountry without script', async function () {152 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('en', 'US', null).once();153 mocks.adb.expects('ensureCurrentLocale').withExactArgs('en', 'US', null).once().returns(true);154 await helpers.ensureDeviceLocale(adb, 'en', 'US', undefined);155 mocks.adb.verify();156 });157 it('should call setDeviceLanguageCountry with script', async function () {158 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('zh', 'CN', 'Hans').once();159 mocks.adb.expects('ensureCurrentLocale').withExactArgs('zh', 'CN', 'Hans').once().returns(true);160 await helpers.ensureDeviceLocale(adb, 'zh', 'CN', 'Hans');161 mocks.adb.verify();162 });163 it('should never call setDeviceLanguageCountry', async function () {164 mocks.adb.expects('setDeviceLanguageCountry').never();165 mocks.adb.expects('getApiLevel').never();166 await helpers.ensureDeviceLocale(adb);167 mocks.adb.verify();168 });169 it('should call setDeviceLanguageCountry with throw', async function () {170 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('fr', 'FR', null).once();171 mocks.adb.expects('ensureCurrentLocale').withExactArgs('fr', 'FR', null).once().returns(false);172 await helpers.ensureDeviceLocale(adb, 'fr', 'FR').should.eventually.be.rejectedWith(Error, `Failed to set language: fr and country: FR`);173 mocks.adb.verify();174 });175 }));176 describe('getDeviceInfoFromCaps', function () {177 // list of device/emu udids to their os versions178 // using list instead of map to preserve order179 let devices = [180 {udid: 'emulator-1234', os: '4.9.2'},181 {udid: 'rotalume-1339', os: '5.1.5'},182 {udid: 'rotalume-1338', os: '5.0.1'},183 {udid: 'rotalume-1337', os: '5.0.1'},184 {udid: 'roamulet-9000', os: '6.0'},185 {udid: 'roamulet-0', os: '2.3'},186 {udid: 'roamulet-2019', os: '9'},...

Full Screen

Full Screen

ah1.js

Source:ah1.js Github

copy

Full Screen

...548 await helpers.pushSettingsApp(adb);549 if (!opts.avd) {550 await helpers.setMockLocationApp(adb, SETTINGS_HELPER_PKG_ID);551 }552 await helpers.ensureDeviceLocale(adb, opts.language, opts.locale);553 await adb.startLogcat();554 let defaultIME;555 if (opts.unicodeKeyboard) {556 defaultIME = await helpers.initUnicodeKeyboard(adb);557 }558 if (_.isUndefined(opts.unlockType)) {559 await helpers.pushUnlock(adb);560 }561 return defaultIME;562};563helpers.removeNullProperties = function (obj) {564 for (let key of _.keys(obj)) {565 if (_.isNull(obj[key]) || _.isUndefined(obj[key])) {566 delete obj[key];...

Full Screen

Full Screen

android-helpers.js

Source:android-helpers.js Github

copy

Full Screen

...499 // pushSettingsApp required before calling ensureDeviceLocale for API Level 24+500 // await helpers.pushSettingsApp(adb);501 await helpers.setMockLocationApp(adb, SETTINGS_HELPER_PKG_ID);502 }503 await helpers.ensureDeviceLocale(adb, opts.language, opts.locale);504 await adb.startLogcat();505 let defaultIME;506 if (opts.unicodeKeyboard) {507 defaultIME = await helpers.initUnicodeKeyboard(adb);508 }509 if (_.isUndefined(opts.unlockType)) {510 //await helpers.pushUnlock(adb);511 }512 return defaultIME;513};514helpers.removeNullProperties = function (obj) {515 for (let key of _.keys(obj)) {516 if (_.isNull(obj[key]) || _.isUndefined(obj[key])) {517 delete obj[key];...

Full Screen

Full Screen

android-helper-e2e-specs.js

Source:android-helper-e2e-specs.js Github

copy

Full Screen

...34 });35 });36 describe('ensureDeviceLocale @skip-ci', function () {37 after(async function () {38 await helpers.ensureDeviceLocale(adb, 'en', 'US');39 });40 it('should set device language and country', async function () {41 await helpers.ensureDeviceLocale(adb, 'fr', 'FR');42 if (await adb.getApiLevel() < 23) {43 await adb.getDeviceLanguage().should.eventually.equal('fr');44 await adb.getDeviceCountry().should.eventually.equal('FR');45 } else {46 await adb.getDeviceLocale().should.eventually.equal('fr-FR');47 }48 });49 it('should set device language and country with script', async function () {50 await helpers.ensureDeviceLocale(adb, 'zh', 'CN', 'Hans');51 if (await adb.getApiLevel() < 23) {52 await adb.getDeviceLanguage().should.eventually.equal('fr');53 await adb.getDeviceCountry().should.eventually.equal('FR');54 } else {55 await adb.getDeviceLocale().should.eventually.equal('fr-Hans-CN');56 }57 });58 });59 describe('pushSettingsApp', function () {60 const settingsPkg = 'io.appium.settings';61 it('should be able to upgrade from settings v1 to latest', async function () {62 await adb.uninstallApk(settingsPkg);63 // get and install old version of settings app64 await exec('npm', ['install', `${settingsPkg}@2.0.0`]);...

Full Screen

Full Screen

strings-e2e-specs.js

Source:strings-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { APIDEMOS_CAPS } from '../desired';4import ADB from 'appium-adb';5import { initSession, deleteSession } from '../helpers/session';6import { getLocale } from '../helpers/helpers';7import _ from 'lodash';8import { androidHelpers } from 'appium-android-driver';9chai.should();10chai.use(chaiAsPromised);11describe('strings', function () {12 let driver;13 describe('specific language', function () {14 before(async function () {15 // Don't run these tests on TestObject. On TO, we don't have access to the .apk16 // which is necessary for extracting the app strings17 if (process.env.TESTOBJECT_E2E_TESTS) {18 this.skip();19 }20 driver = await initSession(APIDEMOS_CAPS);21 });22 after(async function () {23 if (!process.env.TESTOBJECT_E2E_TESTS) {24 await deleteSession();25 }26 });27 it('should return app strings', async function () {28 let strings = await driver.getAppStrings('en');29 strings.hello_world.should.equal('Hello, World!');30 });31 it('should return app strings for different language', async function () {32 let strings = await driver.getAppStrings('fr');33 strings.hello_world.should.equal('Bonjour, Monde!');34 });35 });36 describe('device language', function () {37 let initialLocale;38 let adb;39 before(async function () {40 // Don't test ADB on test object41 if (process.env.TESTOBJECT_E2E_TESTS) {42 this.skip();43 }44 // restarting doesn't work on Android 7+45 adb = new ADB();46 initialLocale = await getLocale(adb);47 });48 afterEach(async function () {49 if (driver) {50 if (await adb.getApiLevel() > 23) {51 let [language, country] = initialLocale.split('-');52 await androidHelpers.ensureDeviceLocale(adb, language, country);53 } else {54 // This method is flakey in CI55 if (!process.env.CI) {56 await androidHelpers.ensureDeviceLocale(adb, null, initialLocale);57 }58 }59 await deleteSession();60 }61 });62 it('should return app strings with default locale/language', async function () {63 driver = await initSession(APIDEMOS_CAPS);64 let strings = await driver.getAppStrings();65 strings.hello_world.should.equal('Hello, World!');66 });67 it('should return app strings when language/locale set @skip-ci', async function () {68 if (process.env.TESTOBJECT_E2E_TESTS) {69 this.skip();70 }71 driver = await initSession(_.defaults({72 language: 'fr',73 locale: 'CA',74 }, APIDEMOS_CAPS));75 let strings = await driver.getAppStrings();76 strings.hello_world.should.equal('Bonjour, Monde!');77 });78 });...

Full Screen

Full Screen

language-e2e-specs.js

Source:language-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import ADB from 'appium-adb';4import { initSession, deleteSession } from '../helpers/session';5import { APIDEMOS_CAPS } from '../desired';6import { androidHelpers } from 'appium-android-driver';7import { getLocale } from '../helpers/helpers';8chai.should();9chai.use(chaiAsPromised);10// Skip ci since the command restart emulator when the test device's API is 22-.11describe('Localization - locale @skip-ci @skip-real-device', function () {12 let initialLocale;13 let adb;14 before(async function () {15 if (process.env.TESTOBJECT_E2E_TESTS) {16 this.skip();17 }18 // restarting doesn't work on Android 7+19 let adb = new ADB();20 if (await adb.getApiLevel() > 23) return this.skip(); //eslint-disable-line curly21 initialLocale = await getLocale(adb);22 });23 let driver;24 after(async function () {25 if (driver) {26 if (await adb.getApiLevel() > 23) {27 let [language, country] = initialLocale.split('-');28 await androidHelpers.ensureDeviceLocale(driver.adb, language, country);29 } else {30 await androidHelpers.ensureDeviceLocale(driver.adb, null, initialLocale);31 }32 await deleteSession();33 }34 });35 it('should start as FR', async function () {36 let frCaps = Object.assign({}, APIDEMOS_CAPS, {37 language: 'fr',38 locale: 'FR',39 });40 driver = await initSession(frCaps);41 await getLocale(driver.adb).should.eventually.equal('fr-FR');42 });43 it('should start as US', async function () {44 let usCaps = Object.assign({}, APIDEMOS_CAPS, {45 language: 'en',46 locale: 'US',47 });48 driver = await initSession(usCaps);49 await getLocale(driver.adb).should.eventually.equal('en-US');50 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var androidHelpers = require('appium-android-driver').androidHelpers;5var desired = {6};7var driver = wd.promiseChainRemote('localhost', 4723);8 .init(desired)9 .then(function () {10 return androidHelpers.ensureDeviceLocale(driver, 'en');11 })12 .then(function () {13 console.log('Locale set to en');14 })15 .fin(function () {16 return driver.quit();17 })18 .done();19Copyright (c) 2012-present, Appium Committers

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var helpers = require('appium-android-driver/build/lib/helpers');4describe('Android', function() {5 this.timeout(300000);6 var driver;7 before(function() {8 var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new AndroidDriver();2var desiredCaps = {3};4driver.createSession(desiredCaps).then(function () {5 return driver.ensureDeviceLocale("en_US");6}).then(function () {7 return driver.quit();8});9commands.ensureDeviceLocale = function (language, country) {10 var desired = this.opts.desiredCapabilities;11 if (language) {12 desired.language = language;13 }14 if (country) {15 desired.country = country;16 }17 return this.setDeviceLanguageCountry(desired.language, desired.country);18};19commands.setDeviceLanguageCountry = function (language, country) {20 var cmd, args;21 if (this.isEmulator()) {22 logger.debug("Setting Android Device Language to " + language);23 cmd = "setprop";24 args = ['persist.sys.language', language];25 return this.adb.shell(args).then(function () {26 if (country) {27 logger.debug("Setting Android Device Country to " + country);28 args = ['persist.sys.country', country];29 return this.adb.shell(args);30 }31 }.bind(this)).then(function () {32 logger.debug("Rebooting device");33 return this.adb.reboot();34 }.bind(this)).then(function () {35 logger.debug("Waiting for device to come online");36 return this.adb.waitForDevice();37 }.bind(this));38 } else {39 logger.debug("Setting Android Device Language to " + language);40 cmd = "am";41 'io.appium.settings/.ChangeLocaleService'];42 return this.adb.shell(args);43 }44};

Full Screen

Using AI Code Generation

copy

Full Screen

1const helpers = require('appium-android-driver/lib/android-helpers');2const desiredCaps = {3};4helpers.ensureDeviceLocale(desiredCaps);5const helpers = require('appium-android-driver/lib/android-helpers');6const desiredCaps = {7};8helpers.ensureDeviceLocale(desiredCaps);9const helpers = require('appium-android-driver/lib/android-helpers');10const desiredCaps = {11};12helpers.ensureDeviceLocale(desiredCaps);13const helpers = require('appium-android-driver/lib/android-helpers');14const desiredCaps = {15};16helpers.ensureDeviceLocale(desiredCaps);17const helpers = require('appium-android-driver/lib/android-helpers');18const desiredCaps = {19};20helpers.ensureDeviceLocale(desiredCaps);21const helpers = require('appium-android-driver/lib/android-helpers');22const desiredCaps = {23};24helpers.ensureDeviceLocale(desiredCaps);25const helpers = require('appium-android-driver/lib/android-helpers');26const desiredCaps = {27};28helpers.ensureDeviceLocale(desiredCaps);29const helpers = require('appium-android-driver/lib/android-helpers');30const desiredCaps = {31};32helpers.ensureDeviceLocale(desiredCaps);33const helpers = require('appium-android-driver/lib

Full Screen

Using AI Code Generation

copy

Full Screen

1var AndroidDriver = require('appium-android-driver');2var helpers = AndroidDriver.helpers;3var language = 'en';4var country = 'US';5var locale = language + '-' + country;6helpers.ensureDeviceLocale(language, country, locale, function(err, locale) {7 if (err) {8 console.log('Error setting the device locale');9 } else {10 console.log('Device locale set to ' + locale);11 }12});13var language = 'fr';14var country = 'FR';15var locale = language + '-' + country;16helpers.ensureDeviceLocale(language, country, locale, function(err, locale) {17 if (err) {18 console.log('Error setting the device locale');19 } else {20 console.log('Device locale set to ' + locale);21 }22});23var language = 'de';24var country = 'DE';25var locale = language + '-' + country;26helpers.ensureDeviceLocale(language, country, locale, function(err, locale) {27 if (err) {28 console.log('Error setting the device locale');29 } else {30 console.log('Device locale set to ' + locale);31 }32});33var language = 'es';34var country = 'ES';35var locale = language + '-' + country;36helpers.ensureDeviceLocale(language, country, locale, function(err, locale)

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