mirror of
https://github.com/appium/appium.git
synced 2026-05-13 06:18:42 -05:00
remove need for things other than safari.js to know about SafariLauncher
This commit is contained in:
+9
-31
@@ -220,15 +220,7 @@ Appium.prototype.invoke = function (cb) {
|
||||
cb(null, this.device);
|
||||
}.bind(this);
|
||||
|
||||
var onDie = function () {
|
||||
// if we're using the safari launcher app, don't end the session when
|
||||
// instruments inevitably crashes out
|
||||
if (this.device.dontCleanupSession) {
|
||||
this.cleanupSession();
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
this.device.start(onStart, onDie);
|
||||
this.device.start(onStart, this.cleanupSession.bind(this));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -328,33 +320,19 @@ Appium.prototype.stop = function (cb) {
|
||||
}
|
||||
|
||||
logger.info('Shutting down appium session...');
|
||||
// TODO get this out of appium.js
|
||||
if (this.isSafariLauncherApp === true) {
|
||||
syntasdfasdf
|
||||
this.device.closeWindow(function () {
|
||||
if (this.device.udid === null && this.device.instruments !== null) {
|
||||
this.device.instruments.shutdown(function () {
|
||||
this.cleanupSession(null, cb);
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.cleanupSession(null, cb);
|
||||
}
|
||||
}.bind(this));
|
||||
} else {
|
||||
this.device.stop(function (code) {
|
||||
var err;
|
||||
if (code && code > 0) {
|
||||
err = new Error("Device exited with code: " + code);
|
||||
}
|
||||
this.cleanupSession(err, cb);
|
||||
}.bind(this));
|
||||
}
|
||||
this.device.stop(function (code) {
|
||||
var err;
|
||||
if (code && code > 0) {
|
||||
err = new Error("Device exited with code: " + code);
|
||||
}
|
||||
this.cleanupSession(err, cb);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
||||
Appium.prototype.reset = function (cb) {
|
||||
logger.info("Resetting app mid-session");
|
||||
if ((this.isIos() && !this.device.instruments.udid) || !this.fastReset) {
|
||||
if ((this.isIos() && !this.device.instruments.udid) || !this.args.fastReset) {
|
||||
var oldImpWait = this.device.implicitWaitMs
|
||||
, oldCommandTimeout = this.commandTimeoutMs
|
||||
, oldId = this.sessionId;
|
||||
|
||||
@@ -24,7 +24,7 @@ iOSHybrid.closeAlertBeforeTest = function (cb) {
|
||||
|
||||
iOSHybrid.listWebFrames = function (cb, exitCb) {
|
||||
var isDone = false;
|
||||
if (!this.args.bundleId && !this.args.isSafariLauncherApp) {
|
||||
if (!this.args.bundleId) {
|
||||
logger.error("Can't enter web frame without a bundle ID");
|
||||
return cb(new Error("Tried to enter web frame without a bundle ID"));
|
||||
}
|
||||
@@ -159,30 +159,31 @@ iOSHybrid.onPageChange = function (pageArray) {
|
||||
|
||||
iOSHybrid.getAtomsElement = deviceCommon.getAtomsElement;
|
||||
|
||||
iOSHybrid.stopRemote = function () {
|
||||
iOSHybrid.stopRemote = function (closeWindowBeforeDisconnecting) {
|
||||
if (typeof closeWindowBeforeDisconnecting === "undefined") {
|
||||
closeWindowBeforeDisconnecting = false;
|
||||
}
|
||||
if (!this.remote) {
|
||||
logger.error("We don't appear to be in a web frame");
|
||||
throw new Error("Tried to leave a web frame but weren't in one");
|
||||
} else {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
this.closeWindow(function () {
|
||||
if (this.args.udid) {
|
||||
this.remote.disconnect(function () {});
|
||||
} else {
|
||||
this.remote.disconnect();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var disconnect = function () {
|
||||
if (this.args.udid) {
|
||||
this.remote.disconnect(function () {});
|
||||
} else {
|
||||
this.remote.disconnect();
|
||||
}
|
||||
this.curWindowHandle = null;
|
||||
this.curWebFrames = [];
|
||||
this.curWebCoords = null;
|
||||
this.remote = null;
|
||||
}.bind(this);
|
||||
|
||||
if (closeWindowBeforeDisconnecting) {
|
||||
this.closeWindow(disconnect);
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
this.curWindowHandle = null;
|
||||
this.curWebFrames = [];
|
||||
this.curWebCoords = null;
|
||||
this.remote = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+8
-31
@@ -96,6 +96,7 @@ IOS.prototype.init = function () {
|
||||
IOS.prototype._deviceConfigure = Device.prototype.configure;
|
||||
IOS.prototype.configure = function (args, caps, cb) {
|
||||
this._deviceConfigure(args, caps);
|
||||
this.setIOSArgs();
|
||||
if (this.args.app) {
|
||||
this.configureApp(cb);
|
||||
} else {
|
||||
@@ -105,7 +106,7 @@ IOS.prototype.configure = function (args, caps, cb) {
|
||||
}
|
||||
};
|
||||
|
||||
IOS.prototype.initArgs = function () {
|
||||
IOS.prototype.setIOSArgs = function () {
|
||||
this.args.withoutDelay = !this.args.nativeInstrumentsLib;
|
||||
this.args.reset = !this.args.noReset;
|
||||
this.args.removeTraceDir = !this.args.keepArtifacts;
|
||||
@@ -290,7 +291,7 @@ IOS.prototype.makeInstruments = function () {
|
||||
return new Instruments({
|
||||
app: this.args.app || this.args.bundleId
|
||||
, udid: this.args.udid
|
||||
, isSafariLauncherApp: this.args.isSafariLauncherApp
|
||||
, ignoreStartupExit: this.shouldIgnoreInstrumentsExit()
|
||||
, bootstrap: path.resolve(__dirname, 'uiauto', 'bootstrap.js')
|
||||
, template: this.args.automationTraceTemplatePath
|
||||
, sock: sock
|
||||
@@ -303,6 +304,10 @@ IOS.prototype.makeInstruments = function () {
|
||||
});
|
||||
};
|
||||
|
||||
IOS.prototype.shouldIgnoreInstrumentsExit = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
IOS.prototype.onInstrumentsLaunch = function (cb) {
|
||||
logger.info('Instruments launched. Starting poll loop for new commands.');
|
||||
this.instruments.setDebug(true);
|
||||
@@ -315,14 +320,6 @@ IOS.prototype.onInstrumentsLaunch = function (cb) {
|
||||
};
|
||||
|
||||
IOS.prototype.setBundleId = function (cb) {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
if (!this.args.udid) {
|
||||
this.args.bundleId = "com.apple.mobilesafari";
|
||||
} else {
|
||||
this.args.bundleId = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (this.args.bundleId !== null) {
|
||||
cb();
|
||||
} else {
|
||||
@@ -336,10 +333,6 @@ IOS.prototype.setBundleId = function (cb) {
|
||||
};
|
||||
|
||||
IOS.prototype.setInitialOrientation = function (cb) {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
if (typeof this.args.initialOrientation === "string" &&
|
||||
_.contains(["LANDSCAPE", "PORTRAIT"],
|
||||
this.args.initialOrientation.toUpperCase())
|
||||
@@ -361,9 +354,6 @@ IOS.prototype.setInitialOrientation = function (cb) {
|
||||
};
|
||||
|
||||
IOS.prototype.setBootstrapConfig = function (cb) {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
return cb();
|
||||
}
|
||||
logger.info("Setting bootstrap config keys/values");
|
||||
var pre = "setBootstrapConfig: ";
|
||||
var cmd = pre + "autoAcceptAlerts=" + JSON.stringify(!!this.args.autoAcceptAlerts);
|
||||
@@ -657,9 +647,7 @@ IOS.prototype.detectUdid = function (cb) {
|
||||
|
||||
IOS.prototype.installToRealDevice = function (cb) {
|
||||
if (this.args.udid) {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
this.installSafariLauncher(cb);
|
||||
} else if (this.args.ipa && this.args.bundleId) {
|
||||
if (this.args.ipa && this.args.bundleId) {
|
||||
this.installIpa(cb);
|
||||
} else if (this.args.ipa) {
|
||||
var msg = "You specified a UDID and ipa but did not include the bundle " +
|
||||
@@ -684,17 +672,6 @@ IOS.prototype.installToRealDevice = function (cb) {
|
||||
}
|
||||
};
|
||||
|
||||
IOS.prototype.installSafariLauncher = function (cb) {
|
||||
this.isAppInstalled("com.bytearc.SafariLauncher", function (err) {
|
||||
if (err) {
|
||||
this.installApp(this.args.app, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
||||
IOS.prototype.getIDeviceObj = function () {
|
||||
var idiPath = path.resolve(__dirname, "../../../build/",
|
||||
"libimobiledevice-macosx/ideviceinstaller");
|
||||
|
||||
@@ -19,11 +19,10 @@ _.extend(Safari.prototype, IOS.prototype);
|
||||
Safari.prototype.configure = function (args, caps, cb) {
|
||||
logger.info("Configuring Safari session");
|
||||
this._deviceConfigure(args, caps);
|
||||
this.initArgs();
|
||||
this.setIOSArgs();
|
||||
this.capabilities.safari = true;
|
||||
if (this.args.udid) {
|
||||
this.dontCleanupSession = true;
|
||||
this.args.isSafariLauncherApp = true;
|
||||
this.args.app = path.resolve(__dirname,
|
||||
"../../../build/SafariLauncher/SafariLauncher.zip");
|
||||
this.configureLocalApp(cb);
|
||||
@@ -76,14 +75,25 @@ Safari.prototype.configureSafari = function (cb) {
|
||||
|
||||
Safari.prototype._start = IOS.prototype.start;
|
||||
Safari.prototype.start = function (cb, onDie) {
|
||||
var newOnDie = function (err) {
|
||||
if (this.args.udid) {
|
||||
return; // if we're using SafariLauncher, don't report failure
|
||||
}
|
||||
onDie(err);
|
||||
}.bind(this);
|
||||
|
||||
this._start(function (err) {
|
||||
if (err) return cb(err);
|
||||
this.navToInitialWebview(cb);
|
||||
}.bind(this), onDie);
|
||||
}.bind(this), newOnDie);
|
||||
};
|
||||
|
||||
Safari.prototype.shouldIgnoreInstrumentsExit = function () {
|
||||
return !!this.args.udid;
|
||||
};
|
||||
|
||||
Safari.prototype.navToInitialWebview = function (cb) {
|
||||
if (this.args.isSafariLauncherApp) {
|
||||
if (this.args.udid) {
|
||||
setTimeout(function () {
|
||||
//the latest window is the one newly created by Safari launcher.
|
||||
this.navToLatestAvailableWebview(cb);
|
||||
@@ -158,4 +168,59 @@ Safari.prototype.click = function (elementId, cb) {
|
||||
}
|
||||
};
|
||||
|
||||
Safari.prototype.setBundleId = function (cb) {
|
||||
this.args.bundleId = "com.apple.mobilesafari";
|
||||
cb();
|
||||
};
|
||||
|
||||
Safari.prototype._setInitialOrientation = IOS.prototype.setInitialOrientation;
|
||||
Safari.prototype.setInitialOrientation = function (cb) {
|
||||
if (this.args.udid) {
|
||||
logger.info("Not setting initial orientation because we're on " +
|
||||
"SafariLauncher");
|
||||
return cb();
|
||||
}
|
||||
this._setInitialOrientation(cb);
|
||||
};
|
||||
|
||||
Safari.prototype._setBootstrapConfig = IOS.prototype._setBootstrapConfig;
|
||||
Safari.prototype.setBootstrapConfig = function (cb) {
|
||||
if (this.args.udid) {
|
||||
logger.info("Not setting bootstrap config because we're on " +
|
||||
"SafariLauncher");
|
||||
return cb();
|
||||
}
|
||||
this._setBootstrapConfig(cb);
|
||||
};
|
||||
|
||||
Safari.prototype.installToRealDevice = function (cb) {
|
||||
if (this.args.udid) {
|
||||
this.isAppInstalled("com.bytearc.SafariLauncher", function (err) {
|
||||
if (err) {
|
||||
this.installApp(this.args.app, cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}.bind(this));
|
||||
} else {
|
||||
logger.info("Not installing to real device since we're on sim");
|
||||
cb();
|
||||
}
|
||||
};
|
||||
|
||||
Safari.prototype._stopRemote = IOS.prototype.stopRemote;
|
||||
Safari.prototype.stopRemote = function () {
|
||||
this._stopRemote(true);
|
||||
};
|
||||
|
||||
Safari.prototype._stop = IOS.prototype.stop;
|
||||
Safari.prototype.stop = function (cb) {
|
||||
if (this.args.udid) {
|
||||
logger.info("Stopping safariLauncher");
|
||||
this.shutdown(null, null, cb);
|
||||
} else {
|
||||
this._stop(cb);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Safari;
|
||||
|
||||
+4
-4
@@ -66,15 +66,15 @@
|
||||
"node-idevice": "~0.1.2",
|
||||
"win-spawn": "~2.0.0",
|
||||
"adm-zip": "~0.4.3",
|
||||
"ws": "0.4.31",
|
||||
"ws": "~0.4.31",
|
||||
"socket.io": "~0.9.16",
|
||||
"md5calculator": "~0.0.3",
|
||||
"through": "~2.3.4",
|
||||
"date-utils": "~1.2.14",
|
||||
"bytes": "~0.2.1",
|
||||
"appium-atoms": "0.0.2",
|
||||
"appium-instruments": "0.0.3",
|
||||
"appium-uiauto": "0.0.3"
|
||||
"appium-atoms": "~0.0.2",
|
||||
"appium-instruments": "~0.0.3",
|
||||
"appium-uiauto": "~0.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "grunt travis"
|
||||
|
||||
Reference in New Issue
Block a user