Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Selenium Testing Tools - Third Edition

You're reading from   Learning Selenium Testing Tools - Third Edition Leverage the power of Selenium to build your own real-time test cases from scratch

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781784396497
Length 318 pages
Edition 3rd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Raghavendra Prasad MG Raghavendra Prasad MG
Author Profile Icon Raghavendra Prasad MG
Raghavendra Prasad MG
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting Started with Selenium IDE FREE CHAPTER 2. Locators 3. Overview of the Selenium WebDriver 4. Finding Elements 5. Design Patterns 6. Working with WebDriver 7. Automation Framework Development and Building Utilities 8. Mobile Devices 9. Getting Started with the Selenium Grid 10. Advanced User Interactions 11. Working with HTML5 12. Advanced Topics 13. Migrating from Remote Control to WebDriver A. Automation Prerequisites for Selenium Automation B. Answers for Self-test Questions Index

Multiplying windows

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 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:

  1. 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.
  2. Verify the text in the popup by right-clicking and selecting VerifyText id=popup text within the popup window.
  3. Once the window has loaded, click on the Close the Window text inside it.
  4. Add a verify command for an element on the page. Your test should now look like the following screenshot:
    Working with multiple windows

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.

Complex working with multiple windows

In this example, we will open 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:
    Complex working with multiple windows

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.

You have been reading a chapter from
Learning Selenium Testing Tools - Third Edition - Third Edition
Published in: Feb 2015
Publisher:
ISBN-13: 9781784396497
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image