mirror of
https://github.com/appium/appium.git
synced 2026-05-04 17:29:28 -05:00
Merge pull request #1472 from snevesbarros/close_tab_solution
Added ability to close tabs in safari when using safariLauncher
This commit is contained in:
+1
-1
@@ -685,7 +685,7 @@ Appium.prototype.stop = function(cb) {
|
||||
|
||||
logger.info('Shutting down appium session...');
|
||||
if (this.isSafariLauncherApp === true) {
|
||||
this.device.leaveWebView(function() {
|
||||
this.device.closeWindow(function() {
|
||||
if (this.device.udid === null && this.device.instruments !== null) {
|
||||
this.device.instruments.shutdown(function() {
|
||||
this.cleanupSession(null, cb);
|
||||
|
||||
@@ -1180,7 +1180,7 @@ iOSController.setWindow = function(name, cb) {
|
||||
|
||||
iOSController.closeWindow = function(cb) {
|
||||
if (this.curWindowHandle) {
|
||||
var script = "return window.setTimeout(function() { window.close(); }, 1000);";
|
||||
var script = "return window.open('','_self').close();";
|
||||
this.executeAtom('execute_script', [script, []], function(err, res) {
|
||||
setTimeout(function() {
|
||||
cb(err, res);
|
||||
|
||||
@@ -12,7 +12,8 @@ iOSHybrid.navToInitialWebview = function(cb) {
|
||||
if (this.autoWebview) {
|
||||
if (this.isSafariLauncherApp) {
|
||||
setTimeout(function() {
|
||||
this.navToFirstAvailWebview(cb);
|
||||
//the latest window is the one newly created by Safari launcher.
|
||||
this.navToLatestAvailableWebview(cb);
|
||||
}.bind(this), 6000);
|
||||
} else {
|
||||
this.navToFirstAvailWebview(cb);
|
||||
@@ -42,6 +43,19 @@ iOSHybrid.navToFirstAvailWebview = function(cb) {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
iOSHybrid.navToLatestAvailableWebview = function(cb) {
|
||||
logger.info("Navigating to latest webview");
|
||||
this.getWindowHandles(function(err, res) {
|
||||
if (res.status !== 0) {
|
||||
cb(new Error("Could not navigate to webview! Code: " + res.status));
|
||||
} else if (res.value.length === 0) {
|
||||
cb(new Error("Could not navigate to webview; there aren't any!"));
|
||||
} else {
|
||||
logger.info("Picking webview " + res.value[0]);
|
||||
this.setWindow(res.value[res.value.length - 1], cb);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
iOSHybrid.closeAlertBeforeTest = function(cb) {
|
||||
this.proxy("au.alertIsPresent()", function(err, res) {
|
||||
@@ -207,11 +221,20 @@ iOSHybrid.stopRemote = function() {
|
||||
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 {
|
||||
//should probably add a callback to both debuggers.
|
||||
if (this.udid) {
|
||||
this.remote.disconnect(function(){});
|
||||
if (this.isSafariLauncherApp) {
|
||||
this.closeWindow(function(){
|
||||
if (this.udid) {
|
||||
this.remote.disconnect(function(){});
|
||||
} else {
|
||||
this.remote.disconnect();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.remote.disconnect();
|
||||
if (this.udid) {
|
||||
this.remote.disconnect(function(){});
|
||||
} else {
|
||||
this.remote.disconnect();
|
||||
}
|
||||
}
|
||||
this.curWindowHandle = null;
|
||||
this.curWebFrames = [];
|
||||
|
||||
Reference in New Issue
Block a user