How to use this.navToInitialWebview 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
_

safari.js

Source: safari.js Github

copy
1"use strict";
2
3var IOS = require('./ios.js')
4  , logger = require('../../server/logger.js').get('appium')
5  , path = require('path')
6  , _ = require('underscore');
7
8var SAFARI_BUNDLE = 'com.apple.mobilesafari';
9
10var Safari = function () {
11  this.init();
12  this.landscapeWebCoordsOffset = 40;
13};
14
15_.extend(Safari.prototype, IOS.prototype);
16
17Safari.prototype.configure = function (args, caps, cb) {
18  logger.debug("Configuring Safari session");
19  this._deviceConfigure(args, caps);
20  this.setIOSArgs();
21  this.capabilities.safari = true;
22  if (this.args.udid) {
23    this.dontCleanupSession = true;
24    this.args.app = path.resolve(__dirname,
25        "../../../build/SafariLauncher/SafariLauncher.zip");
26    this.configureLocalApp(cb);
27  } else {
28    if (parseFloat(this.args.platformVersion) >= 8) {
29      logger.debug("We're on iOS8+ so not copying mobile safari app");
30      this.args.bundleId = SAFARI_BUNDLE;
31      this.args.app = null;
32    } else {
33      // make sure args.app has something in it so we get to the right spots
34      // in moveBuiltInApp()
35      this.args.app = "safari";
36    }
37    cb();
38  }
39};
40
41Safari.prototype.moveBuiltInApp = function (cb) {
42  if (!this.args.udid && this.args.app !== null) {
43    logger.debug("Trying to use mobile safari, version " +
44                 this.args.platformVersion);
45    this.sim.prepareSafari(this.args.tmpDir, function (err, attemptedApp, origApp) {
46      if (err) {
47        logger.error("Could not prepare mobile safari: " + err);
48        return cb(err);
49      }
50      logger.debug("Using mobile safari app at " + attemptedApp);
51      this.args.app = attemptedApp;
52      this.args.origAppPath = origApp;
53      cb();
54    }.bind(this));
55  } else {
56    cb();
57  }
58};
59
60// once safariLauncher is running and instrumented, this function
61// finds the button which launches safari and clicks it.
62Safari.prototype._clickButtonToLaunchSafari = function (cb) {
63  this.findElement('accessibility id', 'launch safari',
64                   function (err, res) {
65    if (err || res.status !== 0) {
66      var msg = "Error. Could not find button to launch Safari. " +
67                "Make sure you are using the latest version of " +
68                "SafariLauncher that appium is using";
69      logger.error(msg);
70      return cb(new Error(msg));
71    }
72
73    var buttonId = res.value.ELEMENT;
74
75    this.click(buttonId, function (err, res) {
76      if (err || res.status !== 0) {
77        var msg = "Error. For whatever reason, could not click " +
78                  "the 'launch safari' button of SafariLauncher";
79        logger.error(msg);
80        return cb(new Error(msg));
81      }
82
83      logger.debug("Clicked button, safari should be launching.");
84
85      // we're done with instruments at this point, we go on to Safari
86      this.navToInitialWebview(cb);
87
88    }.bind(this));
89  }.bind(this));
90};
91
92Safari.prototype._start = IOS.prototype.start;
93Safari.prototype.start = function (cb, onDie) {
94  var newOnDie = function (err) {
95    if (this.args.udid) {
96      return; // if we're using SafariLauncher, don't report failure
97    }
98    onDie(err);
99  }.bind(this);
100
101  this._start(function (err) {
102    if (err) return cb(err);
103
104    if (this.args.udid) {
105      logger.debug("On Safari Launcher. Tapping button to launch Safari");
106
107      this._clickButtonToLaunchSafari(function (err) {
108        if (err) return cb(err);
109
110        this.navToInitialWebview(cb);
111      }.bind(this));
112    } else {
113      this.navToInitialWebview(cb);
114    }
115  }.bind(this), newOnDie);
116};
117
118Safari.prototype.shouldIgnoreInstrumentsExit = function () {
119  return !!this.args.udid;
120};
121
122Safari.prototype._click = IOS.prototype.click;
123Safari.prototype.click = function (elementId, cb) {
124  if (this.capabilities.nativeWebTap && !this.args.udid) {
125    // atoms-based clicks don't always work in safari 7
126    this.nativeWebTap(elementId, cb);
127  } else {
128    this._click(elementId, cb);
129  }
130};
131
132Safari.prototype.setBundleId = function (cb) {
133  this.args.bundleId = SAFARI_BUNDLE;
134  cb();
135};
136
137Safari.prototype._setInitialOrientation = IOS.prototype.setInitialOrientation;
138Safari.prototype.setInitialOrientation = function (cb) {
139  if (this.shouldIgnoreInstrumentsExit()) {
140    logger.debug("Not setting initial orientation because we're on " +
141                 "SafariLauncher");
142    return cb();
143  }
144  this._setInitialOrientation(cb);
145};
146
147Safari.prototype.installToRealDevice = function (cb) {
148  if (this.args.udid) {
149    try {
150      if (!this.realDevice) {
151        this.realDevice = this.getIDeviceObj();
152      }
153    } catch (e) {
154      return cb(e);
155    }
156    this.isAppInstalled("com.bytearc.SafariLauncher", function (err, installed) {
157      if (err || !installed) {
158        this.installApp(this.args.app, cb);
159      } else {
160        cb();
161      }
162    }.bind(this));
163  } else {
164    logger.debug("Not installing to real device since we're on sim");
165    cb();
166  }
167};
168
169Safari.prototype.clearAppData = function (cb) {
170  if (this.args.fullReset) {
171    // Even though we delete typical apps on a regular reset, we do a good
172    // job of getting safari back to its original state, so actually deleting
173    // it is overkill in most cases, and requires an instantLaunchAndQuit.
174    // So we only delete it if the user requests a full reset
175    try {
176      this.sim.deleteSafari();
177    } catch (e) {
178      return cb(e);
179    }
180    cb();
181  } else {
182    this.sim.cleanSafari(this.keepAppToRetainPrefs, cb);
183  }
184};
185
186Safari.prototype._stopRemote = IOS.prototype.stopRemote;
187Safari.prototype.stopRemote = function () {
188  this._stopRemote(true);
189};
190
191Safari.prototype._stop = IOS.prototype.stop;
192Safari.prototype.stop = function (cb) {
193  if (this.shouldIgnoreInstrumentsExit()) {
194    logger.debug("Stopping safariLauncher");
195    this.shutdown(null, cb);
196  } else {
197    this._stop(cb);
198  }
199};
200
201module.exports = Safari;
202
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)