How to use iproxy.start 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
_

iproxy.js

Source: iproxy.js Github

copy
1import log from '../logger';
2import { killProcess } from './utils';
3import B from 'bluebird';
4import { logger } from 'appium-support';
5import { SubProcess } from 'teen_process';
6
7
8const IPROXY_TIMEOUT = 5000;
9
10const iproxyLog = logger.getLogger('iProxy');
11
12class iProxy {
13  constructor (udid, localport, deviceport) {
14    log.debug(`Starting iproxy to forward traffic from local port ${localport} to device port ${deviceport} over USB`);
15    this.expectIProxyErrors = true;
16    this.iproxy = new SubProcess('iproxy', [localport, deviceport, udid], {
17      detached: true,
18      stdio: ['ignore', 'pipe', 'pipe'],
19    });
20  }
21
22  async start () {
23    this.expectIProxyErrors = true;
24
25    return await new B((resolve, reject) => {
26      this.iproxy.on('exit', (code) => {
27        log.debug(`iproxy exited with code '${code}'`);
28        if (code) {
29          return reject(new Error(`iproxy exited with code '${code}'`));
30        }
31      });
32      this.iproxy.on('output', (stdout, stderr) => {
33        // do nothing if we expect errors
34        if (this.expectIProxyErrors) {
35          return;
36        }
37
38        let out = stdout || stderr;
39        for (let line of out.split('\n')) {
40          if (!line.length) {
41            continue;
42          }
43
44          if (line.indexOf('Resource temporarily unavailable') !== -1) {
45            // this generally happens when WDA does not respond,
46            // so print a more useful message
47            log.debug('Connection to WDA timed out');
48          } else {
49            iproxyLog.debug(line);
50          }
51        }
52      });
53
54      return (async () => {
55        try {
56          await this.iproxy.start(IPROXY_TIMEOUT);
57          this.iproxy.proc.unref();
58          resolve();
59        } catch (err) {
60          log.error(`Error starting iproxy: '${err.message}'`);
61          reject(new Error('Unable to start iproxy. Is it installed?'));
62        }
63      })();
64    });
65  }
66
67  async quit () {
68    await killProcess('iproxy', this.iproxy);
69    this.expectIProxyErrors = true;
70  }
71}
72
73export { iProxy };
74export default iProxy;
75
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)