Tuesday, October 15, 2013

How to work with multiple windows

Working with multiple 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 shall see the tests click on an element on the page which will
cause a new window to appear. If you have a pop-up blocker running, it may be a good idea
to disable it for this site while you work through these examples.
1. Open up Selenium IDE and go to the Chapter 1 page on the site.
2. Click on one of the elements on the page that has the text Click this link to launch
another window. This will cause a small window to appear.
3. Verify the text in the popup by right-clicking and selecting VerifyText id=popup text
within the popup window.
4. Once the window has loaded, click on the Close the Window text inside it.
5. Add a verify command for an element on the page. Your test should now look like
the following screenshot:



In the next example we are going to open up two pop-up windows and move between them
and the parent window as it completes its steps.
1. Start Selenium IDE and go to Chapter 1 on the website.
2. Click on the Click this link to launch another window link. This will launch
a pop-up window.
3. Assert the text on the page. We do this by right-clicking and selecting assertText.
4. Go back to the parent window and click on the link to launch the second
pop-up window.
5. Verify the text on the page.
6. Move to the first pop-up window and close it using the close link. As before,
be aware of clickAndWait instead of click.
7. Move to the second pop-up window and close it using the close link.
8. Move back to the parent window and verify an element on that page.
9. Run your test and watch how it moves between the windows. When complete it
should look like the following screenshot:


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.

No comments:

Post a Comment