<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- Copyright 2004 ThoughtWorks, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>BrowserBot tests</title> <link rel="stylesheet" type="text/css" href="../../jsunit/css/jsUnitStyle.css"> <script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script> <script language="JavaScript" type="text/javascript" src="../jsmock/mock.js"></script> <script language="JavaScript" type="text/javascript" src="../dummy-logging.js"></script> <script language="JavaScript" type="text/javascript" src="../../core/scripts/htmlutils.js"></script> <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserdetect.js"></script> <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserbot.js"></script> <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-logging.js"></script> <script language="JavaScript" type="text/javascript"> function setUp() { mockWindow = new String('mockWindow'); mockWindow.closed = false; browserBot = new MozillaBrowserBot(mockWindow); browserBot.currentWindowName = 'originalWindowName'; browserBot.currentPage = 'originalPage'; } function testCurrentWindowNameIsSetToNullWhenSelectWindowIsCalledWithNull() { browserBot.selectWindow('null'); assertNull(browserBot.currentWindowName); } function testCurrentWindowIsSetWhenSelectWindowIsCalledWithNonNull() { // Make sure new window can be found mockWindow.windowName = new String('anotherWindow'); browserBot.selectWindow('windowName'); assertEquals('windowName', browserBot.currentWindowName); } function testExceptionWhenSelectWindowIsCalledWithUnknownWindowName() { try { browserBot.selectWindow('notAwindow'); fail("Should have thrown exception"); } catch (e) { assertEquals("Could not find window with title notAwindow", e.message); } } function testFrameSrcIsSetOnOpenLocationWhenThereIsNoCurrentWindow() { browserBot.currentWindowName = null; var mockLocation = { href:"" }; mockWindow.location = mockLocation; var mockDocument = new Object(); mockWindow.document = mockDocument; mockWindow.document.location = mockLocation; browserBot.baseUrl = "http://x"; browserBot.openLocation('myNewLocation'); assertEquals('http://x/myNewLocation', mockWindow.location.href); } function testCurrentPageIsLazyCreatedBasedOnContentWindowWhenCurrentWindowNameIsNull() { browserBot.currentWindowName = null; browserBot.currentPage = null; var mockLocation = new Mock(); mockLocation.expectsProperty('pathname').returns('thelocation'); mockWindow.location = mockLocation; var mockDocument = new Object(); mockWindow.document = mockDocument; mockWindow.document.location = mockLocation; mockWindow.addEventListener = function(){}; mockWindow.attachEvent = function(){}; var pageBot = browserBot.getCurrentPage(); assertEquals(mockWindow, pageBot.getCurrentWindow()); assertEquals(mockDocument, pageBot.getDocument()); mockLocation.verify(); } function testCurrentPageIsLazyCreatedBasedOnNamedWindowWhenCurrentWindowNameIsSet() { browserBot.currentPage = null; var mockLocation = new Mock(); mockLocation.expectsProperty('pathname').returns('thelocation'); mockWindow.location = mockLocation; var mockDocument = new Object(); mockWindow.document = mockDocument; mockWindow.document.location = mockLocation; mockWindow.addEventListener = function(){}; mockWindow.attachEvent = function(){}; var pageBot = browserBot.getCurrentPage(); assertEquals(mockWindow, pageBot.getCurrentWindow()); mockLocation.verify(); } </script> </head> <body>Selenium BrowserBot Tests</body> </html>