How to use _mergeLaunchArgs method in root

Best JavaScript code snippet using root

AppleSimUtils.js

Source:AppleSimUtils.js Github

copy

Full Screen

...101 printLaunchHint(udid, bundleId, launchArgs, languageAndLocale) {102 log.info({},103 'Waiting for you to manually launch your app in Xcode.\n' +104 'Make sure to pass the launch arguments listed below:\n' +105 this._mergeLaunchArgs(launchArgs, languageAndLocale).map(pair => ` ${pair}\n`).join(''),106 '\nPress any key to continue...'107 );108 }109 async sendToHome(udid) {110 await this._execSimctl({ cmd: `launch ${udid} com.apple.springboard`, retries: 10 });111 }112 async matchBiometric(udid, matchType) {113 if (!_.includes(['Face', 'Finger'], matchType)) {114 return;115 }116 const options = {117 args: `--byId ${udid} --match${matchType}`,118 retries: 1,119 statusLogs: {120 trying: `Trying to match ${matchType}...`,121 successful: `Matched ${matchType}!`122 },123 };124 await this._execAppleSimUtils(options);125 }126 async unmatchBiometric(udid, matchType) {127 if (!_.includes(['Face', 'Finger'], matchType)) {128 return;129 }130 const options = {131 args: `--byId ${udid} --unmatch${matchType}`,132 retries: 1,133 statusLogs: {134 trying: `Trying to unmatch ${matchType}...`,135 successful: `Unmatched ${matchType}!`136 },137 }138 await this._execAppleSimUtils(options);139 }140 async setBiometricEnrollment(udid, yesOrNo) {141 if (!_.includes(['YES', 'NO'], yesOrNo)) {142 return;143 }144 const toggle = yesOrNo === 'YES';145 const options = {146 args: `--byId ${udid} --biometricEnrollment ${yesOrNo}`,147 retries: 1,148 statusLogs: {149 trying: `Turning ${toggle ? 'on' : 'off'} biometric enrollment...`,150 successful: toggle ? 'Activated!' : 'Deactivated!'151 },152 }153 await this._execAppleSimUtils(options);154 }155 async clearKeychain(udid) {156 const options = {157 args: `--byId ${udid} --clearKeychain`,158 retries: 1,159 statusLogs: {160 trying: `Clearing Keychain...`,161 successful: 'Cleared Keychain!'162 },163 }164 await this._execAppleSimUtils(options);165 }166 async getAppContainer(udid, bundleId) {167 return _.trim((await this._execSimctl({ cmd: `get_app_container ${udid} ${bundleId}` })).stdout);168 }169 logStream({ udid, stdout, level, processImagePath, style }) {170 const args = ['simctl', 'spawn', udid, 'log', 'stream'];171 if (level) {172 args.push('--level');173 args.push(level);174 }175 if (style) {176 args.push('--style');177 args.push(style);178 }179 if (processImagePath) {180 args.push('--predicate');181 args.push(`processImagePath beginsWith "${processImagePath}"`);182 }183 const promise = exec.spawnAndLog('/usr/bin/xcrun', args, {184 stdio: ['ignore', stdout, 'ignore'],185 silent: true,186 });187 return promise;188 }189 async terminate(udid, bundleId) {190 const statusLogs = {191 trying: `Terminating ${bundleId}...`,192 successful: `${bundleId} terminated`193 };194 try {195 await this._execSimctl({196 cmd: `terminate ${udid} ${bundleId}`,197 statusLogs: statusLogs,198 silent: true199 });200 } catch (err) {201 // Since we have no convenient way to check whether the app is currently running or not, we might execute this202 // command (terminate) even if the app is not currently running, or even installed.203 // We have encountered some case where the following error is thrown in a case where the app did not run:204 // ```205 // An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=3):206 // Application termination failed.207 // FBSSystemService reported failure without an error, possibly because the app is not currently running.208 // ```209 // This workaround is done to ignore the error above, as we do not care if the app was running before, we just210 // want to make sure it isn't now.211 if (err.code === 3 && err.stderr.includes(`the app is not currently running`)) {212 return213 }214 throw err215 }216 }217 async shutdown(udid) {218 const statusLogs = {219 trying: `Shutting down ${udid}...`,220 successful: `${udid} shut down`221 };222 await this._execSimctl({ cmd: `shutdown ${udid}`, statusLogs });223 }224 async openUrl(udid, url) {225 await this._execSimctl({ cmd: `openurl ${udid} ${url}` });226 }227 async setLocation(udid, lat, lon) {228 const result = await exec.execWithRetriesAndLogs(`which fbsimctl`, { retries: 1 });229 if (_.get(result, 'stdout')) {230 await exec.execWithRetriesAndLogs(`fbsimctl ${udid} set_location ${lat} ${lon}`, { retries: 1 });231 } else {232 throw new Error(`setLocation currently supported only through fbsimctl.233 Install fbsimctl using:234 "brew tap facebook/fb && export CODE_SIGNING_REQUIRED=NO && brew install fbsimctl"`);235 }236 }237 async resetContentAndSettings(udid) {238 await this._execSimctl({ cmd: `erase ${udid}` });239 }240 async takeScreenshot(udid, destination) {241 await this._execSimctl({242 cmd: `io ${udid} screenshot "${destination}"`,243 silent: destination === '/dev/null',244 });245 }246 recordVideo(udid, destination, options = {}) {247 const args = ['simctl', 'io', udid, 'recordVideo', destination];248 if (options.codec) {249 args.push('--codec');250 args.push(options.codec);251 }252 return exec.spawnAndLog('/usr/bin/xcrun', args);253 }254 async _execAppleSimUtils(options) {255 const bin = `applesimutils`;256 return await exec.execWithRetriesAndLogs(bin, options);257 }258 async _execSimctl({ cmd, statusLogs = {}, retries = 1, silent = false }) {259 const options = {260 verbosity: silent ? 'low' : 'normal',261 statusLogs,262 retries,263 }264 return await exec.execWithRetriesAndLogs(`/usr/bin/xcrun simctl ${cmd}`, options);265 }266 _parseResponseFromAppleSimUtils(response) {267 let out = _.get(response, 'stdout');268 if (_.isEmpty(out)) {269 out = _.get(response, 'stderr');270 }271 if (_.isEmpty(out)) {272 return undefined;273 }274 let parsed;275 try {276 parsed = JSON.parse(out);277 } catch (ex) {278 throw new Error(`Could not parse response from applesimutils, please update applesimutils and try again.279 'brew uninstall applesimutils && brew tap wix/brew && brew install applesimutils'`);280 }281 return parsed;282 }283 _mergeLaunchArgs(launchArgs, languageAndLocale) {284 const args = {285 ...launchArgs,286 };287 if (languageAndLocale) {288 if (languageAndLocale.language) {289 args.AppleLanguages = `(${languageAndLocale.language})`;290 }291 if (languageAndLocale.locale) {292 args.AppleLocale = languageAndLocale.locale;293 }294 }295 return _.map(args, (v, k) => `-${k} "${v}"`); // TODO: replace naive quoting296 }297 async _launchMagically(frameworkPath, udid, bundleId, launchArgs, languageAndLocale) {298 let dylibs = `${frameworkPath}/Detox`;299 if (process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES) {300 dylibs = `${process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES}:${dylibs}`;301 }302 const cmdArgs = this._mergeLaunchArgs(launchArgs, languageAndLocale).join(' ');303 let launchBin = `SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="${dylibs}" ` +304 `/usr/bin/xcrun simctl launch ${udid} ${bundleId} --args ${cmdArgs}`;305 const result = await exec.execWithRetriesAndLogs(launchBin, {306 retries: 1,307 statusLogs: {308 trying: `Launching ${bundleId}...`,309 },310 });311 return result;312 }313 async _printLoggingHint(udid, bundleId) {314 const appContainer = await this.getAppContainer(udid, bundleId);315 const CFBundleExecutable = await exec.execAsync(`/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" "${path.join(appContainer, 'Info.plist')}"`);316 const predicate = `process == "${CFBundleExecutable}"`;...

Full Screen

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 root automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful