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
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788299671
Vendor :
Apache
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 141.97
Mastering Selenium WebDriver 3.0
$48.99
Selenium WebDriver 3 Practical Guide
$43.99
Selenium Framework Design in Data-Driven Testing
$48.99
Total $ 141.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.