Skip to content

Commit

Permalink
add a prodigious number of potentially interesting events
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Mar 4, 2017
1 parent 7e15404 commit 7214491
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class XCUITestDriver extends BaseDriver {
throw Error(`Platform version must be 9.3 or above. '${this.opts.platformVersion}' is not supported.`);
}

this.logEvent('xcodeDetailsRetrieved');

let {device, udid, realDevice} = await this.determineDevice();
log.info(`Determining device to run tests on: udid: '${udid}', real device: ${realDevice}`);
this.opts.device = device;
Expand All @@ -217,6 +219,7 @@ class XCUITestDriver extends BaseDriver {

if (this.isSimulator() && this.opts.customSSLCert) {
await installSSLCert(this.opts.customSSLCert, this.opts.udid);
this.logEvent('customCertInstalled');
}

// at this point if there is no platformVersion, get it from the device
Expand Down Expand Up @@ -251,6 +254,7 @@ class XCUITestDriver extends BaseDriver {
} else {
await this.configureApp();
}
this.logEvent('appConfigured');

// fail very early if the app doesn't actually exist
if (this.opts.app) {
Expand All @@ -276,12 +280,14 @@ class XCUITestDriver extends BaseDriver {

// handle logging
await this.startLogCapture();
this.logEvent('logCaptureStarted');

log.info(`Setting up ${this.isRealDevice() ? 'real device' : 'simulator'}`);

if (this.isRealDevice()) {
if (this.opts.app) {
await this.installApp();
this.logEvent('appInstalled');
}
} else {
this.localeConfig = await iosSettings.setLocale(this.opts.device, this.opts, {}, this.isSafari());
Expand All @@ -304,28 +310,34 @@ class XCUITestDriver extends BaseDriver {
}
}
await this.startSim();
this.logEvent('simStarted');
await installAppPromise;
this.logEvent('appInstalled');
}

await this.startWda(this.opts.sessionId, realDevice);

await this.setInitialOrientation(this.opts.orientation);
this.logEvent('orientationSet');

if (this.isSafari() || this.opts.autoWebview) {
log.debug('Waiting for initial webview');
await this.navToInitialWebview();
this.logEvent('initialWebviewNavigated');
}
}

async startWda (sessionId, realDevice) {
let startupRetries = this.opts.wdaStartupRetries || WDA_STARTUP_RETRIES;
let startupRetryInterval = this.opts.wdaStartupRetryInterval || WDA_STARTUP_RETRY_INTERVAL;
await retryInterval(startupRetries, startupRetryInterval, async () => {
this.logEvent('wdaStartAttempted');
this.wda = new WebDriverAgent(this.xcodeVersion, this.opts);

if (this.opts.useNewWDA) {
log.debug(`Capability 'useNewWDA' set, so uninstalling WDA before proceeding`);
await this.wda.uninstall();
this.logEvent('wdaUninstalled');
}

// local helper for the two places we need to uninstall wda and re-start it
Expand All @@ -341,6 +353,7 @@ class XCUITestDriver extends BaseDriver {
try {
wdaStatus = await this.wda.launch(sessionId, realDevice);
} catch (err) {
this.logEvent('wdaStartFailed');
await quitAndUninstall(`Unable to launch WebDriverAgent because of xcodebuild failure: ${err.message}`);
}

Expand All @@ -349,6 +362,7 @@ class XCUITestDriver extends BaseDriver {

try {
await retryInterval(15, 1000, async () => {
this.logEvent('wdaSessionAttempted');
log.debug('Sending createSession command to WDA');
try {
if (wdaStatus) {
Expand All @@ -363,16 +377,19 @@ class XCUITestDriver extends BaseDriver {
throw err;
}
});
this.logEvent('wdaSessionStarted');
} catch (err) {
return await quitAndUninstall(`Unable to start WebDriverAgent session: ${err.message}`);
}

this.opts.preventWDAAttachments = !util.hasValue(this.opts.preventWDAAttachments) || this.opts.preventWDAAttachments;
await adjustWDAAttachmentsPermissions(this.opts.preventWDAAttachments ? '555' : '755');
this.logEvent('wdaPermsAdjusted');

// we expect certain socket errors until this point, but now
// mark things as fully working
this.wda.fullyStarted = true;
this.logEvent('wdaStarted');
});
}

Expand All @@ -383,11 +400,13 @@ class XCUITestDriver extends BaseDriver {
}

async runReset () {
this.logEvent('resetStarted');
if (this.isRealDevice()) {
await runRealDeviceReset(this.opts.device, this.opts);
} else {
await runSimulatorReset(this.opts.device, this.opts);
}
this.logEvent('resetComplete');
}

async deleteSession () {
Expand Down Expand Up @@ -582,6 +601,7 @@ class XCUITestDriver extends BaseDriver {
async launchApp () {
const APP_LAUNCH_TIMEOUT = 20 * 1000;

this.logEvent('appLaunchAttempted');
await launch(this.opts.device.udid, this.opts.bundleId);

let checkStatus = async () => {
Expand All @@ -596,6 +616,7 @@ class XCUITestDriver extends BaseDriver {
let retries = parseInt(APP_LAUNCH_TIMEOUT / 200, 10);
await retryInterval(retries, 200, checkStatus);
log.info(`${this.opts.bundleId} is in foreground`);
this.logEvent('appLaunched');
}

async startWdaSession (bundleId, processArguments) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lib": "lib"
},
"dependencies": {
"appium-base-driver": "^2.4.0",
"appium-base-driver": "^2.4.1",
"appium-ios-driver": "^1.15.1",
"appium-ios-simulator": "^1.17.1",
"appium-support": "^2.4.0",
Expand Down

0 comments on commit 7214491

Please sign in to comment.