-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learning Selenium Testing Tools - Third Edition - Third Edition
By :
Web applications, unfortunately, do not live in one window of your browser. An example of this can be a site that shows reports. Most reports will have their own window so that people can easily move between them.
Unfortunately, in testing terms, this can be quite difficult to do, but in this section, we will have a look at creating a test that can move between windows.
Working with multiple browser windows can be one of the most difficult things to do within a Selenium test. This is down to the fact that the browser needs to allow Selenium to programmatically know how many child browser processes have been spawned.
In the following examples, we will see the tests click on an element on the page that will cause a new window to appear. If you have a pop-up blocker running, it's a good idea to disable it for this site while you work through these examples. Open up Selenium IDE and go to the Chapter 1 page on the site and refer to the following steps:

Sometimes, Selenium IDE will add a clickAndWait command instead of a click command. This is because it notices that the page has to unload. If this happens, just change the clickAndWait command to a click so that it does not cause a timeout in the test.
In the test script, we can see that it has clicked on the item to load the new window and then has inserted a waitForPopUp command. This is so that your test knows that it has to wait for a web server to handle the request and the browser to render the page. Any commands that require a page to load from a web server will have a waitFor command. The next command is the selectWindow command. This command tells Selenium IDE that it will need to switch context to the window, called popupwindow, and will execute all the commands that follow in that window unless told otherwise by a later command.
Once the test has finished with the pop-up window, it will need to return to the parent window from where it started. To do this, we need to specify null as the window. This will force the selectWindow command to move the context of the test back to its parent window.
In this example, we will open two pop-up windows and move between them and the parent window as it completes its steps:
clickAndWait instead of click.
We just had a look at creating a test that can move between multiple windows. We saw how we can move between the child windows and its parent window as though we were a user.
Change the font size
Change margin width
Change background colour