Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'appium-ios-driver' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// `contextId` will be in the form of `appId.pageId` in this case
const [appIdKey, pageIdKey] = _.map(contextId.split('.'), (id) => parseInt(id, 10));
try {
this.selectingNewPage = true;
await this.remote.selectPage(appIdKey, pageIdKey, skipReadyCheck);
} catch (err) {
this.curContext = this.curWindowHandle = oldContext;
throw err;
} finally {
this.selectingNewPage = false;
}
// attempt to start performance logging, if requested
if (this.opts.enablePerformanceLogging && this.remote) {
log.debug(`Starting performance log on '${this.curContext}'`);
this.logs.performance = new IOSPerformanceLog(this.remote);
await this.logs.performance.startCapture();
}
// start safari logging if the logs handlers are active
if (name && name !== NATIVE_WIN && this.logs) {
if (this.logs.safariConsole) {
await this.remote.startConsole(this.logs.safariConsole.addLogLine.bind(this.logs.safariConsole));
}
if (this.logs.safariNetwork) {
await this.remote.startNetwork(this.logs.safariNetwork.addLogLine.bind(this.logs.safariNetwork));
}
}
};
// find the keyboard, and hit the last Button
log.debug('Finding keyboard and clicking final button to close');
if (await this.getNativeAttribute('visible', keyboard) === 'false') {
log.debug('No visible keyboard found. Returning');
return;
}
let buttons = await this.findNativeElementOrElements('class name', 'XCUIElementTypeButton', true, keyboard);
if (_.isEmpty(buttons)) {
log.warn(`No button elements found. Unable to hide.`);
return;
}
await this.nativeClick(_.last(buttons));
}
};
commands.getStrings = iosCommands.general.getStrings;
commands.removeApp = async function removeApp (bundleId) {
return await this.mobileRemoveApp({bundleId});
};
commands.launchApp = iosCommands.general.launchApp;
commands.closeApp = iosCommands.general.closeApp;
commands.keys = async function keys (keys) {
if (!this.isWebContext()) {
throw new errors.UnknownError('Command should be proxied to WDA');
}
let el = util.unwrapElement(await this.active());
if (_.isEmpty(el)) {
throw new errors.NoSuchElementError();
}
}, {
waitMs: TMPSERVER_STARTUP_TIMEOUT,
intervalMs: 300,
});
log.debug(`The temporary web server is running at http://${host}:${tmpPort}`);
} 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;
}
if (this.isSimulator()) {
if (this.opts.shutdownOtherSimulators) {
this.ensureFeatureEnabled(SHUTDOWN_OTHER_FEAT_NAME);
await shutdownOtherSimulators(this.opts.device);
}
// this should be done before the simulator is started
// if it is already running, this cap won't work, which is documented
if (this.isSafari() && this.opts.safariGlobalPreferences) {
if (await this.opts.device.updateSafariGlobalSettings(this.opts.safariGlobalPreferences)) {
log.debug(`Safari global preferences updated`);
}
}
this.localConfig = await iosSettings.setLocaleAndPreferences(this.opts.device, this.opts, this.isSafari(), async (sim) => {
await shutdownSimulator(sim);
// we don't know if there needs to be changes a priori, so change first.
// sometimes the shutdown process changes the settings, so reset them,
// knowing that the sim is already shut
await iosSettings.setLocaleAndPreferences(sim, this.opts, this.isSafari());
});
await this.startSim();
if (this.opts.customSSLCert) {
if (await hasSSLCert(this.opts.customSSLCert, this.opts.udid)) {
log.info(`SSL cert '${_.truncate(this.opts.customSSLCert, {length: 20})}' already installed`);
} else {
log.info(`Installing ssl cert '${_.truncate(this.opts.customSSLCert, {length: 20})}'`);
await shutdownSimulator(this.opts.device);
this.localConfig = await iosSettings.setLocaleAndPreferences(this.opts.device, this.opts, this.isSafari(), async (sim) => {
await shutdownSimulator(sim);
// we don't know if there needs to be changes a priori, so change first.
// sometimes the shutdown process changes the settings, so reset them,
// knowing that the sim is already shut
await iosSettings.setLocaleAndPreferences(sim, this.opts, this.isSafari());
});
if (util.compareVersions(this.opts.platformVersion, '<', '12.2')) {
// this option does not work on 12.2 and above
this.opts.processArguments.args = ['-u', this._currentUrl];
}
} else if (this.opts.app || this.opts.bundleId) {
await this.configureApp();
}
this.logEvent('appConfigured');
// fail very early if the app doesn't actually exist
// or if bundle id doesn't point to an installed app
if (this.opts.app) {
await checkAppPresent(this.opts.app);
if (!this.opts.bundleId) {
this.opts.bundleId = await appUtils.extractBundleId(this.opts.app);
}
}
await this.runReset();
const memoizedLogInfo = _.memoize(function logInfo () {
log.info("'skipLogCapture' is set. Skipping starting logs such as crash, system, safari console and safari network.");
});
const startLogCapture = async () => {
if (this.opts.skipLogCapture) {
memoizedLogInfo();
return false;
}
const result = await this.startLogCapture();
if (result) {
import { iosCommands, IOSPerformanceLog, NATIVE_WIN, WEBVIEW_WIN } from 'appium-ios-driver';
import { createRemoteDebugger, RemoteDebugger } from 'appium-remote-debugger';
import { errors, isErrorType } from 'appium-base-driver';
import { util, timing } from 'appium-support';
import log from '../logger';
import { retryInterval } from 'asyncbox';
import _ from 'lodash';
const WEBVIEW_BASE = `${WEBVIEW_WIN}_`;
let commands = {}, helpers = {}, extensions = {};
Object.assign(extensions, iosCommands.context);
// override, as appium-ios-driver's version uses UI Automation to close
extensions.closeAlertBeforeTest = async function closeAlertBeforeTest () { // eslint-disable-line require-await
return true;
};
// the appium-ios-driver version has a wait on real devices, which is no longer
// necessary
extensions.navToInitialWebview = async function navToInitialWebview () {
if (this.useNewSafari()) {
await this.typeAndNavToUrl();
} else if (!this.isRealDevice() && this.opts.safari) {
await this.navToViewThroughFavorites();
} else {
await this.navToViewWithTitle(/.*/);
}
},
},
udid: null,
realDevice: null
};
});
sandbox.stub(driver, 'configureApp').callsFake(_.noop);
sandbox.stub(driver, 'startLogCapture').callsFake(_.noop);
sandbox.stub(driver, 'startSim').callsFake(_.noop);
sandbox.stub(driver, 'startWdaSession').callsFake(_.noop);
sandbox.stub(driver, 'startWda').callsFake(_.noop);
sandbox.stub(driver, 'setReduceMotion').callsFake(_.noop);
sandbox.stub(driver, 'installAUT').callsFake(_.noop);
sandbox.stub(driver, 'connectToRemoteDebugger').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setLocale').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setPreferences').callsFake(_.noop);
sandbox.stub(xcode, 'getMaxIOSSDK').callsFake(async () => '10.0'); // eslint-disable-line require-await
sandbox.stub(utils, 'checkAppPresent').callsFake(_.noop);
sandbox.stub(iosDriver.appUtils, 'extractBundleId').callsFake(_.noop);
});
return '/path/to/uds.socket';
},
},
udid: null,
realDevice: null
};
});
sandbox.stub(driver, 'configureApp').callsFake(_.noop);
sandbox.stub(driver, 'startLogCapture').callsFake(_.noop);
sandbox.stub(driver, 'startSim').callsFake(_.noop);
sandbox.stub(driver, 'startWdaSession').callsFake(_.noop);
sandbox.stub(driver, 'startWda').callsFake(_.noop);
sandbox.stub(driver, 'setReduceMotion').callsFake(_.noop);
sandbox.stub(driver, 'installAUT').callsFake(_.noop);
sandbox.stub(driver, 'connectToRemoteDebugger').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setLocale').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setPreferences').callsFake(_.noop);
sandbox.stub(xcode, 'getMaxIOSSDK').callsFake(async () => '10.0'); // eslint-disable-line require-await
sandbox.stub(utils, 'checkAppPresent').callsFake(_.noop);
sandbox.stub(iosDriver.appUtils, 'extractBundleId').callsFake(_.noop);
});
realDevice: null
};
});
sandbox.stub(driver, 'configureApp').callsFake(_.noop);
sandbox.stub(driver, 'startLogCapture').callsFake(_.noop);
sandbox.stub(driver, 'startSim').callsFake(_.noop);
sandbox.stub(driver, 'startWdaSession').callsFake(_.noop);
sandbox.stub(driver, 'startWda').callsFake(_.noop);
sandbox.stub(driver, 'setReduceMotion').callsFake(_.noop);
sandbox.stub(driver, 'installAUT').callsFake(_.noop);
sandbox.stub(driver, 'connectToRemoteDebugger').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setLocale').callsFake(_.noop);
sandbox.stub(iosDriver.settings, 'setPreferences').callsFake(_.noop);
sandbox.stub(xcode, 'getMaxIOSSDK').callsFake(async () => '10.0'); // eslint-disable-line require-await
sandbox.stub(utils, 'checkAppPresent').callsFake(_.noop);
sandbox.stub(iosDriver.appUtils, 'extractBundleId').callsFake(_.noop);
});