Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log.warn('Setting permissions is only supported on Simulator. ' +
'The "permissions" capability will be ignored.');
}
}
await this.startWda(this.opts.sessionId, realDevice);
await this.setReduceMotion(this.opts.reduceMotion);
await this.setInitialOrientation(this.opts.orientation);
this.logEvent('orientationSet');
// real devices will be handled later, after the web context has been initialized
if (this.isSafari() && !this.isRealDevice() && util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
// on 12.2 the page is not opened in WDA
await openUrl(this.opts.device.udid, this._currentUrl);
}
if (this.isSafari() || this.opts.autoWebview) {
log.debug('Waiting for initial webview');
await this.navToInitialWebview();
this.logEvent('initialWebviewNavigated');
}
if (this.isSafari() && this.isRealDevice() && util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
// on 12.2 the page is not opened in WDA
await this.setUrl(this._currentUrl);
}
if (!this.isRealDevice()) {
if (this.opts.calendarAccessAuthorized) {
await this.opts.device.enableCalendarAccess(this.opts.bundleId);
beforeEach(async function () {
rd = createRemoteDebugger({
bundleId: 'com.apple.mobilesafari',
isSafari: true,
useNewSafari: true,
pageLoadMs: 1000,
platformVersion: PLATFORM_VERSION,
socketPath: await sim.getWebInspectorSocket(),
garbageCollectOnExecute: false,
isSimulator: true,
logAllCommunication: true,
logAllCommunicationHexDump: false,
}, false);
await openUrl(sim.udid, address);
// pause a moment while Safari loads
await B.delay(2000);
});
afterEach(async function () {
} catch (e) {
throw new Error(`The temporary web server cannot be started at http://${host}:${tmpPort}.`);
}
if (this.isRealDevice()) {
try {
await this.proxyCommand('/url', 'POST', {url: certUrl});
} catch (err) {
if (this.isWebContext()) {
// The command above does not always work on real devices
await iosCommands.general.setUrl.call(this, certUrl);
} else {
throw err;
}
}
} else {
await openUrl(this.opts.udid || this.sim.udid, certUrl);
}
let isCertAlreadyInstalled = false;
if (util.compareVersions(this.opts.platformVersion, '>=', '12.2')) {
if (await installPost122Certificate(this, cn)) {
await clickElement(this, Settings.Profile);
await trustCertificateInPreferences(this, cn);
} else {
isCertAlreadyInstalled = true;
}
} else {
if (await installPre122Certificate(this)) {
await clickElement(this, Button.Return_to_Settings);
await trustCertificateInPreferences(this, cn);
} else {
isCertAlreadyInstalled = true;
await waitForCondition(async () => {
try {
// This is to make sure Safari is already running
const {stdout} = await exec('xcrun', ['simctl', 'launch', this.udid, MOBILE_SAFARI_BUNDLE_ID]);
if (PROCESS_LAUNCH_OK_PATTERN(MOBILE_SAFARI_BUNDLE_ID).test(stdout)) {
await simctlOpenUrl(this.udid, url);
return true;
}
} catch (err) {
log.error(`Failed to open '${url}' in Safari. Retrying...`);
lastError = err.stderr || err.message;
}
return false;
}, {waitMs: SAFARI_STARTUP_TIMEOUT, intervalMs: 500});
} catch (err) {
commands.setUrl = async function setUrl (url) {
log.debug(`Attempting to set url '${url}'`);
if (!this.isWebContext()) {
// use xcrun to open deeplink
await openUrl(this.opts.udid || this.sim.udid, url);
return;
}
this.setCurrentUrl(url);
// make sure to clear out any leftover web frames
this.curWebFrames = [];
await this.remote.navToUrl(url);
};