Book Image

Selenium Testing Tools Cookbook

5 (1)
Book Image

Selenium Testing Tools Cookbook

5 (1)

Overview of this book

This book is an incremental guide that will help you learn and use the advanced features of the Selenium toolset including the WebDriver API in various situations to build a reliable test automation. You start off by setting up the test development environment and gain tips on the advanced locater strategy and the effective use of the Selenium WebDriver API. After that, the use of design patterns such as data - driven tests and PageFactory are demonstrated. You will then be familiarised with extending Selenium WebDriver API by implementing custom tasks and setting up your own distributed environment to run tests in parallel for cross-browser testing. Finally, we give you some tips on integrating Selenium WebDriver with other popular tools and testing mobile applications. By the end of this book, you will have learned enough to solve complex testing issues on your own.
Table of Contents (21 chapters)
Selenium Testing Tools Cookbook Second Edition
About the Author
About the Reviewers

Using the PageFactory class for exposing the elements on a page

To implement the Page Object model in tests, we need to create a Page Object class for each page that is being tested. For example, to test the BMI Calculator application, a BMI Calculator page class will be defined, which will expose the internals of the BMI Calculator page to the test, as shown in following diagram. This is done by using the PageFactory class of Selenium WebDriver API:

Getting ready

Before exposing the elements of a page, we need to do the following:

  • Identify the locators that will be needed to find all the required elements from a page uniquely

  • Define the structure of the package and classes for the page

How to do it...

Let's implement a Page Object test for the BMI Calculator page using the PageFactory class with the following steps:

  1. Define and create a package for all the page objects from the application for logical grouping. For example, seleniumcookbook.tests.pageobjects is created to define all the page objects...