Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Selenium WebDriver 3.0
Mastering Selenium WebDriver 3.0

Mastering Selenium WebDriver 3.0: Boost the performance and reliability of your automated checks by mastering Selenium WebDriver , Second Edition

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering Selenium WebDriver 3.0

Producing the Right Feedback When Failing

In this chapter, we are going to have a look at how you can make life easier for yourself when tests start failing. We will do the following:

  • Discuss where our tests should live and examine why
  • Have a look at test reliability
  • Have a look at ways we can force our tests to be run regularly
  • Talk about continuous integration and continuous delivery
  • Extend the project we started in the previous chapter so that it can run against a Selenium-Grid
  • Have a look at ways to diagnose problems with our tests

Location, location, location

Many companies still have discrete test and development teams. This is obviously not an ideal situation, as the test team is usually not completely aware of what the development team is building. This also provides us with additional challenges if the test team is tasked with writing automated functional tests using the web frontend.

The usual problem is that the test team is behind the development team, and how far behind depends upon how frequent development releases are. The thing is, it doesn't really matter how far behind the development team you are. If you are behind the team, you will always be playing catch up. When you are playing catch up, you are constantly updating your scripts to make them work with a new release of software.

Some people may call "fixing their scripts to work with new functionality" refactoring; they are...

Tests are living documentation

What do I mean by living documentation? As the application is built, automated tests are continually being written to ensure that specific criteria are met. These tests come in many different shapes and sizes, ranging from unit tests to integration tests, and leading up to end-to-end functional tests and beyond. All of these tests describe, in some way, how the application works. You have to admit that this sounds just like documentation.

This documentation may not be perfect, but that doesn't stop it from being documentation. Think of an application that has some unit tests, and maybe one badly written end-to-end test. I would equate that to the sort of documentation that you would get with a cheap electrical product, from somewhere such as China. It comes with a manual, which will undoubtedly have a small badly written English bit that doesn...

Reliability

When it comes to automation, the reliability of tests is the key. If your tests are not reliable, they will not be trusted, which can have far-reaching consequences. I'm sure you have all worked in environments where test reliability has been hard for one of many reasons; let's have a look at a couple of scenarios.

The test automation team that works in isolation

One of the more common reasons that tests are not reliable is having a dedicated test automation team that works in isolation from the team that develops the application. This should really be avoided if possible, as the test automation team is always playing catch up. The development team rolls out new features that the test automation teams...

Baking in reliability

How can we try to enforce reliability and make sure that these changes are picked up early?

We could ask our developers to run the tests before every push, but sometimes people forget. Maybe they didn't forget, but it's a small change and it doesn't seem worth going through a full test run for something so minor (have you ever heard somebody say, "It's only a CSS change...?"). Making sure that the tests are run, and pass before every push to the centralized source code repository, takes discipline.

What do we do if our team lacks discipline? What if we still keep getting failures that should have been easily caught, even after we have asked people to run the tests before they push code to the central repository? If nothing else works, we could have a discussion with the developers about enforcing this rule.

This is actually surprisingly...

Continuous integration is key

Continuous integration is a way to try and mitigate the issues that we come across by only building and testing code on our development machines. Our continuous integration server will monitor our source code repository and then every time it detects a change, it will trigger a series of actions. The first action will be to build the code, running any tests that it can as it builds the code (usually unit tests), and then creating a deployable artifact. This artifact would then usually be deployed to a server that is a replica of the live environment. Once this code has been deployed to a server, the rest of our tests will be run against that server to ensure that everything is working as expected. If things do not work as expected, the build fails and the development team is notified so that they can fix the problems. It's important to note that...

Extending our capabilities by using a Selenium-Grid

Since we already have a working Maven implementation, let's enhance it so that it can connect to Selenium-Grid. These enhancements will enable you to connect to any Selenium-Grid, but we are going to specifically look at connecting to a third-party service provided by SauceLabs, since they offer a free tier. Let's have a look at the modifications we need to make to our TestNG code.

We will start off with the modifications to our POM; initially, we are going to add some properties that we can configure on the command line by using this code:

<properties>
<project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-
8</project.reporting.outputEncoding>
<!-- Dependency versions -->
<phantomjsdriver.version>1...

A picture paints a thousand words

Even if you have made your tests totally reliable, they will fail occasionally. When this happens, it is often very hard to describe the problem with words alone. If one of your tests failed, wouldn't it be easier to explain what went wrong if you had a picture of what was happening in the browser when things went wrong? I know that when any of my Selenium tests fail, the first thing I want to know is what was on the screen at the time of failure. If I knew what was on the screen at the time of failure, I would be able to diagnose the vast majority of issues without having to hunt through a stack trace for a specific line number, and then go and look at the associated code to try and work out what went wrong. Wouldn't it be nice if we got a screenshot showing what was on the screen every time a test failed? Let's take the project...

Don't be afraid of the big bad stack trace

It's surprising how many people are intimidated by stack traces. A reaction that I regularly see when a stack trace appears on screen is panic!

"Oh my god! Something has gone wrong! There are hundreds of lines of text talking about code I don't recognize and I can't take it all in; what do I do?"

The first thing to do is to relax; stack traces have a lot of information but they are actually really friendly and helpful things. Let's modify our project to produce a stack trace and work through it. We are going to make a small change to the getDriver() method in DriverFactory to force it to always return null by using this code:

    public static WebDriver getDriver() { 
        return null; 
    } 

This is going to make sure that we never return a driver object, something that we would expect to cause...

Summary

