How to use this.logs.syslog.stopCapture method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

ios.js

Source:ios.js Github

copy

Full Screen

...291IOS.prototype.startInstruments = function (cb) {292 cb = _.once(cb);293 var treatError = function (err, cb) {294 if (!_.isEmpty(this.logs)) {295 this.logs.syslog.stopCapture();296 this.logs = {};297 }298 this.postCleanup(function () {299 cb(err);300 });301 }.bind(this);302 logger.debug("Starting command proxy.");303 this.commandProxy.start(304 function onFirstConnection(err) {305 // first let instruments know so that it does not restart itself306 this.instruments.launchHandler(err);307 // then we call the callback308 cb(err);309 }.bind(this)310 , function regularCallback(err) {311 if (err) return treatError(err, cb);312 logger.debug("Starting instruments");313 this.instruments.start(314 function (err) {315 if (err) return treatError(err, cb);316 // we don't call cb here, waiting for first connection or error317 }.bind(this)318 , function (code) {319 if (!this.shouldIgnoreInstrumentsExit()) {320 this.onUnexpectedInstrumentsExit(code);321 }322 }.bind(this)323 );324 }.bind(this)325 );326};327IOS.prototype.makeInstruments = function (cb) {328 // at the moment all the logging in uiauto is at debug level329 // TODO: be able to use info in appium-uiauto330 var bootstrap = prepareBootstrap({331 sock: this.sock,332 interKeyDelay: this.args.interKeyDelay,333 justLoopInfinitely: false,334 autoAcceptAlerts: !(!this.args.autoAcceptAlerts || this.args.autoAcceptAlerts === 'false'),335 autoDismissAlerts: !(!this.args.autoDismissAlerts || this.args.autoDismissAlerts === 'false'),336 sendKeyStrategy: this.args.sendKeyStrategy || (this.args.udid ? 'grouped' : 'oneByOne')337 });338 bootstrap.then(function (bootstrapPath) {339 var instruments = new Instruments({340 // on real devices bundleId is always used341 app: (!this.args.udid ? this.args.app : null) || this.args.bundleId342 , udid: this.args.udid343 , processArguments: this.args.processArguments344 , ignoreStartupExit: this.shouldIgnoreInstrumentsExit()345 , bootstrap: bootstrapPath346 , template: this.args.automationTraceTemplatePath347 , instrumentsPath: this.args.instrumentsPath348 , withoutDelay: this.args.withoutDelay349 , platformVersion: this.args.platformVersion350 , webSocket: this.args.webSocket351 , launchTimeout: this.args.launchTimeout352 , flakeyRetries: this.args.backendRetries353 , simulatorSdkAndDevice: this.iOSSDKVersion >= 7.1 ? this.getDeviceString() : null354 , tmpDir: path.resolve(this.args.tmpDir , 'appium-instruments')355 , traceDir: this.args.traceDir356 });357 cb(null, instruments);358 }.bind(this), cb).fail(cb);359};360IOS.prototype.shouldIgnoreInstrumentsExit = function () {361 return false;362};363IOS.prototype.onInstrumentsLaunch = function (cb) {364 logger.debug('Instruments launched. Starting poll loop for new commands.');365 this.instruments.setDebug(true);366 if (this.args.origAppPath) {367 logger.debug("Copying app back to its original place");368 return ncp(this.args.app, this.args.origAppPath, cb);369 }370 cb();371};372IOS.prototype.setBundleId = function (cb) {373 if (this.args.bundleId) {374 // We already have a bundle Id375 cb();376 } else {377 this.proxy('au.bundleId()', function (err, bId) {378 if (err) return cb(err);379 logger.debug('Bundle ID for open app is ' + bId.value);380 this.args.bundleId = bId.value;381 cb();382 }.bind(this));383 }384};385IOS.prototype.setInitialOrientation = function (cb) {386 if (typeof this.args.initialOrientation === "string" &&387 _.contains(["LANDSCAPE", "PORTRAIT"],388 this.args.initialOrientation.toUpperCase())389 ) {390 logger.debug("Setting initial orientation to " + this.args.initialOrientation);391 var command = ["au.setScreenOrientation('",392 this.args.initialOrientation.toUpperCase(), "')"].join('');393 this.proxy(command, function (err, res) {394 if (err || res.status !== status.codes.Success.code) {395 logger.warn("Setting initial orientation did not work!");396 } else {397 this.curOrientation = this.args.initialOrientation;398 }399 cb();400 }.bind(this));401 } else {402 cb();403 }404};405IOS.isSpringBoard = function (uiAppObj) {406// Test for iOS homescreen (SpringBoard). AUT occassionally start the sim, but fails to load407// the app. If that occurs, getSourceForElementFoXML will return a doc object that meets our408// app-check conditions, resulting in a false positive. This function tests the UiApplication409// property's meta data to ensure that the Appium doesn't confuse SpringBoard with the app410// under test.411 return _.propertyOf(uiAppObj['@'])('name') === 'SpringBoard';412};413IOS.prototype.waitForAppLaunched = function (cb) {414 // on iOS8 in particular, we can get a working session before the app415 // is ready to respond to commands; in that case the source will be empty416 // so we just spin until it's not417 var condFn;418 if (this.args.waitForAppScript) {419 // the default getSourceForElementForXML does not fit some use case, so making this customizable.420 // TODO: collect script from customer and propose several options, please comment in issue #4190.421 logger.debug("Using custom script to wait for app start:" + this.args.waitForAppScript);422 condFn = function (cb) {423 this.proxy('try{\n' + this.args.waitForAppScript +424 '\n} catch(err) { $.log("waitForAppScript err: " + error); false; };',425 function (err, res) {426 cb(!!res.value, err);427 });428 }.bind(this);429 } else {430 logger.debug("Waiting for app source to contain elements");431 condFn = function (cb) {432 this.getSourceForElementForXML(null, function (err, res) {433 if (err || !res || res.status !== status.codes.Success.code) {434 return cb(false, err);435 }436 var sourceObj, appEls;437 try {438 sourceObj = JSON.parse(res.value);439 appEls = sourceObj.UIAApplication['>'];440 if (appEls.length > 0 && !IOS.isSpringBoard(sourceObj.UIAApplication)) {441 return cb(true);442 } else {443 return cb(false, new Error("App did not have elements"));444 }445 } catch (e) {446 return cb(false, new Error("Couldn't parse JSON source"));447 }448 return cb(true, err);449 });450 }.bind(this);451 }452 this.waitForCondition(10000, condFn, cb, 500);453};454IOS.prototype.configureBootstrap = function (cb) {455 logger.debug("Setting bootstrap config keys/values");456 var isVerbose = logger.transports.console.level === 'debug';457 var cmd = '';458 cmd += 'target = $.target();\n';459 cmd += 'au = $;\n';460 cmd += '$.isVerbose = ' + isVerbose + ';\n';461 // Not using uiauto grace period because of bug.462 // cmd += '$.target().setTimeout(1);\n';463 this.proxy(cmd, cb);464};465IOS.prototype.onUnexpectedInstrumentsExit = function (code) {466 logger.debug("Instruments exited unexpectedly");467 this.isShuttingDown = true;468 var postShutdown = function () {469 if (typeof this.cbForCurrentCmd === "function") {470 logger.debug("We were in the middle of processing a command when " +471 "instruments died; responding with a generic error");472 var error = new UnknownError("Instruments died while responding to " +473 "command, please check appium logs");474 this.onInstrumentsDie(error, this.cbForCurrentCmd);475 } else {476 this.onInstrumentsDie();477 }478 }.bind(this);479 if (this.commandProxy) {480 this.commandProxy.safeShutdown(function () {481 this.shutdown(code, postShutdown);482 }.bind(this));483 } else {484 this.shutdown(code, postShutdown);485 }486};487IOS.prototype.setXcodeVersion = function (cb) {488 logger.debug("Setting Xcode version");489 xcode.getVersion(function (err, versionNumber) {490 if (err) {491 logger.error("Could not determine Xcode version:" + err.message);492 } else {493 var minorVersion = parseFloat(versionNumber.slice(0, 3));494 var pv = parseFloat(this.args.platformVersion);495 // we deprecate Xcodes < 6.3, except for iOS 8.0 in which case we496 // support Xcode 6.0 as well497 if (minorVersion < 6.3 && (!(minorVersion === 6.0 && pv === 8.0))) {498 logCustomDeprecationWarning('Xcode version', versionNumber,499 'Support for Xcode ' + versionNumber + ' ' +500 'has been deprecated and will be removed ' +501 'in a future version. Please upgrade ' +502 'to version 6.3 or higher (or version ' +503 '6.0.1 for iOS 8.0)');504 }505 }506 this.xcodeVersion = versionNumber;507 logger.debug("Xcode version set to " + versionNumber);508 cb();509 }.bind(this));510};511IOS.prototype.setiOSSDKVersion = function (cb) {512 logger.debug("Setting iOS SDK Version");513 xcode.getMaxIOSSDK(function (err, versionNumber) {514 if (err) {515 logger.error("Could not determine iOS SDK version");516 return cb(err);517 }518 this.iOSSDKVersion = versionNumber;519 logger.debug("iOS SDK Version set to " + this.iOSSDKVersion);520 cb();521 }.bind(this));522};523IOS.prototype.setLocale = function (cb) {524 var msg;525 var setLoc = function (err) {526 logger.debug("Setting locale information");527 if (err) return cb(err);528 var needSimRestart = false;529 this.localeConfig = this.localeConfig || {};530 _(['language', 'locale', 'calendarFormat']).each(function (key) {531 needSimRestart = needSimRestart ||532 (this.args[key] &&533 this.args[key] !== this.localeConfig[key]);534 }, this);535 this.localeConfig = {536 language: this.args.language,537 locale: this.args.locale,538 calendarFormat: this.args.calendarFormat539 };540 var simRoots = this.sim.getDirs();541 if (simRoots.length < 1) {542 msg = "Cannot set locale information because the iOS Simulator directory could not be determined.";543 logger.error(msg);544 return cb(new Error(msg));545 }546 try {547 this.sim.setLocale(this.args.language, this.args.locale, this.args.calendarFormat);548 } catch (e) {549 msg = "Appium was unable to set locale info: " + e;550 logger.error(msg);551 return cb(new Error(msg));552 }553 logger.debug("Locale was set");554 if (needSimRestart) {555 logger.debug("First time setting locale, or locale changed, killing existing Instruments and Sim procs.");556 Instruments.killAllSim();557 Instruments.killAll();558 setTimeout(cb, 250);559 } else {560 cb();561 }562 }.bind(this);563 if ((this.args.language || this.args.locale || this.args.calendarFormat) && this.args.udid === null) {564 if (this.args.fullReset && this.args.platformVersion <= 6.1) {565 msg = "Cannot set locale information because a full-reset was requested. full-reset interferes with the language/locale caps on iOS 6.1 and older";566 logger.error(msg);567 return cb(new Error(msg));568 }569 if (!this.sim.dirsExist()) {570 this.instantLaunchAndQuit(false, setLoc);571 } else {572 setLoc();573 }574 } else if (this.args.udid) {575 logger.debug("Not setting locale because we're using a real device");576 cb();577 } else {578 logger.debug("Not setting locale");579 cb();580 }581};582IOS.prototype.checkPreferences = function (cb) {583 logger.debug("Checking whether we need to set app preferences");584 if (this.args.udid !== null) {585 logger.debug("Not setting iOS and app preferences since we're on a real " +586 "device");587 return cb();588 }589 var settingsCaps = [590 'locationServicesEnabled',591 'locationServicesAuthorized',592 'safariAllowPopups',593 'safariIgnoreFraudWarning',594 'safariOpenLinksInBackground'595 ];596 var safariSettingsCaps = settingsCaps.slice(2, 5);597 this.needToSetPrefs = false;598 this.needToSetSafariPrefs = false;599 _.each(settingsCaps, function (cap) {600 if (_.has(this.capabilities, cap)) {601 this.needToSetPrefs = true;602 if (_.contains(safariSettingsCaps, cap)) {603 this.needToSetSafariPrefs = true;604 }605 }606 }.bind(this));607 this.keepAppToRetainPrefs = this.needToSetPrefs;608 cb();609};610IOS.prototype.setPreferences = function (cb) {611 if (!this.needToSetPrefs) {612 logger.debug("No iOS / app preferences to set");613 return cb();614 } else if (this.args.fullReset) {615 var msg = "Cannot set preferences because a full-reset was requested";616 logger.debug(msg);617 logger.error(msg);618 return cb(new Error(msg));619 }620 var setPrefs = function (err) {621 if (err) return cb(err);622 try {623 this.setLocServicesPrefs();624 } catch (e) {625 logger.error("Error setting location services preferences, prefs will not work");626 logger.error(e);627 logger.error(e.stack);628 }629 try {630 this.setSafariPrefs();631 } catch (e) {632 logger.error("Error setting safari preferences, prefs will not work");633 logger.error(e);634 logger.error(e.stack);635 }636 cb();637 }.bind(this);638 logger.debug("Setting iOS and app preferences");639 if (!this.sim.dirsExist() ||640 !settings.locServicesDirsExist(this.sim) ||641 (this.needToSetSafariPrefs && !this.sim.safariDirsExist())) {642 this.instantLaunchAndQuit(this.needToSetSafariPrefs, setPrefs);643 } else {644 setPrefs();645 }646};647IOS.prototype.instantLaunchAndQuit = function (needSafariDirs, cb) {648 logger.debug("Sim files for the " + this.iOSSDKVersion + " SDK do not yet exist, launching the sim " +649 "to populate the applications and preference dirs");650 var condition = function () {651 var simDirsExist = this.sim.dirsExist();652 var locServicesExist = settings.locServicesDirsExist(this.sim);653 var safariDirsExist = this.args.platformVersion < 7.0 ||654 (this.sim.safariDirsExist() &&655 (this.args.platformVersion < 8.0 ||656 this.sim.userSettingsPlistExists())657 );658 var okToGo = simDirsExist && locServicesExist &&659 (!needSafariDirs || safariDirsExist);660 if (!okToGo) {661 logger.debug("We launched the simulator but the required dirs don't " +662 "yet exist. Waiting some more...");663 }664 return okToGo;665 }.bind(this);666 this.prelaunchSimulator(function (err) {667 if (err) return cb(err);668 this.makeInstruments(function (err, instruments) {669 instruments.launchAndKill(condition, function (err) {670 if (err) return cb(err);671 this.endSimulator(cb);672 }.bind(this));673 }.bind(this));674 }.bind(this));675};676IOS.prototype.setLocServicesPrefs = function () {677 if (typeof this.capabilities.locationServicesEnabled !== "undefined" ||678 this.capabilities.locationServicesAuthorized) {679 var locServ = this.capabilities.locationServicesEnabled;680 locServ = locServ || this.capabilities.locationServicesAuthorized;681 locServ = locServ ? 1 : 0;682 logger.debug("Setting location services to " + locServ);683 settings.updateSettings(this.sim, 'locationServices', {684 LocationServicesEnabled: locServ,685 'LocationServicesEnabledIn7.0': locServ,686 'LocationServicesEnabledIn8.0': locServ687 }688 );689 }690 if (typeof this.capabilities.locationServicesAuthorized !== "undefined") {691 if (!this.args.bundleId) {692 var msg = "Can't set location services for app without bundle ID";693 logger.error(msg);694 throw new Error(msg);695 }696 var locAuth = !!this.capabilities.locationServicesAuthorized;697 if (locAuth) {698 logger.debug("Authorizing location services for app");699 } else {700 logger.debug("De-authorizing location services for app");701 }702 settings.updateLocationSettings(this.sim, this.args.bundleId, locAuth);703 }704};705IOS.prototype.setSafariPrefs = function () {706 var safariSettings = {};707 var val;708 if (_.has(this.capabilities, 'safariAllowPopups')) {709 val = !!this.capabilities.safariAllowPopups;710 logger.debug("Setting javascript window opening to " + val);711 safariSettings.WebKitJavaScriptCanOpenWindowsAutomatically = val;712 safariSettings.JavaScriptCanOpenWindowsAutomatically = val;713 }714 if (_.has(this.capabilities, 'safariIgnoreFraudWarning')) {715 val = !this.capabilities.safariIgnoreFraudWarning;716 logger.debug("Setting fraudulent website warning to " + val);717 safariSettings.WarnAboutFraudulentWebsites = val;718 }719 if (_.has(this.capabilities, 'safariOpenLinksInBackground')) {720 val = this.capabilities.safariOpenLinksInBackground ? 1 : 0;721 logger.debug("Setting opening links in background to " + !!val);722 safariSettings.OpenLinksInBackground = val;723 }724 if (_.size(safariSettings) > 0) {725 settings.updateSafariSettings(this.sim, safariSettings);726 }727};728IOS.prototype.detectUdid = function (cb) {729 var msg;730 logger.debug("Auto-detecting iOS udid...");731 if (this.args.udid !== null && this.args.udid === "auto") {732 which('idevice_id', function (notFound, cmdPath) {733 var udidetectPath;734 if (notFound) {735 udidetectPath = require.resolve('udidetect');736 } else {737 udidetectPath = cmdPath + " -l";738 }739 exec(udidetectPath, { maxBuffer: 524288, timeout: 3000 }, function (err, stdout) {740 if (err) {741 msg = "Error detecting udid: " + err.message;742 logger.error(msg);743 cb(err);744 }745 if (stdout && stdout.length > 2) {746 this.args.udid = stdout.split("\n")[0];747 logger.debug("Detected udid as " + this.args.udid);748 cb();749 } else {750 msg = "Could not detect udid.";751 logger.error(msg);752 cb(new Error(msg));753 }754 }.bind(this));755 }.bind(this));756 } else {757 logger.debug("Not auto-detecting udid, running on sim");758 cb();759 }760};761IOS.prototype.setBundleIdFromApp = function (cb) {762 // This method will try to extract the bundleId from the app763 if (this.args.bundleId) {764 // We aleady have a bundle Id765 cb();766 } else {767 this.getBundleIdFromApp(function (err, bundleId) {768 if (err) {769 logger.error("Could not set the bundleId from app.");770 return cb(err);771 }772 this.args.bundleId = bundleId;773 cb();774 }.bind(this));775 }776};777IOS.prototype.installToRealDevice = function (cb) {778 // if user has passed in desiredCaps.autoLaunch = false779 // meaning they will manage app install / launching780 if (this.args.autoLaunch === false) {781 cb();782 } else {783 if (this.args.udid) {784 try {785 this.realDevice = this.getIDeviceObj();786 } catch (e) {787 return cb(e);788 }789 this.isAppInstalled(this.args.bundleId, function (err, installed) {790 if (err || !installed) {791 logger.debug("App is not installed. Will try to install the app.");792 } else {793 logger.debug("App is installed.");794 if (this.args.fullReset) {795 logger.debug("fullReset requested. Forcing app install.");796 } else {797 logger.debug("fullReset not requested. No need to install.");798 return cb();799 }800 }801 if (this.args.ipa && this.args.bundleId) {802 this.installIpa(cb);803 } else if (this.args.ipa) {804 var msg = "You specified a UDID and ipa but did not include the bundle " +805 "id";806 logger.error(msg);807 cb(new Error(msg));808 } else if (this.args.app) {809 this.installApp(this.args.app, cb);810 } else {811 logger.debug("Real device specified but no ipa or app path, assuming bundle ID is " +812 "on device");813 cb();814 }815 }.bind(this));816 } else {817 logger.debug("No device id or app, not installing to real device.");818 cb();819 }820 }821};822IOS.prototype.getIDeviceObj = function () {823 var idiPath = path.resolve(__dirname, "../../../build/",824 "libimobiledevice-macosx/ideviceinstaller");825 logger.debug("Creating iDevice object with udid " + this.args.udid);826 try {827 return iDevice(this.args.udid);828 } catch (e1) {829 logger.debug("Couldn't find ideviceinstaller, trying built-in at " +830 idiPath);831 try {832 return iDevice(this.args.udid, {cmd: idiPath});833 } catch (e2) {834 var msg = "Could not initialize ideviceinstaller; make sure it is " +835 "installed and works on your system";836 logger.error(msg);837 throw new Error(msg);838 }839 }840};841IOS.prototype.installIpa = function (cb) {842 logger.debug("Installing ipa found at " + this.args.ipa);843 if (!this.realDevice) {844 this.realDevice = this.getIDeviceObj();845 }846 var d = this.realDevice;847 async.waterfall([848 function (cb) { d.isInstalled(this.args.bundleId, cb); }.bind(this),849 function (installed, cb) {850 if (installed) {851 logger.debug("Bundle found on device, removing before reinstalling.");852 d.remove(this.args.bundleId, cb);853 } else {854 logger.debug("Nothing found on device, going ahead and installing.");855 cb();856 }857 }.bind(this),858 function (cb) { d.installAndWait(this.args.ipa, this.args.bundleId, cb); }.bind(this)859 ], cb);860};861IOS.getDeviceStringFromOpts = function (opts) {862 logger.debug("Getting device string from opts: " + JSON.stringify({863 forceIphone: opts.forceIphone,864 forceIpad: opts.forceIpad,865 xcodeVersion: opts.xcodeVersion,866 iOSSDKVersion: opts.iOSSDKVersion,867 deviceName: opts.deviceName,868 platformVersion: opts.platformVersion869 }));870 var xcodeMajorVer = parseInt(opts.xcodeVersion.substr(0,871 opts.xcodeVersion.indexOf('.')), 10);872 var isiPhone = opts.forceIphone || opts.forceIpad === null || (opts.forceIpad !== null && !opts.forceIpad);873 var isTall = isiPhone;874 var isRetina = opts.xcodeVersion[0] !== '4';875 var is64bit = false;876 var deviceName = opts.deviceName;877 var fixDevice = true;878 if (deviceName && deviceName[0] === '=') {879 return deviceName.substring(1);880 }881 logger.debug("fixDevice is " + (fixDevice ? "on" : "off"));882 if (deviceName) {883 var device = deviceName.toLowerCase();884 if (device.indexOf("iphone") !== -1) {885 isiPhone = true;886 } else if (device.indexOf("ipad") !== -1) {887 isiPhone = false;888 }889 if (deviceName !== opts.platformName) {890 isTall = isiPhone && (device.indexOf("4-inch") !== -1);891 isRetina = (device.indexOf("retina") !== -1);892 is64bit = (device.indexOf("64-bit") !== -1);893 }894 }895 var iosDeviceString = isiPhone ? "iPhone" : "iPad";896 if (xcodeMajorVer === 4) {897 if (isiPhone && isRetina) {898 iosDeviceString += isTall ? " (Retina 4-inch)" : " (Retina 3.5-inch)";899 } else {900 iosDeviceString += isRetina ? " (Retina)" : "";901 }902 } else if (xcodeMajorVer === 5) {903 iosDeviceString += isRetina ? " Retina" : "";904 if (isiPhone) {905 if (isRetina && isTall) {906 iosDeviceString += is64bit ? " (4-inch 64-bit)" : " (4-inch)";907 } else if (deviceName.toLowerCase().indexOf("3.5") !== -1) {908 iosDeviceString += " (3.5-inch)";909 }910 } else {911 iosDeviceString += is64bit ? " (64-bit)" : "";912 }913 } else if (_.contains([6, 7], xcodeMajorVer)) {914 iosDeviceString = opts.deviceName ||915 (isiPhone ? "iPhone Simulator" : "iPad Simulator");916 }917 var reqVersion = opts.platformVersion || opts.iOSSDKVersion;918 if (opts.iOSSDKVersion >= 8 && xcodeMajorVer === 7) {919 iosDeviceString += " (" + reqVersion + ")";920 } else if (opts.iOSSDKVersion >= 8) {921 iosDeviceString += " (" + reqVersion + " Simulator)";922 } else if (opts.iOSSDKVersion >= 7.1) {923 iosDeviceString += " - Simulator - iOS " + reqVersion;924 }925 if (fixDevice) {926 // Some device config are broken in 5.1927 var CONFIG_FIX = {928 'iPhone - Simulator - iOS 7.1': 'iPhone Retina (4-inch 64-bit) - ' +929 'Simulator - iOS 7.1',930 'iPad - Simulator - iOS 7.1': 'iPad Retina (64-bit) - Simulator - ' +931 'iOS 7.1',932 'iPad Simulator (8.0 Simulator)': 'iPad 2 (8.0 Simulator)',933 'iPad Simulator (8.1 Simulator)': 'iPad 2 (8.1 Simulator)',934 'iPad Simulator (8.2 Simulator)': 'iPad 2 (8.2 Simulator)',935 'iPad Simulator (8.3 Simulator)': 'iPad 2 (8.3 Simulator)',936 'iPad Simulator (8.4 Simulator)': 'iPad 2 (8.4 Simulator)',937 'iPad Simulator (7.1 Simulator)': 'iPad 2 (7.1 Simulator)',938 'iPhone Simulator (8.4 Simulator)': 'iPhone 6 (8.4 Simulator)',939 'iPhone Simulator (8.3 Simulator)': 'iPhone 6 (8.3 Simulator)',940 'iPhone Simulator (8.2 Simulator)': 'iPhone 6 (8.2 Simulator)',941 'iPhone Simulator (8.1 Simulator)': 'iPhone 6 (8.1 Simulator)',942 'iPhone Simulator (8.0 Simulator)': 'iPhone 6 (8.0 Simulator)',943 'iPhone Simulator (7.1 Simulator)': 'iPhone 5s (7.1 Simulator)'944 };945 // For xcode major version 7946 var CONFIG_FIX__XCODE_7 = {947 'iPad Simulator (8.1)': 'iPad 2 (8.1)',948 'iPad Simulator (8.2)': 'iPad 2 (8.2)',949 'iPad Simulator (8.3)': 'iPad 2 (8.3)',950 'iPad Simulator (8.4)': 'iPad 2 (8.4)',951 'iPhone Simulator (8.1)': 'iPhone 6 (8.1)',952 'iPhone Simulator (8.2)': 'iPhone 6 (8.2)',953 'iPhone Simulator (8.3)': 'iPhone 6 (8.3)',954 'iPhone Simulator (8.4)': 'iPhone 6 (8.4)',955 'iPad Simulator (9.0)': 'iPad 2 (9.0)',956 'iPad Simulator (9.1)': 'iPad 2 (9.1)',957 // Fixing ambiguous device name by adding '[' at the end so intruments958 // correctly starts iPhone 6 [udid] and not the iPhone 6 (9.0) + Apple Watch959 // for ios9.0 and above; see #5619960 'iPhone Simulator (9.0)': 'iPhone 6 (9.0) [',961 'iPhone Simulator (9.1)': 'iPhone 6 (9.1) [',962 'iPhone 6 (9.0)': 'iPhone 6 (9.0) [',963 'iPhone 6 (9.1)': 'iPhone 6 (9.1) ['964 };965 var configFix = xcodeMajorVer === 7 ? CONFIG_FIX__XCODE_7 : CONFIG_FIX;966 if (configFix[iosDeviceString]) {967 var oldDeviceString = iosDeviceString;968 iosDeviceString = configFix[iosDeviceString];969 logger.debug("Fixing device. Changed from: \"" + oldDeviceString +970 "\" to: \"" + iosDeviceString + "\"");971 }972 }973 logger.debug("Final device string is: '" + iosDeviceString + "'");974 return iosDeviceString;975};976IOS.prototype.getDeviceString = function () {977 var opts = _.clone(this.args);978 _.extend(opts, {979 xcodeVersion: this.xcodeVersion,980 iOSSDKVersion: this.iOSSDKVersion981 });982 return IOS.getDeviceStringFromOpts(opts);983};984IOS.prototype.setDeviceTypeInInfoPlist = function (cb) {985 var plist = path.resolve(this.args.app, "Info.plist");986 var dString = this.getDeviceString();987 var isiPhone = dString.toLowerCase().indexOf("ipad") === -1;988 var deviceTypeCode = isiPhone ? 1 : 2;989 parsePlistFile(plist, function (err, obj) {990 if (err) {991 logger.error("Could not set the device type in Info.plist");992 return cb(err, null);993 } else {994 var newPlist;995 obj.UIDeviceFamily = [deviceTypeCode];996 if (binaryPlist) {997 newPlist = bplistCreate(obj);998 } else {999 newPlist = xmlplist.build(obj);1000 }1001 fs.writeFile(plist, newPlist, function (err) {1002 if (err) {1003 logger.error("Could not save new Info.plist");1004 cb(err);1005 } else {1006 logger.debug("Wrote new app Info.plist with device type");1007 cb();1008 }1009 }.bind(this));1010 }1011 }.bind(this));1012};1013IOS.prototype.getBundleIdFromApp = function (cb) {1014 logger.debug("Getting bundle ID from app");1015 var plist = path.resolve(this.args.app, "Info.plist");1016 parsePlistFile(plist, function (err, obj) {1017 if (err) {1018 logger.error("Could not get the bundleId from app.");1019 cb(err, null);1020 } else {1021 cb(null, obj.CFBundleIdentifier);1022 }1023 }.bind(this));1024};1025IOS.getSimForDeviceString = function (dString, availDevices) {1026 var matchedDevice = null;1027 var matchedUdid = null;1028 _.each(availDevices, function (device) {1029 if (device.indexOf(dString) !== -1) {1030 matchedDevice = device;1031 try {1032 matchedUdid = /.+\[([^\]]+)\]/.exec(device)[1];1033 } catch (e) {1034 matchedUdid = null;1035 }1036 }1037 });1038 return [matchedDevice, matchedUdid];1039};1040IOS.prototype.checkSimAvailable = function (cb) {1041 if (this.args.udid) {1042 logger.debug("Not checking whether simulator is available since we're on " +1043 "a real device");1044 return cb();1045 }1046 if (this.iOSSDKVersion < 7.1) {1047 logger.debug("Instruments v < 7.1, not checking device string support");1048 return cb();1049 }1050 logger.debug("Checking whether instruments supports our device string");1051 Instruments.getAvailableDevicesWithRetry(3, function (err, availDevices) {1052 if (err) return cb(err);1053 var noDevicesError = function () {1054 var msg = "Could not find a device to launch. You requested '" +1055 dString + "', but the available devices were: " +1056 JSON.stringify(availDevices);1057 logger.error(msg);1058 cb(new Error(msg));1059 };1060 var dString = this.getDeviceString();1061 if (this.iOSSDKVersion >= 8) {1062 var sim = IOS.getSimForDeviceString(dString, availDevices);1063 if (sim[0] === null || sim[1] === null) {1064 return noDevicesError();1065 }1066 this.iOSSimUdid = sim[1];1067 logger.debug("iOS sim UDID is " + this.iOSSimUdid);1068 return cb();1069 } else if (!_.contains(availDevices, dString)) {1070 return noDevicesError();1071 }1072 cb();1073 }.bind(this));1074};1075IOS.prototype.setDeviceInfo = function (cb) {1076 this.shouldPrelaunchSimulator = false;1077 if (this.args.udid) {1078 logger.debug("Not setting device type since we're on a real device");1079 return cb();1080 }1081 if (!this.args.app && this.args.bundleId) {1082 logger.debug("Not setting device type since we're using bundle ID and " +1083 "assuming app is already installed");1084 return cb();1085 }1086 if (!this.args.deviceName &&1087 this.args.forceIphone === null &&1088 this.args.forceIpad === null) {1089 logger.debug("No device specified, current device in the iOS " +1090 "simulator will be used.");1091 return cb();1092 }1093 if (this.args.defaultDevice || this.iOSSDKVersion >= 7.1) {1094 if (this.iOSSDKVersion >= 7.1) {1095 logger.debug("We're on iOS7.1+ so forcing defaultDevice on");1096 } else {1097 logger.debug("User specified default device, letting instruments launch it");1098 }1099 } else {1100 this.shouldPrelaunchSimulator = true;1101 }1102 this.setDeviceTypeInInfoPlist(cb);1103};1104IOS.prototype.createSimulator = function (cb) {1105 this.sim = new Simulator({1106 platformVer: this.args.platformVersion,1107 sdkVer: this.iOSSDKVersion,1108 udid: this.iOSSimUdid1109 });1110 cb();1111};1112IOS.prototype.moveBuiltInApp = function (cb) {1113 if (this.appString().toLowerCase() === "settings") {1114 logger.debug("Trying to use settings app, version " +1115 this.args.platformVersion);1116 this.sim.preparePreferencesApp(this.args.tmpDir, function (err, attemptedApp, origApp) {1117 if (err) {1118 logger.error("Could not prepare settings app: " + err);1119 return cb(err);1120 }1121 logger.debug("Using settings app at " + attemptedApp);1122 this.args.app = attemptedApp;1123 this.args.origAppPath = origApp;1124 cb();1125 }.bind(this));1126 } else {1127 cb();1128 }1129};1130IOS.prototype.prelaunchSimulator = function (cb) {1131 var msg;1132 if (!this.shouldPrelaunchSimulator) {1133 logger.debug("Not pre-launching simulator");1134 return cb();1135 }1136 xcode.getPath(function (err, xcodePath) {1137 if (err) {1138 return cb(new Error('Could not find xcode folder. Needed to start simulator. ' + err.message));1139 }1140 logger.debug("Pre-launching simulator");1141 var iosSimPath = path.resolve(xcodePath,1142 "Platforms/iPhoneSimulator.platform/Developer/Applications" +1143 "/iPhone Simulator.app/Contents/MacOS/iPhone Simulator");1144 if (!fs.existsSync(iosSimPath)) {1145 msg = "Could not find ios simulator binary at " + iosSimPath;1146 logger.error(msg);1147 return cb(new Error(msg));1148 }1149 this.endSimulator(function (err) {1150 if (err) return cb(err);1151 logger.debug("Launching device: " + this.getDeviceString());1152 var iosSimArgs = ["-SimulateDevice", this.getDeviceString()];1153 this.iosSimProcess = spawn(iosSimPath, iosSimArgs);1154 var waitForSimulatorLogs = function (countdown) {1155 if (countdown <= 0 ||1156 (this.logs.syslog && (this.logs.syslog.getAllLogs().length > 0 ||1157 (this.logs.crashlog && this.logs.crashlog.getAllLogs().length > 0)))) {1158 logger.debug(countdown > 0 ? "Simulator is now ready." :1159 "Waited 10 seconds for simulator to start.");1160 cb();1161 } else {1162 setTimeout(function () {1163 waitForSimulatorLogs(countdown - 1);1164 }, 1000);1165 }1166 }.bind(this);1167 waitForSimulatorLogs(10);1168 }.bind(this));1169 }.bind(this));1170};1171IOS.prototype.parseLocalizableStrings = function (/* language, stringFile, cb */) {1172 var args = new Args(arguments);1173 var cb = args.callback;1174 if (this.args.app === null) {1175 logger.debug("Localizable.strings is not currently supported when using real devices.");1176 return cb();1177 }1178 var language = args.all[0] || this.args.language1179 , stringFile = args.all[1] || "Localizable.strings"1180 , strings = null;1181 if (language) {1182 strings = path.resolve(this.args.app, language + ".lproj", stringFile);1183 }1184 if (!fs.existsSync(strings)) {1185 if (language) {1186 logger.debug("No strings file '" + stringFile + "' for language '" + language + "', getting default strings");1187 }1188 strings = path.resolve(this.args.app, stringFile);1189 }1190 if (!fs.existsSync(strings)) {1191 strings = path.resolve(this.args.app, this.args.localizableStringsDir, stringFile);1192 }1193 parsePlistFile(strings, function (err, obj) {1194 if (err) {1195 logger.warn("Could not parse app " + stringFile +" assuming it " +1196 "doesn't exist");1197 } else {1198 logger.debug("Parsed app " + stringFile);1199 this.localizableStrings = obj;1200 }1201 cb();1202 }.bind(this));1203};1204IOS.prototype.deleteSim = function (cb) {1205 this.sim.deleteSim(cb);1206};1207IOS.prototype.clearAppData = function (cb) {1208 if (!this.keepAppToRetainPrefs && this.args.app && this.args.bundleId) {1209 this.sim.cleanCustomApp(path.basename(this.args.app), this.args.bundleId);1210 }1211 cb();1212};1213IOS.prototype.cleanupSimState = function (cb) {1214 if (this.realDevice && this.args.bundleId && this.args.fullReset) {1215 logger.debug("fullReset requested. Will try to uninstall the app.");1216 var bundleId = this.args.bundleId;1217 this.realDevice.remove(bundleId, function (err) {1218 if (err) {1219 this.removeApp(bundleId, function (err) {1220 if (err) {1221 logger.error("Could not remove " + bundleId + " from device");1222 cb(err);1223 } else {1224 logger.debug("Removed " + bundleId);1225 cb();1226 }1227 }.bind(this));1228 } else {1229 logger.debug("Removed " + bundleId);1230 cb();1231 }1232 }.bind(this));1233 } else if (!this.args.udid) {1234 this.sim.cleanSim(this.args.keepKeyChains, this.args.tmpDir, function (err) {1235 if (err) {1236 logger.error("Could not reset simulator. Leaving as is. Error: " + err.message);1237 }1238 this.clearAppData(cb);1239 }.bind(this));1240 } else {1241 logger.debug("On a real device; cannot clean device state");1242 cb();1243 }1244};1245IOS.prototype.runSimReset = function (cb) {1246 if (this.args.reset || this.args.fullReset) {1247 logger.debug("Running ios sim reset flow");1248 // The simulator process must be ended before we delete applications.1249 async.series([1250 this.endSimulator.bind(this),1251 function (cb) {1252 if (this.args.reset) {1253 this.cleanupSimState(cb);1254 } else {1255 cb();1256 }1257 }.bind(this),1258 function (cb) {1259 if (this.args.fullReset && !this.args.udid) {1260 this.deleteSim(cb);1261 } else {1262 cb();1263 }1264 }.bind(this)1265 ], cb);1266 } else {1267 logger.debug("Reset not set, not ending sim or cleaning up app state");1268 cb();1269 }1270};1271IOS.prototype.isolateSimDevice = function (cb) {1272 if (!this.args.udid && this.args.isolateSimDevice &&1273 this.iOSSDKVersion >= 8) {1274 this.sim.deleteOtherSims(cb);1275 } else {1276 cb();1277 }1278};1279IOS.prototype.postCleanup = function (cb) {1280 this.curCoords = null;1281 this.curOrientation = null;1282 if (!_.isEmpty(this.logs)) {1283 this.logs.syslog.stopCapture();1284 this.logs = {};1285 }1286 if (this.remote) {1287 this.stopRemote();1288 }1289 this.runSimReset(function () {1290 // ignore any errors during reset and continue shutting down1291 this.isShuttingDown = false;1292 cb();1293 }.bind(this));1294};1295IOS.prototype.endSimulator = function (cb) {1296 logger.debug("Killing the simulator process");1297 if (this.iosSimProcess) {...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...164 // postcleanup165 this.curCoords = null;166 this.opts.curOrientation = null;167 if (!_.isEmpty(this.logs)) {168 await this.logs.syslog.stopCapture();169 this.logs = {};170 }171 if (this.remote) {172 await this.stopRemote();173 }174 await this.stopIWDP();175 }176 async deleteSession () {177 logger.debug('Deleting ios session');178 await this.stop();179 if (this.opts.clearSystemFiles) {180 await utils.clearLogs(LOG_LOCATIONS);181 } else {182 logger.debug('Not clearing log files. Use `clearSystemFiles` capability to turn on.');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .then(function (client) {9 return client.logs('syslog')10 .then(function (logs) {11 return client.logs('syslog').stopCapture()12 .then(function (logs) {13 console.log(logs);14 return client.end();15 });16 });17 })18 .catch(function (err) {19 console.log(err);20 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { exec } = require('child_process');3async function main() {4 await driver.init({5 });6 await driver.setImplicitWaitTimeout(60000);7 await driver.getLogs('syslog');8 await driver.logs.syslog.stopCapture();9 await driver.quit();10}11main();12const wd = require('wd');13const { exec } = require('child_process');14async function main() {15 await driver.init({16 });17 await driver.setImplicitWaitTimeout(60000);18 await driver.getLogs('syslog');19 await driver.logs.syslog.stopCapture();20 await driver.quit();21}22main();23driver.getLogs('syslog')24driver.logs.syslog.stopCapture()

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var logs = require('wd/lib/commands').logs;4var logger = require('wd/lib/logger');5var appium = require('appium');6var desired = {7};8var driver = wd.promiseChainRemote('localhost', 4723);9driver.init(desired);10 .then(function () {11 return driver.logs.syslog.startCapture();12 })13 .then(function () {14 return driver.sleep(10000);15 })16 .then(function () {17 return driver.logs.syslog.stopCapture();18 })19 .then(function (logs) {20 console.log('logs: ', logs);21 })22 .catch(function (err) {23 console.log('error: ', err);24 });25var wd = require('wd');26var assert = require('assert');27var logs = require('wd/lib/commands').logs;28var logger = require('wd/lib/logger');29var appium = require('appium');30var desired = {31};32var driver = wd.promiseChainRemote('localhost', 4723);33driver.init(desired);34 .then(function () {35 return driver.logs.syslog.startCapture();36 })37 .then(function () {38 return driver.sleep(10000);39 })40 .then(function () {41 return driver.logs.syslog.stopCapture();42 })43 .then(function (logs) {44 console.log('logs: ', logs);45 })46 .catch(function (err) {47 console.log('error: ', err);48 });49var wd = require('wd');50var assert = require('assert');51var logs = require('wd/lib/commands').logs;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful