How to use this.remote.startNetwork method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

context.js

Source: context.js Github

copy
1import { iosCommands, NATIVE_WIN } from 'appium-ios-driver';
2import { RemoteDebugger } from 'appium-remote-debugger';
3import { util } from 'appium-support';
4
5let extensions = {};
6
7Object.assign(extensions, iosCommands.context);
8
9// override, as appium-ios-driver's version uses UI Automation to close
10extensions.closeAlertBeforeTest = async function closeAlertBeforeTest () { // eslint-disable-line require-await
11  return true;
12};
13
14extensions._setContext = extensions.setContext;
15extensions.setContext = async function setContext (name, callback, skipReadyCheck) {
16  await this._setContext(name, callback, skipReadyCheck);
17
18  // start safari logging if the logs handlers are active
19  if (name && name !== NATIVE_WIN && this.logs) {
20    if (this.logs.safariConsole) {
21      await this.remote.startConsole(this.logs.safariConsole.addLogLine.bind(this.logs.safariConsole));
22    }
23    if (this.logs.safariNetwork) {
24      await this.remote.startNetwork(this.logs.safariNetwork.addLogLine.bind(this.logs.safariNetwork));
25    }
26  }
27};
28
29// the appium-ios-driver version of this function fails in CI,
30// and the wrong webview is almost always retrieved
31extensions._getLatestWebviewContextForTitle = extensions.getLatestWebviewContextForTitle;
32extensions.getLatestWebviewContextForTitle = async function getLatestWebviewContextForTitle (regExp) {
33  let currentUrl = this.getCurrentUrl();
34  if (!currentUrl) {
35    return await this._getLatestWebviewContextForTitle(regExp);
36  }
37
38  let contexts = await this.getContextsAndViews();
39  let matchingCtx;
40  for (let ctx of contexts) {
41    if (ctx.view) {
42      let url = ctx.view.url || '';
43      if (url === this.getCurrentUrl()) {
44        matchingCtx = ctx;
45        break;
46      }
47    }
48  }
49  if (matchingCtx) {
50    return matchingCtx.id;
51  }
52  return await this._getLatestWebviewContextForTitle(regExp);
53};
54
55extensions.isWebContext = function isWebContext () {
56  return !!this.curContext && this.curContext !== iosCommands.context.NATIVE_WIN;
57};
58
59extensions.isWebview = function isWebview () {
60  return this.isWebContext();
61};
62
63extensions.getNewRemoteDebugger = async function getNewRemoteDebugger () {
64  const socketPath = await this.opts.device.getWebInspectorSocket();
65  return new RemoteDebugger({
66    bundleId: this.opts.bundleId,
67    isSafari: this.isSafari(),
68    useNewSafari: this.useNewSafari(),
69    pageLoadMs: this.pageLoadMs,
70    platformVersion: this.opts.platformVersion,
71    socketPath,
72    remoteDebugProxy: this.opts.remoteDebugProxy,
73    garbageCollectOnExecute: util.hasValue(this.opts.safariGarbageCollect)
74      ? !!this.opts.safariGarbageCollect
75      : false,
76  });
77};
78
79/**
80 * @typedef {Object} Context
81 *
82 * @property {string} id - The identifier of the context. The native context
83 *                          will be 'NATIVE_APP' and the webviews will be
84 *                          'WEBVIEW_xxx'
85 * @property {?string} title - The title associated with the webview content
86 * @property {?string} url - The url associated with the webview content
87 */
88
89/**
90 * Get the contexts available, with information about the url and title of each
91 * webview
92 * @returns {Array} List of Context objects
93 */
94extensions.mobileGetContexts = async function mobileGetContexts () {
95  const curOpt = this.opts.fullContextList;
96  try {
97    // `appium-ios-driver#getContexts` returns the full list of contexts
98    // if this option is on
99    this.opts.fullContextList = true;
100    return await this.getContexts();
101  } finally {
102    // reset the option so there are no side effects
103    this.opts.fullContextList = curOpt;
104  }
105};
106
107
108export default extensions;
109
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 Xcuitest 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)