Index: javascript/core/scripts/selenium-browserbot.js =================================================================== --- javascript/core/scripts/selenium-browserbot.js (revision 1729) +++ javascript/core/scripts/selenium-browserbot.js (working copy) @@ -288,7 +288,12 @@ BrowserBot.prototype.selectWindow = function(target) { if (target && target != "null") { - this._selectWindowByName(target); + try { + this._selectWindowByName(target); + } + catch (e) { + this._selectWindowByTitle(target); + } } else { this._selectTopWindow(); } @@ -308,6 +313,11 @@ this.isSubFrameSelected = false; } +BrowserBot.prototype._selectWindowByTitle = function(target) { + var windowName = this.getWindowNameByTitle(target); + this._selectWindowByName(windowName); +} + BrowserBot.prototype.selectFrame = function(target) { if (target == "relative=up") { this.currentWindow = this.getCurrentWindow().parent; @@ -789,6 +799,26 @@ return targetWindow; }; +/** + * Find a window name from the window title. + */ +BrowserBot.prototype.getWindowNameByTitle = function(windowTitle) { + LOG.debug("getWindowNameByTitle(" + windowTitle + ")"); + + // First look in the map of opened windows and iterate them + for (var windowName in this.openedWindows) { + var targetWindow = this.openedWindows[windowName]; + + // If the target window's title is our title + if (targetWindow.document.title == windowTitle + && !this._windowClosed(targetWindow)) { + return windowName; + } + } + + throw new SeleniumError("Window does not exist from title"); +}; + BrowserBot.prototype.getCurrentWindow = function(doNotModify) { var testWindow = this.currentWindow; if (!doNotModify) { Index: javascript/tests/TestSuite.html =================================================================== --- javascript/tests/TestSuite.html (revision 1729) +++ javascript/tests/TestSuite.html (working copy) @@ -82,6 +82,7 @@
| Test selectWindow by title + |
+ ||
| open | +../tests/html/test_select_window.html | ++ |
| click | +popupPage | ++ |
| waitForPopUp | +myPopupWindow | +5000 | +
| selectWindow | + +Select Window Popup | ++ |
| verifyLocation | +*/tests/html/test_select_window_popup.html | ++ |
| verifyTitle | +Select Window Popup | ++ |
| verifyAllWindowNames | +*,* | ++ |
| verifyAllWindowNames | +regexp:myNewWindow | ++ |
| close | ++ | + |
| selectWindow | +null | ++ |
| verifyLocation | +*/tests/html/test_select_window.html | ++ |
| click | +popupPage | ++ |
| waitForPopUp | +myNewWindow | +5000 | +
| selectWindow | +myNewWindow | ++ |
| verifyLocation | +*/tests/html/test_select_window_popup.html | ++ |
| close | ++ | + |
| selectWindow | +null | ++ |
Select an anonymous window (one that isn't assigned to a variable)
+| click | +popupAnonymous | ++ |
| waitForPopUp | +anonymouspopup | +5000 | +
| selectWindow | +anonymouspopup | ++ |
| verifyLocation | +*/tests/html/test_select_window_popup.html | ++ |
| click | +closePage | ++ |
| selectWindow | +null | ++ |
Try onclick close handler
+| click | +popupAnonymous | ++ |
| waitForPopUp | +anonymouspopup | +5000 | +
| selectWindow | +anonymouspopup | ++ |
| verifyLocation | +*/tests/html/test_select_window_popup.html | ++ |
| click | +closePage2 | ++ |
Leave the test in a selected window - the next test should begin in the main window
+ + +