How to use driver.setSharedPreferences method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

driver-specs.js

Source:driver-specs.js Github

copy

Full Screen

...52 let builder = new SharedPrefsBuilder();53 describe('should skip setting sharedPreferences', withMocks({driver}, (mocks) => {54 it('on undefined name', async () => {55 driver.opts.sharedPreferences = {};56 (await driver.setSharedPreferences()).should.be.false;57 mocks.driver.verify();58 });59 }));60 describe('should set sharedPreferences', withMocks({driver, adb, builder, fs}, (mocks) => {61 it('on defined sharedPreferences object', async () => {62 driver.opts.appPackage = 'io.appium.test';63 driver.opts.sharedPreferences = {64 name: 'com.appium.prefs',65 prefs: [{type: 'string', name: 'mystr', value:'appium rocks!'}]66 };67 mocks.driver.expects('getPrefsBuilder').once().returns(builder);68 mocks.builder.expects('build').once();69 mocks.builder.expects('toFile').once();70 mocks.adb.expects('shell').once()71 .withExactArgs(['mkdir', '-p', '/data/data/io.appium.test/shared_prefs']);72 mocks.adb.expects('push').once()73 .withExactArgs('/tmp/com.appium.prefs.xml', '/data/data/io.appium.test/shared_prefs/com.appium.prefs.xml');74 mocks.fs.expects('exists').once()75 .withExactArgs('/tmp/com.appium.prefs.xml')76 .returns(true);77 mocks.fs.expects('unlink').once()78 .withExactArgs('/tmp/com.appium.prefs.xml');79 await driver.setSharedPreferences();80 mocks.driver.verify();81 mocks.adb.verify();82 mocks.builder.verify();83 mocks.fs.verify();84 });85 }));86 });87 describe('createSession', () => {88 beforeEach(() => {89 driver = new AndroidDriver();90 sandbox.stub(driver, 'checkAppPresent');91 sandbox.stub(driver, 'checkPackagePresent');92 sandbox.stub(driver, 'startAndroidSession');93 sandbox.stub(ADB, 'createADB', async (opts) => {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({'browserName': 'chrome'})4 .build();5driver.setSharedPreferences('testkey', 'testvalue');6driver.quit();7var webdriver = require('selenium-webdriver');8var driver = new webdriver.Builder()9 .withCapabilities({'browserName': 'chrome'})10 .build();11driver.setSharedPreferences('testkey', 'testvalue');12driver.getPreferences('testkey').then(function(value){13 console.log(value);14 driver.quit();15});16var webdriver = require('selenium-webdriver');17var driver = new webdriver.Builder()18 .withCapabilities({'browserName': 'chrome'})19 .build();20driver.getPerformanceDataTypes().then(function(value){21 console.log(value);22 driver.quit();23});24var webdriver = require('selenium-webdriver');25var driver = new webdriver.Builder()26 .withCapabilities({'browserName': 'chrome'})27 .build();28driver.getPerformanceDataTypes().then(function

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var wd = require('wd');3var util = require('util');4var assert = require('assert');5var Q = require('q');6var _ = require('underscore');7var caps = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var androidDriver = require("appium-android-driver");4var driver = wd.promiseChainRemote("localhost", 4723);5driver.init({6}).then(function() {7 driver.setSharedPreferences({8 "com.myApp": {9 }10 });11 driver.startActivity({12 });13});14driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var colors = require('colors');4var desired = {5};6var driver = wd.promiseChainRemote("localhost", 4723);7driver.setSharedPreferences({8, prefData: {9 }10})11.init(desired)12.getSharedPrefs({13})14.then(function(sharedPrefs) {15 console.log('sharedPrefs: ' + JSON.stringify(sharedPrefs));16})17.quit();

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