How to use adb.setDeviceLanguageCountry method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

apk-utils-specs.js

Source:apk-utils-specs.js Github

copy

Full Screen

...657      mocks.adb.expects('getDeviceCountry').never();658      mocks.adb.expects('getDeviceLocale').never();659      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();660      mocks.adb.expects('reboot').never();661      await adb.setDeviceLanguageCountry();662    });663    it('should return if language or country are not passed', async function () {664      mocks.adb.expects('getDeviceLanguage').never();665      mocks.adb.expects('getDeviceCountry').never();666      mocks.adb.expects('getDeviceLocale').never();667      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();668      mocks.adb.expects('reboot').never();669      await adb.setDeviceLanguageCountry('us');670    });671    it('should set language, country and reboot the device when API < 23', async function () {672      mocks.adb.expects('getApiLevel').withExactArgs()673        .once().returns(22);674      mocks.adb.expects('getDeviceLanguage').withExactArgs()675        .once().returns('fr');676      mocks.adb.expects('getDeviceCountry').withExactArgs()677        .once().returns('');678      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').withExactArgs(language, country)679        .once().returns('');680      mocks.adb.expects('reboot').never();681      await adb.setDeviceLanguageCountry(language, country);682    });683    it('should not set language and country if it does not change when API < 23', async function () {684      mocks.adb.expects('getApiLevel').withExactArgs()685          .once().returns(22);686      mocks.adb.expects('getDeviceLanguage').once().returns('en');687      mocks.adb.expects('getDeviceCountry').once().returns('US');688      mocks.adb.expects('getDeviceLocale').never();689      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();690      mocks.adb.expects('reboot').never();691      await adb.setDeviceLanguageCountry(language.toLowerCase(), country.toLowerCase());692    });693    it('should call set locale via setting app when API 23+', async function () {694      mocks.adb.expects('getApiLevel').withExactArgs()695          .once().returns(23);696      mocks.adb.expects('getDeviceLocale').withExactArgs()697          .once().returns('fr-FR');698      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').withExactArgs(language, country, null)699          .once().returns('');700      mocks.adb.expects('reboot').never();701      await adb.setDeviceLanguageCountry(language, country);702    });703    it('should call set locale with script via setting app when API 24+', async function () {704      mocks.adb.expects('getApiLevel').withExactArgs()705          .once().returns(24);706      mocks.adb.expects('getDeviceLocale').withExactArgs()707          .once().returns('fr-FR');708      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').withExactArgs('zh', 'CN', 'Hans')709          .once().returns('');710      mocks.adb.expects('reboot').never();711      await adb.setDeviceLanguageCountry('zh', 'CN', 'Hans');712    });713    it('should not set language and country if it does not change when API 24+', async function () {714      mocks.adb.expects('getApiLevel').withExactArgs()715          .once().returns(24);716      mocks.adb.expects('getDeviceLocale').withExactArgs()717          .once().returns(locale);718      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();719      mocks.adb.expects('reboot').never();720      await adb.setDeviceLanguageCountry(language, country);721    });722    it('should not set language and country if no language when API 24+', async function () {723      mocks.adb.expects('getApiLevel').withExactArgs()724          .once().returns(24);725      mocks.adb.expects('getDeviceLocale').withExactArgs()726          .once().returns(locale);727      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();728      mocks.adb.expects('reboot').never();729      await adb.setDeviceLanguageCountry(country);730    });731    it('should not set language and country if no country when API 24+', async function () {732      mocks.adb.expects('getApiLevel').withExactArgs()733          .once().returns(24);734      mocks.adb.expects('getDeviceLocale').withExactArgs()735          .once().returns(locale);736      mocks.adb.expects('setDeviceSysLocaleViaSettingApp').never();737      mocks.adb.expects('reboot').never();738      await adb.setDeviceLanguageCountry(language);739    });740  });741  describe('getPackageInfo', function () {742    it('should properly parse installed package info', async function () {743      mocks.adb.expects('shell').once().returns(`Packages:744      Package [com.example.testapp.first] (2036fd1):745        userId=10225746        pkg=Package{42e7a36 com.example.testapp.first}747        codePath=/data/app/com.example.testapp.first-1748        resourcePath=/data/app/com.example.testapp.first-1749        legacyNativeLibraryDir=/data/app/com.example.testapp.first-1/lib750        primaryCpuAbi=null751        secondaryCpuAbi=null752        versionCode=1 minSdk=21 targetSdk=24...

Full Screen

Full Screen

ah1.js

Source:ah1.js Github

copy

Full Screen

...133    logger.warn(`setDeviceLanguageCountry requires language or country.`);134    logger.warn(`Got language: '${language}' and country: '${country}'`);135    return;136  }137  await adb.setDeviceLanguageCountry(language, country);138  if (!await adb.ensureCurrentLocale(language, country)) {139    throw new Error(`Failed to set language: ${language} and country: ${country}`);140  }141};142helpers.getDeviceInfoFromCaps = async function (opts = {}) {143  // we can create a throwaway ADB instance here, so there is no dependency144  // on instantiating on earlier (at this point, we have no udid)145  // we can only use this ADB object for commands that would not be confused146  // if multiple devices are connected147  const adb = await helpers.createBaseADB(opts);148  let udid = opts.udid;149  let emPort = null;150  // a specific avd name was given. try to initialize with that151  if (opts.avd) {...

Full Screen

Full Screen

android-helpers.js

Source:android-helpers.js Github

copy

Full Screen

...110    logger.warn(`setDeviceLanguageCountry requires language or country.`);111    logger.warn(`Got language: '${language}' and country: '${country}'`);112    return;113  }114  await adb.setDeviceLanguageCountry(language, country);115  if (!await adb.ensureCurrentLocale(language, country)) {116    throw new Error(`Failed to set language: ${language} and country: ${country}`);117  }118};119helpers.getDeviceInfoFromCaps = async function (opts = {}) {120  // we can create a throwaway ADB instance here, so there is no dependency121  // on instantiating on earlier (at this point, we have no udid)122  // we can only use this ADB object for commands that would not be confused123  // if multiple devices are connected124  let adb = await ADB.createADB({125    javaVersion: opts.javaVersion,126    adbPort: opts.adbPort,127    remoteAdbHost: opts.remoteAdbHost,128    suppressKillServer: opts.suppressKillServer,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb');2adb.setDeviceLanguageCountry('en', 'US', 'emulator-5554', function (err) {3  if (err) {4    console.log('Error setting language/country');5  } else {6    console.log('Language/Country set successfully');7  }8});9var adb = require('appium-adb');10adb.setDeviceLanguageCountry('en', 'US', 'emulator-5554')11  .then(function () {12    console.log('Language/Country set successfully');13  })14  .catch(function (err) {15    console.log('Error setting language/country');16  });

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var desiredCaps = {3};4driver.init(desiredCaps).then(function() {5    return driver.setDeviceLanguageCountry("en", "IN");6});7driver.quit();8[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"platformName":"Android","platformVersion":"6.0","deviceName":"Android Emulator","app":"C:/Users/username/Desktop/app-debug.apk","automationName":"Appium"}}9[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"6.0","deviceName":"Android Emulator","app":"C:/Users/username/Desktop/app-debug.apk","automationName":"Appium"},null,null]10[debug] [BaseDriver] Event 'newSessionRequested' logged at 1494230039203 (07:13:59 GMT+0530 (India Standard Time))11[Appium] Creating new AndroidDriver (v1.23.0) session12[debug] [BaseDriver] Creating session with MJSONWP desired capabilities: {"platformName":"Android","platformVersion":"6.0","deviceName":"Android Emulator","app":"C:/Users/username/Desktop/app-debug.apk","automationName":"Appium"}

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-android-driver').ADB;2var adbObj = new adb();3var language = 'en';4var country = 'US';5adbObj.setDeviceLanguageCountry(language, country)6  .then(function () {7    console.log('Language set to ' + language + ' and country set to ' + country);8  })9  .catch(function (err) {10    console.log('Error setting language and country');11    console.log(err);12  });

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb').adb;2var language = 'en';3var country = 'US';4adb.setDeviceLanguageCountry(language, country, function(err, res) {5    if (err) {6        console.log("Error occured: " + err);7    } else {8        console.log("Success: " + res);9    }10});11adb.setDeviceLocale(language, country, function(err, res) {12    if (err) {13        console.log("Error occured: " + err);14    } else {15        console.log("Success: " + res);16    }17});18adb.setDeviceTimezone(timezone, function(err, res) {19    if (err) {20        console.log("Error occured: " + err);21    } else {22        console.log("Success: " + res);23    }24});25adb.setDeviceOrientation(orientation, function(err, res) {26    if (err) {27        console.log("Error occured: " + err);28    } else {29        console.log("Success: " + res);30    }31});32adb.getDeviceOrientation(function(err, res) {33    if (err) {34        console.log("Error occured: " + err);35    } else {36        console.log("Success: " + res);37    }38});39adb.getDeviceLocation(function(err, res) {40    if (err) {41        console.log("Error occured: " + err);42    } else {43        console.log("Success: " + res);44    }45});46adb.setDeviceLocation(latitude, longitude, altitude, function(err, res) {47    if (err) {48        console.log("Error occured: " + err);49    } else {50        console.log("Success: " + res);51    }52});53adb.getDeviceSysTemPort(function(err, res) {54    if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb').ADB.createADB();2var language = 'en';3var country = 'US';4adb.setDeviceLanguageCountry(language, country, function(err) {5  if (err) {6    console.log(err);7  } else {8    console.log('Device Language and Country set to ' + language + ' ' + country);9  }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var Appium = require('appium');3var argv = require('optimist').argv;4var language = argv._[0];5var country = argv._[1];6var appium = new Appium();7var driver = wd.remote("localhost",4723);8driver.init({9}, function(err) {10    if (err) {11        console.log("Error while initializing: " + err);12    }13    driver.setDeviceLanguageCountry(language,country,function(err){14        if(err){15            console.log("Error while setting language and country: " + err);16        }17        driver.quit(function(err){18            if(err){19                console.log("Error while quitting: " + err);20            }21        });22    });23});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var async = require('async');4var chai = require('chai');5var chaiAsPromised = require('chai-as-promised');6chai.use(chaiAsPromised);7chai.should();8chaiAsPromised.transferPromiseness = wd.transferPromiseness;9var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3    desiredCapabilities: {4    }5};6var client = webdriverio.remote(options);7    .init()8    .setDeviceLanguageCountry('en','US')9    .end();10var webdriverio = require('webdriverio');11var options = {12    desiredCapabilities: {13    }14};15var client = webdriverio.remote(options);16    .init()17    .setDeviceLanguageCountry('en','US')18    .end();

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