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

Selenium WebDriver 3 Practical Guide - Second Edition

Book Description

Real-world examples of cross-browser, mobile, and data-driven testing with all the latest features of Selenium WebDriver 3

Key Features

  • Unlock the full potential of Selenium to test your web applications
  • Use Selenium Grid for faster, parallel running, and cross-browser testing
  • Test iOS and Android Apps with Appium

Book Description

Selenium WebDriver is an open source automation tool implemented through a browser-specific driver, which sends commands to a browser and retrieves results. The latest version of Selenium 3 brings with it a lot of new features that change the way you use and setup Selenium WebDriver. This book covers all those features along with the source code, including a demo website that allows you to work with an HMTL5 application and other examples throughout the book.

Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations available. You will learn to strategize and handle rich web UI using advanced WebDriver API along with real-time challenges faced in WebDriver and solutions to handle them. You will discover different types and domains of testing such as cross-browser testing, load testing, and mobile testing with Selenium. Finally, you will also be introduced to data-driven testing using TestNG to create your own automation framework.

By the end of this book, you will be able to select any web application and automate it the way you want.

What you will learn

  • Understand what Selenium 3 is and how is has been improved than its predecessor
  • Use different mobile and desktop browser platforms with Selenium 3
  • Perform advanced actions, such as drag-and-drop and action builders on web page
  • Learn to use Java 8 API and Selenium 3 together
  • Explore remote WebDriver and discover how to use it
  • Perform cross browser and distributed testing with Selenium Grid
  • Use Actions API for performing various keyboard and mouse actions

Who this book is for

