Best JavaScript code snippet using appium-android-driver
driver.js
Source:driver.js
...316 this.opts.language, this.adb, this.opts);317 // This must run after installing the apk, otherwise it would cause the318 // install to fail. And before running the app.319 if (!_.isUndefined(this.opts.sharedPreferences)) {320 await this.setSharedPreferences(this.opts);321 }322 }323 async startChromeSession () {324 log.info("Starting a chrome-based browser session");325 let opts = _.cloneDeep(this.opts);326 opts.chromeUseRunningApp = false;327 const knownPackages = ["org.chromium.chrome.shell",328 "com.android.chrome",329 "com.chrome.beta",330 "org.chromium.chrome",331 "org.chromium.webview_shell"];332 if (!_.includes(knownPackages, this.opts.appPackage)) {333 opts.chromeAndroidActivity = this.opts.appActivity;334 }...
driver-specs.js
Source:driver-specs.js
...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) => {...
platform.js
Source:platform.js
1/**2 * Device agnostic platform interface.3 *4 * @package core5 * @author Andrew Sliwinski <a@mozillafoundation.org>6 */7var lru = require('lru-cache');8/**9 * Constructor10 */11function Platform () {12 // Check to see if window.Platform exists. If it does, return it.13 if (window.Platform) {14 return window.Platform;15 }16 // Init storage objects17 this.sharedStorage = window.localStorage;18 this.memStorage = lru(50);19 this.sessionKey = 'WEBMAKER_SESSION';20 this.cacheKey = '::' + window.pathname;21}22// -----------------------------------------------------------------------------23// Persistent storage24// -----------------------------------------------------------------------------25Platform.prototype.getSharedPreferences = function(key, global) {26 if (!global) {27 key += this.cacheKey;28 }29 return this.sharedStorage.getItem(key);30};31Platform.prototype.setSharedPreferences = function(key, value, global) {32 if (!global) {33 key += this.cacheKey;34 }35 return this.sharedStorage.setItem(key, value);36};37Platform.prototype.resetSharedPreferences = function() {38 return this.sharedStorage.clear();39};40// -----------------------------------------------------------------------------41// Session storage42// -----------------------------------------------------------------------------43Platform.prototype.getUserSession = function() {44 return this.getSharedPreferences(this.sessionKey);45};46Platform.prototype.setUserSession = function(data) {47 return this.setUserSession(this.sessionKey, data);48};49Platform.prototype.clearUserSession = function() {50 return this.setUserSession(this.sessionKey, null);51};52// -----------------------------------------------------------------------------53// Java caching54// -----------------------------------------------------------------------------55Platform.prototype.getAPI = function() {56 // True only if platform was supplied via the Android "windows.Platform"57 // mechanism, otherwise this is very much false.58 return false;59};60// -----------------------------------------------------------------------------61// Memory (LRU) storage62// -----------------------------------------------------------------------------63Platform.prototype.getMemStorage = function(key, global) {64 if (!global) {65 key += this.cacheKey;66 }67 return this.memStorage.get(key);68};69Platform.prototype.setMemStorage = function(key, value, global) {70 if (!global) {71 key += this.cacheKey;72 }73 return this.memStorage.set(key, value);74};75// -----------------------------------------------------------------------------76// Navigation77// -----------------------------------------------------------------------------78Platform.prototype.setView = function(uri) {79 window.location.href = uri;80};81Platform.prototype.openExternalUrl = function(uri) {82 window.location = uri;83};84Platform.prototype.goBack = function() {85 // @todo86};87Platform.prototype.goToHomeScreen = function() {88 // @todo89};90// -----------------------------------------------------------------------------91// Router92// -----------------------------------------------------------------------------93Platform.prototype.getRouteParams = function() {94 // @todo95};96Platform.prototype.getRouteData = function() {97 // @todo98};99Platform.prototype.clearRouteData = function() {100 // @todo101};102// -----------------------------------------------------------------------------103// Images104// -----------------------------------------------------------------------------105Platform.prototype.cameraIsAvailable = function() {106 // @todo107 return false;108};109Platform.prototype.getFromCamera = function() {110 // @todo111};112Platform.prototype.getFromMedia = function() {113 // @todo114};115// -----------------------------------------------------------------------------116// Sharing117// -----------------------------------------------------------------------------118Platform.prototype.shareProject = function() {119 // @todo120};121// -----------------------------------------------------------------------------122// Google Analytics123// -----------------------------------------------------------------------------124Platform.prototype.trackEvent = function(category, action, label, value) {125 if (!window.ga) {126 return;127 }128 window.ga('send', {129 'hitType': 'event',130 'eventCategory': category,131 'eventAction': action,132 'eventLabel': label,133 'eventValue': value134 });135};136// -----------------------------------------------------------------------------137// Configuration138// -----------------------------------------------------------------------------139Platform.prototype.isDebugBuild = function() {140 // @todo141 return false;142};143// -----------------------------------------------------------------------------144// Check network availability145// -----------------------------------------------------------------------------146Platform.prototype.isNetworkAvailable = function() {147 // @todo - the android method is synchronous, we need to do the browser chekc async 148 return true;149};...
pageadmin.js
Source:pageadmin.js
...62 // Trigger FTU63 if (pagesAdded === 2) {64 dispatcher.fire('secondPageCreated', {});65 }66 platform.setSharedPreferences('ftu::pages-created', pagesAdded, true);67 var json = {68 x: coords.x,69 y: coords.y,70 styles: {backgroundColor: '#f2f6fc'}71 };72 this.setState({loading: true});73 api({74 method: 'post',75 uri: this.uri(),76 json77 }, (err, data) => {78 this.setState({loading: false});79 if (err) {80 return reportError('Error loading project', err);...
Using AI Code Generation
1driver.setSharedPreferences("com.test.app", {name: "value"});2driver.getSharedPreferences("com.test.app", ["name"]);3driver.pushFile("/data/local/tmp/test.txt", "Hello World!");4driver.pullFile("/data/local/tmp/test.txt");5driver.pullFolder("/data/local/tmp");6driver.toggleLocationServices();7driver.getDeviceTime();8driver.installApp("/path/to/app.apk");9driver.isAppInstalled("com.test.app");10driver.removeApp("com.test.app");11driver.launchApp();12driver.closeApp();13driver.resetApp();14driver.runAppInBackground(3);15driver.startActivity("com.test.app", ".MainActivity", "com.test.app", "android.intent.action.MAIN", "android.intent.category.LAUNCHER");16driver.currentActivity();17driver.getDeviceSystemBars();18driver.getDisplayDensity();
Using AI Code Generation
1driver.setSharedPreferences('com.example.foo', {foo: 'bar'});2driver.getSharedPreferences('com.example.foo')3driver.removeSharedPreferences('com.example.foo')4driver.getPerformanceData('com.example.foo', 'memoryinfo', 1000)5driver.getPerformanceDataTypes()6driver.startActivity('com.example.foo', '.MainActivity', 'action', 'category', 'uri', 'mimeType', 'data', 'flags', 'optionalIntentArguments')7driver.currentActivity()8driver.currentPackage()9driver.pushFile('/data/local/tmp/test.txt', 'Hello World')10driver.pullFile('/data/local/tmp/test.txt')11driver.pullFolder('/data/local/tmp')12driver.toggleLocationServices()13driver.toggleData()14driver.toggleAirplaneMode()15driver.toggleWiFi()16driver.toggleFlightMode()17driver.toggleNetworkSpeed()18driver.toggleNetworkConnection()19driver.toggleData()20driver.toggleAirplaneMode()21driver.toggleWiFi()22driver.toggleFlightMode()23driver.toggleNetworkSpeed()
Using AI Code Generation
1driver.setSharedPreferences("key", "value");2driver.getSharedPreferences("key");3driver.getClipboard();4driver.setClipboard("content");5driver.getPerformanceData("packageName", "dataType", 10);6driver.getPerformanceDataTypes();7driver.toggleWiFi();8driver.toggleData();9driver.toggleAirplaneMode();10driver.toggleLocationServices();11driver.openNotifications();12driver.startActivity("appPackage", "
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!