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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Estimated delivery fee Deliver to Greece

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Estimated delivery fee Deliver to Greece

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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
€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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela