Book Image

Selenium Testing Tools Cookbook Second Edition

By : UNMESH GUNDECHA
5 (1)
Book Image

Selenium Testing Tools Cookbook Second Edition

5 (1)
By: UNMESH GUNDECHA

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 (16 chapters)
15
Index

Using the PageFactory class for exposing an operation on a page


In the previous recipe, we created the BmiCalcPage class, which provides elements from the BMI Calculator page to the test. Along with elements, we define operations or behaviors on a page. In the BMI Calculator application, we are calculating the BMI by entering height and weight values. We can create an operation named calculateBmi and call it directly in a test, instead of calling individual elements and operations.

In this recipe, let's refine the BmiCalcPage class. And instead of elements, let's provide the operations that are supported on the page, and some common properties. We will also move the WebDriver instance of the test to the BmiCalcPage class to make the test generic.

Getting ready

Identify operations that will be required in a test and can be exposed from a page. This recipe uses the BmiCalcPage class created in the previous recipe.

How to do it...

Let's modify the BmiCalcPage class created in the previous recipe...