Hands-On Selenium WebDriver with Java

Book description

Get started with Selenium WebDriver, the open source library for automating tests to ensure your web application performs as expected. In this practical hands-on book, author Boni Garcia takes Java developers through Selenium's main features for automating web navigation, browser manipulation, web element interaction, and more, with ready-to-be-executed test examples.

You'll start by learning the core features of Selenium (composed of WebDriver, Grid, and IDE) and its ecosystem. Discover why Selenium WebDriver is the de facto library for developing end-to-end tests on your web application. You'll explore ways to use advanced Selenium WebDriver features, including using web browsers in Docker containers or the DevTools protocol. Selenium WebDriver examples in this book are available on GitHub.

With this book, you'll learn how to:

  • Set up a Java project containing end-to-end tests that use Selenium WebDriver
  • Conduct automated interaction with web applications
  • Use strategies for managing browser-specific capabilities and cross-browser testing
  • Interact with web forms, manage pop-up messages, and execute JavaScript
  • Control remote browsers and use advanced browser infrastructure for Selenium WebDriver tests in the cloud
  • Model web pages using object-oriented classes to ease test maintenance and reduce code duplication

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. Navigating This Book
      1. Part I, Introduction
      2. Part II, The Selenium WebDriver API
      3. Part III, Advanced Concepts
    4. Conventions Used in This Book
    5. Using Code Examples
    6. O’Reilly Online Learning
    7. How to Contact Us
    8. Acknowledgments
  3. I. Introduction
  4. 1. A Primer on Selenium
    1. Selenium Core Components
      1. Selenium WebDriver
      2. Selenium Grid
      3. Selenium IDE
    2. Selenium Ecosystem
      1. Language Bindings
      2. Driver Managers
      3. Locator Tools
      4. Frameworks
      5. Browser Infrastructure
      6. Community
    3. Software Testing Fundamentals
      1. Levels of Testing
      2. Types of Testing
      3. Testing Methodologies
      4. Test Automation Tools
    4. Summary and Outlook
  5. 2. Preparing for Testing
    1. Requirements
      1. Java Virtual Machine
      2. Text Editor or IDE
      3. Browsers and Drivers
      4. Build Tools
      5. Optional Software
    2. Project Setup
      1. Project Layout
      2. Dependencies
    3. Hello World
      1. Using Additional Browsers
    4. Summary and Outlook
  6. II. The Selenium WebDriver API
  7. 3. WebDriver Fundamentals
    1. Basic WebDriver Usage
      1. WebDriver Creation
      2. WebDriver Methods
      3. Session Identifier
      4. WebDriver Disposal
    2. Locating WebElements
      1. The Document Object Model (DOM)
      2. WebElement Methods
      3. Location Strategies
      4. Finding Locators on a Web Page
      5. Compound Locators
      6. Relative Locators
      7. What Strategy Should You Use?
    3. Keyboard Actions
      1. File Uploading
      2. Range Sliders
    4. Mouse Actions
      1. Web Navigation
      2. Checkboxes and Radio Buttons
    5. User Gestures
      1. Right-Click and Double-Click
      2. Mouseover
      3. Drag and Drop
      4. Click and Hold
      5. Copy and Paste
    6. Waiting Strategies
      1. Implicit Wait
      2. Explicit Wait
      3. Fluent Wait
    7. Summary and Outlook
  8. 4. Browser-Agnostic Features
    1. Executing JavaScript
      1. Synchronous Scripts
      2. Pinned Scripts
      3. Asynchronous Scripts
    2. Timeouts
      1. Page Loading Timeout
      2. Script Loading Timeout
    3. Screenshots
      1. WebElement Screenshots
    4. Window Size and Position
    5. Browser History
    6. The Shadow DOM
    7. Cookies
    8. Dropdown Lists
      1. Data List Elements
    9. Navigation Targets
      1. Tabs and Windows
      2. Frames and Iframes
    10. Dialog Boxes
      1. Alerts, Confirms, and Prompts
      2. Modal Windows
    11. Web Storage
    12. Event Listeners
    13. WebDriver Exceptions
    14. Summary and Outlook
  9. 5. Browser-Specific Manipulation
    1. Browser Capabilities
      1. Headless Browser
      2. Page Loading Strategies
      3. Device Emulation
      4. Web Extensions
      5. Geolocation
      6. Notifications
      7. Browser Binary
      8. Web Proxies
      9. Log Gathering
      10. Get User Media
      11. Loading Insecure Pages
      12. Localization
      13. Incognito
      14. Edge in Internet Explorer Mode
    2. The Chrome DevTools Protocol
      1. CDP Selenium Wrappers
      2. CDP Raw Commands
    3. Location Context
    4. Web Authentication
    5. Print Page
    6. WebDriver BiDi
    7. Summary and Outlook
  10. 6. Remote WebDriver
    1. Selenium WebDriver Architecture
    2. Creation of RemoteWebDriver Objects
      1. RemoteWebDriver Constructor
      2. RemoteWebDriver Builder
      3. WebDriverManager Builder
      4. Selenium-Jupiter
    3. Selenium Grid
      1. Standalone
      2. Hub-nodes
      3. Fully Distributed
      4. Observability
      5. Configuration
    4. Cloud Providers
    5. Browsers in Docker Containers
      1. Docker Images for Selenium Grid
      2. Selenoid
      3. WebDriverManager
      4. Selenium-Jupiter
    6. Summary and Outlook
  11. III. Advanced Concepts
  12. 7. The Page Object Model (POM)
    1. Motivation
    2. The POM Design Pattern
      1. Page Objects
      2. Robust Page Objects
    3. Creating a Domain Specific Language (DSL)
    4. Page Factory
    5. Summary and Outlook
  13. 8. Testing Framework Specifics
    1. Parameterized Tests
      1. Cross-Browser Testing
    2. Categorizing and Filtering Tests
    3. Ordering Tests
    4. Failure Analysis
    5. Retrying Tests
    6. Parallel Test Execution
    7. Test Listeners
    8. Disabled Tests
    9. Summary and Outlook
  14. 9. Third-Party Integrations
    1. File Download
      1. Using Browser-Specific Capabilities
      2. Using an HTTP Client
    2. Capture Network Traffic
    3. Nonfunctional Testing
      1. Performance
      2. Security
      3. Accessibility
      4. A/B Testing
    4. Fluent API
    5. Test Data
    6. Reporting
    7. Behavior Driven Development
    8. Web Frameworks
    9. Summary and Outlook
  15. 10. Beyond Selenium
    1. Mobile Apps
      1. Mobile Testing
      2. Appium
    2. REST Services
      1. REST Assured
    3. Alternatives to Selenium
      1. Cypress
      2. WebDriverIO
      3. TestCafe
      4. Puppeteer
      5. Playwright
    4. Summary and Final Remarks
  16. A. What’s New in Selenium 4
    1. Selenium WebDriver
      1. Migration Guide
    2. Selenium Grid
    3. Selenium IDE
    4. Other Novelties
  17. B. Driver Management
    1. WebDriverManager: Automated Driver Management
      1. Generic Manager
      2. Advanced Configuration
      3. Other Uses
    2. Manual Driver Management
    3. Summary
  18. C. Examples Repository Setup
    1. Project Layout
    2. Maven
      1. Common Setup
      2. JUnit 4
      3. JUnit 5
      4. Selenium-Jupiter
      5. TestNG
      6. Other Dependencies
    3. Gradle
      1. JUnit 4
      2. JUnit 5
      3. Selenium-Jupiter
      4. TestNG
      5. Other Dependencies
    4. Logging
    5. GitHub Actions
    6. Dependabot
    7. Summary
  19. Index
  20. About the Author

Product information

  • Title: Hands-On Selenium WebDriver with Java
  • Author(s): Boni Garcia
  • Release date: April 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098110000