How to use this.adb.startUri method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

general.js

Source: general.js Github

copy
1import _ from 'lodash';
2import log from '../logger';
3import { androidHelpers } from 'appium-android-driver';
4import { errors } from 'appium-base-driver';
5
6let extensions = {},
7    commands = {},
8    helpers = {};
9
10commands.getPageSource = async function  () {
11  return await this.uiautomator2.jwproxy.command('/source', 'GET', {});
12};
13
14// Need to override this for correct unicode support
15commands.doSendKeys = async function (params) {
16  await this.uiautomator2.jwproxy.command('/keys', 'POST', params);
17};
18
19// uiautomator2 doesn't support metastate for keyevents
20commands.keyevent = async function (keycode, metastate) {
21  log.debug(`Ignoring metastate ${metastate}`);
22  await this.adb.keyevent(keycode);
23};
24
25// Use ADB since we don't have UiAutomator
26commands.back = async function () {
27  await this.adb.keyevent(4);
28};
29
30commands.getStrings = async function (language) {
31  if (!language) {
32    language = await this.adb.getDeviceLanguage();
33    log.info(`No language specified, returning strings for: ${language}`);
34  }
35
36  if (this.apkStrings[language]) {
37    // Return cached strings
38    return this.apkStrings[language];
39  }
40
41  // TODO: This is mutating the current language, but it's how appium currently works
42  this.apkStrings[language] = await androidHelpers.pushStrings(language, this.adb, this.opts);
43  await this.uiautomator2.jwproxy.command(`/appium/app/strings`, 'POST', {});
44
45  return this.apkStrings[language];
46};
47
48// memoized in constructor
49commands.getWindowSize = async function () {
50  return await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {});
51};
52
53// For W3C
54commands.getWindowRect = async function () {
55  const {width, height} = await this.getWindowSize();
56  return {
57    width,
58    height,
59    x: 0,
60    y: 0,
61  };
62};
63
64extensions.executeMobile = async function (mobileCommand, opts = {}) {
65  const mobileCommandsMapping = {
66    shell: 'mobileShell',
67
68    scrollBackTo: 'mobileScrollBackTo',
69    viewportScreenshot: 'mobileViewportScreenshot',
70
71    deepLink: 'mobileDeepLink',
72
73    startLogsBroadcast: 'mobileStartLogsBroadcast',
74    stopLogsBroadcast: 'mobileStopLogsBroadcast',
75
76    acceptAlert: 'mobileAcceptAlert',
77    dismissAlert: 'mobileDismissAlert',
78
79    batteryInfo: 'mobileGetBatteryInfo',
80  };
81
82  if (!_.has(mobileCommandsMapping, mobileCommand)) {
83    throw new errors.UnknownCommandError(`Unknown mobile command "${mobileCommand}". ` +
84                                         `Only ${_.keys(mobileCommandsMapping)} commands are supported.`);
85  }
86  return await this[mobileCommandsMapping[mobileCommand]](opts);
87};
88
89commands.mobileScrollBackTo = async function (opts) {
90  const {elementId, elementToId} = opts;
91  return await this.uiautomator2.jwproxy.command(`/appium/element/${elementId}/scroll_to/${elementToId}`, 'POST', {});
92};
93
94commands.mobileViewportScreenshot = async function () {
95  return await this.getViewportScreenshot();
96};
97
98commands.setUrl = async function (url) {
99  await this.adb.startUri(url, this.opts.appPackage);
100};
101
102commands.mobileDeepLink = async function (opts = {}) {
103  const {url, package:pkg} = opts;
104  return await this.adb.startUri(url, pkg);
105};
106
107commands.openNotifications = async function () {
108  return await this.uiautomator2.jwproxy.command('/appium/device/open_notifications', 'POST', {});
109};
110
111commands.updateSettings = async function (settings) {
112  return await this.uiautomator2.jwproxy.command('/appium/settings', 'POST', {settings});
113};
114
115commands.getSettings = async function () {
116  return await this.uiautomator2.jwproxy.command('/appium/settings', 'GET');
117};
118
119/**
120 * Overriding appium-android-driver's wrapBootstrapDisconnect,
121 * unlike in appium-android-driver avoiding adb restarting as it intern
122 * kills UiAutomator2 server running in the device.
123 **/
124helpers.wrapBootstrapDisconnect = async function (wrapped)  {
125  await wrapped();
126};
127
128// Stop proxying to any Chromedriver and redirect to uiautomator2
129helpers.suspendChromedriverProxy = function () {
130  this.chromedriver = null;
131  this.proxyReqRes = this.uiautomator2.proxyReqRes.bind(this.uiautomator2);
132  this.jwpProxyActive = true;
133};
134
135Object.assign(extensions, commands, helpers);
136
137export default extensions;
138
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Android Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)