Selenium WebDriver 3 Practical Guide is for software quality assurance/testing professionals, software project managers, or software developers interested in using Selenium for testing their applications. Prior programming experience in Java is necessary.

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. Title Page
  2. Copyright and Credits
    1. Selenium WebDriver 3 Practical Guide Second Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Installing Java
      2. Installing Eclipse
      3. Download the example code files
      4. Download the color images
      5. Conventions used
    4. Get in touch
      1. Reviews
  6. Introducing WebDriver and WebElements
    1. Selenium Testing Tools
      1. Selenium WebDriver 
      2. Selenium Server
      3. Selenium IDE
    2. Differences between Selenium 2 and Selenium 3 
      1. Handling the browser  
      2.  Having better APIs
      3. Having developer support and advanced functionalities
      4. Testing Mobile Apps with Appium
    3. Setting up a project in Eclipse with Maven and TestNG using Java
    4. WebElements
    5. Locating WebElements using WebDriver 
      1. The findElement method
      2. The findElements method
      3. Inspecting Elements with Developer Tools
        1. Inspecting pages and elements with Mozilla Firefox
        2. Inspecting pages and elements in Google Chrome with Developer Tools
      4. Using the By locating mechanism
        1. The By.id() method
        2. The By.name() method
        3. The By.className() method
        4. The By.linkText() method
        5. The By.partialLinkText() method
        6. The By.tagName() method
        7. The By.xpath() method
        8. The By.cssSelector() method
    6. Interacting with WebElements
      1. Getting element properties and attributes
        1. The getAttribute() method
        2. The getText() method
        3. The getCssValue() method
        4. The getLocation() method
        5. The getSize() method
        6. The getTagName() method
      2. Performing actions on WebElements
        1. The sendKeys() method
        2. The clear() method
        3. The submit() method
      3. Checking the WebElement state
        1.  The isDisplayed() method
        2. The isEnabled() method
        3. The isSelected() method
    7. Summary
    8. Questions
    9. Further information
  7. Different Available WebDrivers
    1. Firefox Driver
      1. Using GeckoDriver
      2. Using Headless Mode
      3. Understanding the Firefox profile
        1. Adding the extension to Firefox
        2. Storing and retrieving a profile
      4. Dealing with Firefox preferences
        1. Setting preferences
        2. Understanding frozen preferences
    2. Chrome Driver
      1. Using Headless Mode
      2. Using Mobile Emulation for testing mobile web applications
      3. Adding ChromeExtensions
    3. InternetExplorerDriver
      1. Writing your first test script for the IE browser
      2. Understanding IEDriver capabilities
    4. Edge Driver
      1. Writing your first test script for the Edge browser
    5. Safari Driver
      1. Writing your first test script for the Safari browser
    6. Summary
    7. Questions
    8. Further information
  8. Using Java 8 Features with Selenium
    1. Introducing Java 8 Stream API
      1. Stream.filter()
      2. Stream.sort()
      3. Stream.map()
      4. Stream.collect()
      5. Stream.min() and Stream.max()
      6. Stream.count()
    2. Using Stream API with Selenium WebDriver
      1. Filtering and counting WebElements 
      2. Filtering element attributes
      3. Using the Map function to get the text value from elements
      4. Filtering and performing actions on WebElements
    3. Summary
    4. Questions
    5. Further information
  9. Exploring the Features of WebDriver
    1. Taking screenshots
    2. Locating target windows and Frames
      1. Switching among windows
      2. Switching between frames            
      3. Handling alerts   
    3. Exploring Navigate
    4. Waiting for WebElements to load
      1. Implicit wait time
      2. Explicit wait time
    5. Handling cookies
    6. Summary
    7. Questions
    8. Further information
  10. Exploring Advanced Interactions of WebDriver
    1. Understanding the build and perform actions
    2. Learning mouse based interactions
      1. The moveByOffset action
      2. The click at current location action
      3. The click on a WebElement action
      4. The click and hold at current location action
      5. The click and hold a WebElement action
      6. The release at current location action
      7. The release on another WebElement action 
      8. The moveToElement action
      9. The dragAndDropBy action
      10. The dragAndDrop action
      11. The double click at current location action
      12. The double click on WebElement action
      13. The context click on WebElement action
      14. The context click at current location action
    3. Learning keyboard-based interactions
      1. The keyDown and keyUp actions
      2. The sendKeys method
    4. Summary
    5. Questions
    6. Further information
  11. Understanding WebDriver Events
    1. Introducing the eventFiringWebDriver and eventListener classes 
    2. Creating an instance of EventListener 
      1. Implementing WebDriverEventListener 
      2. Extending AbstractWebDriverEventListener
      3. Creating a WebDriver instance 
      4. Creating EventFiringWebDriver and EventListener instances
      5. Registering EventListener with EventFiringWebDriver
      6. Executing and verifying the events
      7. Registering multiple EventListeners
    3. Exploring different WebDriver event listeners
      1. Listening for WebElement value changes
      2. Listening for the clicked WebElement
      3. Listening for a WebElement search event
      4. Listening for browser back-navigation
      5. Listening for browser forward-navigation
      6. Listening for browser NavigateTo events
      7. Listening for script execution
      8. Listening for an exception
      9. Unregistering EventListener with EventFiringWebDriver
      10. Performing accessibility testing
      11. Capturing page-performance metrics
    4. Summary
    5. Questions
    6. Further information
  12. Exploring RemoteWebDriver
    1. Introducing RemoteWebDriver
      1. Understanding Selenium Standalone Server
        1. Downloading Selenium Standalone Server
        2. Running the server
      2. Understanding the RemoteWebDriver client
        1. Converting an existing test script to use the RemoteWebDriver server
      3. Using RemoteWebDriver for Firefox
      4. Using RemoteWebDriver for Internet Explorer
    2. Understanding the JSON wire protocol                                                            
    3. Summary
    4. Questions
    5. Further information
  13. Setting up Selenium Grid
    1. Exploring Selenium Grid
    2. Understanding the hub
    3. Understanding the node
    4. Modifying the existing test script to use Selenium Grid
      1. Requesting for non-registered capabilities
      2. Queuing up the request if the node is busy 
      3. Dealing with two nodes with matching capabilities                                              
    5. Configuring Selenium Grid
      1. Specifying node-configuration parameters
        1. Setting supported browsers by a node
        2. Setting node timeouts
        3. Setting the limit on browser instances
        4. Reregistering the node automatically
        5. Setting node health-check times
        6. Unregistering an unavailable node
        7. Setting the browser timeout
      2. Hub-configuration parameters
        1. Waiting for a match of the desired capability
        2. Customized CapabilityMatcher
        3. WaitTimeout for a new session
      3. Different ways to specify the configuration
    6. Using cloud-based grids for cross-browser testing
    7. Summary
    8. Questions
    9. Further information
  14. The PageObject Pattern
    1. Creating test cases for our WordPress blog
      1. Test case 1 – adding a new post to our WordPress blog
      2. Test case 2 – deleting a post from our WordPress blog
      3. Test case 3 – counting the number of posts on our WordPress blog
    2. What is the PageObject pattern?
      1. Using the @FindBy annotation
      2. Understanding PageFactory
    3. Good practices for the PageObjects design
      1. Think of a web page as a services provider
      2. Always look for implied services
      3. Using PageObjects within a PageObject
        1. The AddNewPost PageObject
        2. The AllPostsPage PageObject
      4. Think of methods in PageObjects as services and not as user actions
      5. Identifying some WebElements on the fly
      6. Keeping the page-specific details off the test script
      7. Understanding loadable components
    4. Working on an end-to-end example of WordPress
      1. Looking at all the PageObjects
        1. The AdminLoginPage PageObject
        2. The AllPostsPage PageObject
        3. The AddNewPostPage PageObject
        4. The EditPostPage PageObject
        5. The DeletePostPage PageObject
      2. Looking at the test cases
        1. Adding a new post
        2. Editing a post
        3. Deleting a post
        4. Counting posts
    5. Summary
    6. Questions
    7. Further information
  15. Mobile Testing on iOS and Android using Appium
    1. Different forms of mobile applications
    2. Available software tools
    3. Automating iOS and Android tests using Appium
      1. Automating iOS Application tests
      2. Automating Android application tests
      3. Prerequisites for Appium
        1. Setting up Xcode
        2. Setting up Android SDK
        3. Creating the Android Emulator
      4. Installing Appium 
      5. Automating for iOS
      6. Automating for Android
      7. Using Device Cloud to run tests on Real Devices
    4. Summary
    5. Questions
    6. Further information
  16. Data-Driven Testing with TestNG
    1. Overview of data-driven testing
    2. Parameterizing Tests using suite parameters
    3. Parameterizing Tests with a Data Provider
      1. Reading data from a CSV file
      2. Reading data from an Excel file
    4. Summary
    5. Questions
    6. Further information
  17. Assessments
    1. Chapter 1 
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think