O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Selenium WebDriver

Book Description

Increase the performance, capability, and reliability of your automated checks by mastering Selenium WebDriver

About This Book

  • Create an extensible test framework in Java supporting parallel execution with TestNG
  • Understand the power, simplicity, and limitations of the core Selenium framework
  • Write clear, simple, readable, and reliable tests that perform complex test automation tasks

Who This Book Is For

If you are a software tester or a developer who has learnt the basics of Selenium using the WebDriver API and is now ready to take the next step, then this is the book for you.

What You Will Learn

  • Provide fast, useful feedback with sensible errors and screenshots
  • Create extensible, well-composed page objects
  • Gain an in-depth understanding of implicit and explicit waits, and how you should use them
  • Leverage the full power of the Actions API
  • Explore the full potential of the JavascriptExecutor
  • Extend Selenium’s capabilities by integrating other applications
  • Learn how to plug third-party products into Selenium, and where it is appropriate to do so

In Detail

Selenium WebDriver, also known as Selenium 2, is a UI automation tool used by software developers and QA engineers to test their web applications on different web browsers. The Selenium WebDriver API is fully object oriented compared with the deprecated Selenium RC. The WebDriver API provides multi-language support and run tests on all the most popular browsers.

In this wide and complex World Wide Web era, this book will teach you how to tame it by gaining an in-depth understanding of the Selenium API.

This book starts with how to solve the difficult problems that you will undoubtedly come across as you start using Selenium in an enterprise environment, followed by producing the right feedback when failing, and what the common exceptions are, explain them properly (including the root cause) and tell you how to fix them. You will also see the differences between the three available implicit waits and explicit waits, and learn to working with effective page objects.

Moving on, the book shows you how to utilize the Advanced User Interactions API, how you can run any JavaScript you need through Selenium, and how to quickly spin up a Selenium Grid using Docker containers.

At the end, the book will discuss the upcoming Selenium W3C specification and how it is going to affect the future of Selenium.

Style and approach

This book is a pragmatic guide that takes you through the process of creating a test framework. It then shows you how you can extend this framework to overcome common obstacles that you will come across whilst using Selenium.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Mastering Selenium WebDriver
    1. Table of Contents
    2. Mastering Selenium WebDriver
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Who is this book not for?
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Creating a Fast Feedback Loop
      1. Making it easy for developers to run tests
      2. Building our test project with Apache Maven
      3. Running your tests in parallel
      4. Parallel tests with TestNG
      5. There are no silver bullets
      6. Multiple browser support
        1. Firefox
        2. Chrome
        3. Internet Explorer
        4. Safari
        5. Opera
      7. Downloading the WebDriver binaries automatically
      8. Going headless
      9. Summary
    9. 2. Producing the Right Feedback When Failing
      1. Location, location, location
      2. Tests are living documentation
      3. Reliability
        1. The test automation team that works in isolation
        2. Oh that test always flickers, don't worry about it
      4. Baking in reliability
        1. Git
        2. SVN
      5. Continuous integration is the key
        1. TeamCity
        2. Jenkins
      6. Extending our capabilities by using a Selenium Grid
      7. A picture paints a thousand words
      8. Don't be afraid of the big bad stack trace
      9. Summary
    10. 3. Exceptions Are Actually Oracles
      1. Are exceptions oracles?
      2. NoSuchElementException
      3. NoSuchFrameException
      4. NoSuchWindowException
      5. ElementNotVisibleException
      6. StaleElementReferenceException
      7. InvalidElementStateException
      8. UnsupportedCommandException
      9. UnreachableBrowserException
      10. SessionNotFoundException
      11. Summary
    11. 4. The Waiting Game
      1. Are we nearly ready yet?
      2. I've timed it and I know it takes 5 seconds for the page to load
        1. Machine specifications
        2. Server specifications
        3. The JavaScript engine performance
        4. Networks
      3. So, what do we do?
      4. I just want Selenium to do it for me
        1. The page load timeout
        2. The script timeout
        3. The implicit wait timeout
          1. Can it slow my tests down?
          2. Can it break explicit waits?
            1. The explicit wait that never finds an element
              1. Wait, it's a trap!
            2. The explicit wait that works, but slows your tests down
          3. The solution
      5. Using explicit waits
      6. FluentWaits – the core of explicit waits
        1. Functions
        2. Predicates
      7. Summary
    12. 5. Working with Effective Page Objects
      1. Why do you keep repeating yourself?
      2. Starting out with page objects
      3. Using page objects to ensure good separation of concerns
      4. Introducing the Java PageFactory class
        1. Using the PageFactory annotations
        2. Initializing the proxied objects
      5. Creating extensible page objects
      6. Turning your page objects into a readable domain-specific language
      7. Fluent page objects
      8. Summary
    13. 6. Utilizing the Advanced User Interactions API
      1. Getting started with the API
      2. Using the API to solve difficult problems
        1. Working with hover menus
        2. Working with drag and drop
        3. Working with offsets
        4. It doesn't always work for me
      3. Summary
    14. 7. JavaScript Execution with Selenium
      1. Introducing the JavaScript executor
      2. Let's not get carried away
      3. So, what should we do with it?
      4. I want to see a more complex example!
      5. Can I use JavaScript libraries?
      6. Should I inject JavaScript libraries?
      7. What about asynchronous scripts?
      8. Summary
    15. 8. Keeping It Real
      1. Downloading files with Selenium
        1. The scenario
        2. The problem
        3. So, what's next?
        4. Do you really need to download that file?
        5. Checking whether links are valid
        6. What if I do need to download the file?
          1. AutoIt
          2. The Java Robot class
          3. Browser auto download
          4. Extending our existing code
        7. Downloading a file with the help of Selenium
          1. But that's not the same as clicking on a link and downloading the file…
          2. Checking whether we have downloaded the correct file
      2. You cannot track the network traffic with Selenium
      3. But I really want to track my network traffic!
      4. Writing performance tests with Selenium
      5. Penetration testing with Selenium
      6. Summary
    16. 9. Hooking Docker into Selenium
      1. Introducing Docker
      2. Installing Docker
        1. Linux
        2. Windows / OS X
        3. But it didn't work…
        4. Getting started with boot2docker
      3. Spinning up a Selenium Grid with Docker
      4. Running tests against our new Selenium Grid
      5. Starting up Docker containers as part of the build
      6. Using a Docker Maven plugin
      7. The future with Docker
      8. Summary
    17. 10. Selenium – the Future
      1. Selenium – the future of browser and device testing
      2. If Selenium is the future, how can I help?
        1. Getting set up to contribute to a Selenium repository
        2. Aiding the documentation effort
      3. Making changes to Selenium
        1. Keeping your history clean
        2. Now it's your turn
      4. Summary
    18. Index