After reading this chapter, you will hopefully no longer think of automated checks as regression tests; instead you should think of them as living documentation that continues to grow and flourish as the code they are validating changes. When things go wrong you will be able to take screenshots to aid diagnosis, as well as being able to fluently read stack traces. You will know how to connect your tests to a Selenium-Grid to provide additional flexibility. Finally, you will also have a good understanding of why reliability matters and how this feeds into successful continuous integration, continuous delivery, and continuous deployment.

In the next chapter, we are going to have a look at exceptions generated by Selenium. We will work through various exceptions that you may see and what they mean.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand the power, simplicity, and limitations of the core Selenium framework
  • Write clear, readable, and reliable tests that perform complex test automation tasks
  • Work with ChromeDriver and GeckoDriver in headless mode

Description

The second edition of Mastering Selenium 3.0 WebDriver starts by showing you how to build your own Selenium framework with Maven. You'll then look at how you can solve the difficult problems that you will undoubtedly come across as you start using Selenium in an enterprise environment and learn how to produce the right feedback when failing. Next, you’ll explore common exceptions that you will come across as you use Selenium, the root causes of these exceptions, and how to fix them. Along the way, you’ll use Advanced User Interactions APIs, running any JavaScript you need through Selenium; and learn how to quickly spin up a Selenium Grid using Docker containers. In the concluding chapters, you‘ll work through a series of scenarios that demonstrate how to extend Selenium to work with external libraries and applications so that you can be sure you are using the right tool for the job.

Who is this book for?

If you are a software tester or a developer with working experience in Selenium and competency with Java, who is interested in automation and are looking forward to taking the next step in their learning journey, then this is the book for you.

What you will learn

  • Provide fast, useful feedback with screenshots
  • Create extensible, well-composed page objects
  • Utilize ChromeDriver and GeckoDriver in headless mode
  • Leverage the full power of Advanced User Interactions APIs
  • Use JavascriptExecutor to execute JavaScript snippets in the browser through Selenium
  • Build user interaction into your test script using JavascriptExecutor
  • Learn the basics of working with Appium

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 29, 2018
Length: 376 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788293686
Vendor :
Apache
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jun 29, 2018
Length: 376 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788293686
Vendor :
Apache
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 106.97
Mastering Selenium WebDriver 3.0
€36.99
Selenium WebDriver 3 Practical Guide
€32.99
Selenium Framework Design in Data-Driven Testing
€36.99
Total 106.97 Stars icon

Table of Contents

11 Chapters
Creating a Fast Feedback Loop Chevron down icon Chevron up icon
Producing the Right Feedback When Failing Chevron down icon Chevron up icon
Exceptions Are Actually Oracles Chevron down icon Chevron up icon
The Waiting Game Chevron down icon Chevron up icon
Working with Effective Page Objects Chevron down icon Chevron up icon
Utilizing the Advanced User Interactions API Chevron down icon Chevron up icon
JavaScript Execution with Selenium Chevron down icon Chevron up icon
Keeping It Real Chevron down icon Chevron up icon
Hooking Docker into Selenium Chevron down icon Chevron up icon
Selenium – the Future Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(3 Ratings)
5 star 33.3%
4 star 33.3%
3 star 0%
2 star 0%
1 star 33.3%
Sashank Mar 15, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Yes
Amazon Verified review Amazon
Jsh May 31, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Clearly written by somebody who has done significant work with Selenium and to a lesser extent Appium, this is a book that contains more useful information and code than any other Selenium book that I had read so far (and I’ve read quite a few).The writing is opinionated, which works well given the experience of the author, but with one exception – unnecessary references to China. I would have expected any decent editor to have had that section removed.For the most part, I agree with the technical advice given, although not quite 100% of the time. There are also some topics missed that I would have included, but those topics are also missed in pretty much every Selenium book. With that caveat, the list of topics covered is still very good. Whether it’s suitable for somebody completely new to automated testing or DevOps, I’m not sure. It’s more an upper-end of intermediate level book IMHO. Aimed at those working in Java, the code is easy to map into other languages (C#, Python etc).Given the rate of change in computing (esp. browsers, mobile app development, virtualisation etc), it’s inevitable that the text is already (I’m writing this at end of May 2021) in need to an update. However, even without that update, it’s still very useful.Recommended, but with caveats mentioned above.
Amazon Verified review Amazon
Jeff Nyman Sep 29, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
This is, unfortunately, a terrible book. Just in the first two chapters alone, you will find inconsistent code examples (some are clearly bits from the first edition, as you can tell by certain incorrect method signatures), code that doesn't match up with what's being described in the text, and code printed in the book that doesn't match the code in the GitHub repository provided.I submitted errata for the first edition of this book and while there have been some improvements (for example the JUnit inclusion), there are still a series of errors that were not rectified and the introduction of entire new ones.If you're already fairly proficient with Selenium in a Java context, you will likely be able to work your way around these problems. And if you do, you will find that the author does actually create a fairly concise and useful framework that allows you to explore Selenium within Java. This includes up-to-date material such as Chrome and Firefox headless and the use of the new Options approach that Selenium uses, which merges in DesiredCapabilities to a set of options.So there is good to be had here, in terms of some of the material. The problem is that the errors are glaring to the point of ridiculousness, especially in a second edition. You will encounter many such errors just in the first two chapters alone. All of these are certainly surmountable but for someone who is learning, this book will likely rapidly become tedious to the point of distraction.What's most aggravating is that I was able to find these problems on my first read-through of the book. I literally wrote this review after going through the first four chapters. If I could find these errors that quickly, why couldn't whomever reviewed the book? (Assuming, of course, that someone did.) This is an extremely disappointing second attempt by this author and I would highly recommend people avoid this. If you want to get the basics of what the author was providing, simply look up the repo within Packt's space on GitHub. You might not save yourself any aggravation but you will certainly save yourself some money.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.