How to use initWDA 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
_

session.js

Source: session.js Github

copy
1import wd from 'wd';
2import request from 'request-promise';
3import { startServer } from '../../..';
4import { util } from 'appium-support';
5import patchDriverWithEvents from './ci-metrics';
6
7
8// if we are tracking CI metrics, patch the wd framework
9if (process.env.CI_METRICS) {
10  patchDriverWithEvents();
11}
12
13const HOST = process.env.REAL_DEVICE ? util.localIp() : 'localhost',
14      PORT = 4994;
15const MOCHA_TIMEOUT = 60 * 1000 * (process.env.CI ? 8 : 4);
16const WDA_PORT = 8200;
17
18let driver, server;
19
20async function initDriver () {
21  driver = wd.promiseChainRemote(HOST, PORT);
22
23  return driver;
24}
25
26async function initServer () {
27  server = await startServer(PORT, HOST);
28}
29
30async function initWDA (caps) {
31  // first, see if this is necessary
32  try {
33    await request.get({url: `http://${HOST}:${WDA_PORT}/status`});
34  } catch (err) {
35    // easiest way to initialize WDA is to go through a test startup
36    // otherwise every change to the system would require a change here
37    const desiredCaps = Object.assign({
38      autoLaunch: false,
39      wdaLocalPort: WDA_PORT,
40    }, caps);
41    await driver.init(desiredCaps);
42    await driver.quit();
43  }
44}
45
46async function initSession (caps) {
47  await initServer();
48  await initDriver();
49
50  if (process.env.USE_WEBDRIVERAGENTURL) {
51    await initWDA(caps);
52    caps = Object.assign({
53      webDriverAgentUrl: `http://${HOST}:${WDA_PORT}`,
54      wdaLocalPort: WDA_PORT,
55    }, caps);
56  }
57
58  let serverRes = await driver.init(caps);
59  if (!caps.udid && !caps.fullReset && serverRes[1].udid) {
60    caps.udid = serverRes[1].udid;
61  }
62
63  await driver.setImplicitWaitTimeout(5000);
64
65  return driver;
66}
67
68async function deleteSession () {
69  try {
70    await driver.quit();
71  } catch (ign) {}
72  try {
73    await server.close();
74  } catch (ign) {}
75}
76
77export { initDriver, initSession, deleteSession, HOST, PORT, MOCHA_TIMEOUT };
78
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)