Selenium WebDriver Quick Start Guide
eBook - ePub

Selenium WebDriver Quick Start Guide

Write clear, readable, and reliable tests with Selenium WebDriver 3

Pinakin Chaubal

Partager le livre
  1. 192 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Selenium WebDriver Quick Start Guide

Write clear, readable, and reliable tests with Selenium WebDriver 3

Pinakin Chaubal

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Get writing tests and learn to design your own testing framework with Selenium WebDriver API

Key Features

  • Learn Selenium from the ground up
  • Design your own testing framework
  • Create reusable functionality in your framework

Book Description

Selenium WebDriver is a platform-independent API for automating the testing of both browser and mobile applications. It is also a core technology in many other browser automation tools, APIs, and frameworks. This book will guide you through the WebDriver APIs that are used in automation tests.

Chapter by chapter, we will construct the building blocks of a page object model framework as you learn about the required Java and Selenium methods and terminology.

The book starts with an introduction to the same-origin policy, cross-site scripting dangers, and the Document Object Model (DOM). Moving ahead, we'll learn about XPath, which allows us to select items on a page, and how to design a customized XPath. After that, we will be creating singleton patterns and drivers. Then you will learn about synchronization and handling pop-up windows. You will see how to create a factory for browsers and understand command design patterns applicable to this area.

At the end of the book, we tie all this together by creating a framework and implementing multi-browser testing with Selenium Grid.

What you will learn

  • Understand what an XPath is and how to design a customized XPath
  • Learn how to create a Maven project and build
  • Create a Singleton driver
  • Get to grips with Jenkins integration
  • Create a factory for browsers
  • Implement multi-browser testing with Selenium Grid
  • Create a sample pop-up window and JavaScript alert
  • Report using Extent Reports

Who this book is for

This book is for software testers or developers.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Selenium WebDriver Quick Start Guide est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Selenium WebDriver Quick Start Guide par Pinakin Chaubal en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Ciencia de la computaciĂłn et Control y garantĂ­a de calidad. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781789611342

Hybrid Framework

We are in the final chapter, where we will explore two new concepts: TestNG Listeners and DataProviders. We will integrate our framework with reports and logging. In this chapter, we will look at the following concepts:
  • Introducing WebDriverManager
  • DataProviders in TestNG
  • TestNG listeners and assertions
  • Incorporating logging and reporting in the framework
  • Steps to add keywords to the framework
Let's start the chapter with an introduction to a new concept: WebDriverManager.

Technical requirements

You will be required to have Ashot API in addition to software mentioned in Chapter 7, The Command Pattern and Creating Components.
The code files of this chapter can be found on GitHub:
https://github.com/PacktPublishing/Selenium-WebDriver-Quick-Start-Guide/tree/master/Chapter08
Check out the following video to see the code in action:
http://bit.ly/2O8KoXW

Introducing the WebDriverManager library

One constraint in Selenium automation is that we need to download the driver binary executable for Chrome, Firefox, and Internet Explorer. After downloading the executable files for Java, the absolute path of this executable file has to be set to JVM properties using System.setProperty. This was an overhead which has been removed with the introduction of a library called WebDriverManager.
Remember to use JDK 1.8 with this library. It won't work with JDK 1.7.
With this library, there is no need to download the individual binaries for the different browsers. Earlier, we had to manage the versions of the binaries manually. With this library, this gets handled automatically.

How to use the WebDriverManager library

The WebDriverManager library can be used in three ways:
  • As a Java dependency
  • As a command-line interface
  • As a server in itself
Let's look at each of these individually.

WebDriverManager as a Java dependency

One of the ways to use the WebDriverManager library is as a Java dependency. Add the dependency shown in the following code in the Dependencies section. This dependency can be found on GitHub:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
3.0.0 is the latest version at the time of writing.
Prior to WebDriverManager, we had to write the following in order to work with the browsers. Sample code for the Chrome browser is shown here:
private WebDriver driver = null;
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new ChromeDriver();
The same code can be written efficiently, as shown here:
private WebDriver driver = null;
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
As we can seen, we don't require to set the binary path using System.setProperty. WebDriverManager handles it for us.
The following code fragment shows how to use WebDriverManager for Firefox:
private WebDriver driver=null;
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
The following code fragment shows how to use WebDriverManager for Internet Explorer:
private WebDriver driver=null;
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
The sample code is shown here:
public class BrowserFactory {
private WebDriver driver = null;
public void openBrowser(String browser) {
driver = null;
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
}
We will next see how to use WebDriverManager on the command line.

WebDriverManager as CLI

We can use WebDriverManager on the command line as well the the Java dependency. We do this simply by using the following Maven command:
mvn exec:java -Dexec.args="chrome"
On executing this command, the following logs get displayed in the console:

WebDriverManagerServer

WebDriverManager can also be used as a server. There are two ways to use it as a server:
  • Directly from the code and Maven
  • Using WebDriverManager as a fat JAR
Let's look at both of these methods:
  1. Directly from the code and Maven: The command to be used is: mvn exec:java -Dexec.args="server <port>". If the second argument is omitted, the default port (4041) will be used: C:\ Maven mvn exec:java -Dexec.args="server":
  1. Using WebDriverManager as a fat-jar: We can also use WebDriverManager as a fat JAR. For instance: java -jar webdrivermanager-3.0.0-fat.jar chrome.
After executing this command, the following gets printed in the console:
When WebDriverManager gets up and running, HTTP requests can be done to resolve driver binary executables (chromedriver, geckodriver, and so on). For example, suppose that WebDriverManager is running the localhost and in the default port, navigates to the following URLs to get the latest versions of the driver executables:
  • http://localhost:4041/chromedriver: The latest version of chromedriver
  • http://localhost:4041/firefoxdriver: The latest version of geckodriver
  • http://localhost:4041/operadriver: The latest version of operadriver
  • http://localhost:4041/phantomjs: The latest version of phantomjs driver
  • http://localhost:4041/edgedriver: The latest version of MicrosoftWebDriver
  • http://localhost:4041/iedriver: The latest version of IEDriverServer
These requests can be initiated using a normal browser. The driver binary is then automatically downloaded by the browser as an attachment in the HTTP response when the response is sent back.

Advantages of WebDriverManager

Let's see what advantages the WebDriverManager offers:
  • It checks the browser version installed on your machine (for example, Chrome, Firefox, Internet Explorer, and so on).
  • It checks the version of the driver (for example, chromedriver, geckodriver). If the version is not known, it uses the latest version of the driver.
  • It downloads the WebDriver binary executable if it is not present in the WebDriverManager cache in the Maven repository (~/.m2/repository/webdriver by default).
  • It exports the appropriate WebDriver Java environment variables required by Selenium (not done when WebDriverManager is used from the the command-line interface or as a server).
Now that we know about the WebDriverManager library, we will look at what DataProviders are in TestNG.

DataProviders in TestNG

DataProviders in Tes...

Table des matiĂšres