Learn Selenium

Book description

Learn end-to-end automation testing techniques for web and mobile browsers using Selenium WebDriver, AppiumDriver, Java, and TestNG

Key Features

  • Explore the Selenium grid architecture and build your own grid for browser and mobile devices
  • Use ExtentReports for processing results and SauceLabs for cloud-based test services
  • Unlock the full potential of Selenium to test your web applications.

Book Description

Selenium WebDriver 3.x is an open source API for testing both browser and mobile applications. With the help of this book, you can build a solid foundation and can easily perform end-to-end testing on web and mobile browsers.You'll begin by being introduced to the Selenium Page Object Model for software development. You'll architect your own framework with a scalable driver class, Java utility classes, and support for third-party tools and plugins. You'll design and build a Selenium grid from scratch to enable the framework to scale and support different browsers, mobile devices, and platforms.You'll strategize and handle a rich web UI using the advanced WebDriver API and learn techniques to handle real-time challenges in WebDriver. You'll perform different types of testing, such as cross-browser testing, load testing, and mobile testing. Finally, you will also be introduced to data-driven testing, using TestNG to create your own automation framework.By the end of this Learning Path, you'll be able to design your own automation testing framework and perform data-driven testing with Selenium WebDriver.

This Learning Path includes content from the following Packt products:

  • Selenium WebDriver 3 Practical Guide - Second Edition by Unmesh Gundecha
  • Selenium Framework Design in Data-Driven Testing by Carl Cocchiaro

What you will learn

  • Use different mobile and desktop browser platforms with Selenium 3
  • Use the Actions API for performing various keyboard and mouse actions
  • Design the Selenium Driver Class for local, remote, and third-party grid support
  • Build page object classes with the Selenium Page Object Model
  • Develop data-driven test classes using the TestNG framework
  • Encapsulate data using the JSON protocol
  • Build a Selenium Grid for RemoteWebDriver testing
  • Build and use utility classes in synchronization, file I/O, reporting and test listener classes

Who this book is for

This Learning Path is ideal for software quality assurance/testing professionals, software project managers, or software developers interested in using Selenium for testing their applications. Professionals responsible for designing and building enterprise-based testing frameworks will also find this Learning Path useful. Prior programming experience in Java are TestNG is necessary.

Downloading the example code for this ebook: You can download the example code files for this ebook on GitHub at the following link: https://github.com/PacktPublishing/Learn-Selenium. If you require support please email: customercare@packt.com

Table of contents

  1. Title Page
  2. Copyright
    1. Learn Selenium
  3. Contributors
    1. About the authors
    2. Packt is searching for authors like you
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  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. 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. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. Building a Scalable Selenium Test Driver Class for Web and Mobile Applications
    1. Introduction
      1. Data-driven testing
      2. Selenium Page Object Model
      3. DRY 
      4. What you will learn
    2. The singleton driver class
      1. Requirements
      2. The class signature
      3. Class variables
      4. JavaDoc
      5. Parameters
      6. Class methods
    3. Using preferences to support browsers and platforms
      1. Browser preferences
      2. Platforms
    4. Using preferences to support mobile device simulators, emulators, and real devices
      1. iOS preferences
      2. Android preferences
    5. Multithreading support for parallel and distributed testing
    6. Passing optional arguments and parameters to the driver
      1. varargs
      2. The parameter for setDriver
      3. JVM argument – -Dswitch
      4. Parameter processing methods
    7. Selenium Grid Architecture support using the RemoteWebDriver and AppiumDriver classes
    8. Third-party grid architecture support including the Sauce Labs Test Cloud
    9. Using property files to select browsers, devices, versions, platforms, languages, and many more
    10. Summary
  15. Selenium Framework Utility Classes
    1. Introduction
    2. Global variables
    3. Synchronization utility classes
      1. Selenium synchronization classes
        1. The ExpectedConditions class
        2. WebDriverWait/FluentWait classes
        3. Custom synchronization methods
    4. The JavascriptExecutor class
    5. The TestNG Listener class
      1. Building the test listener class
      2. Logging the results to the console or log file
      3. Including the test runner in the test class or suite
    6. File I/O class
      1. Property files
      2. Lookup table files
      3. CSV files
      4. Log files
    7. The image capture class
      1. The capture screen method
      2. The capture image method
      3. The compare image method
    8. The reporter class
    9. The JavaMail class
    10. Summary
  16. Best Practices for Building Selenium Page Object Classes
    1. Introduction
      1. What you will learn
    2. Best practices for naming conventions, comments, and folder structures
      1. Naming conventions
      3. Folder names and structures
    3. Designing and building the abstract base classes for the AUT
      1. The abstract class
      2. Abstract methods
      3. Common locators
      4. Common methods
      5. Wrap up on base classes
    4. Designing and building subclasses for feature-specific pages using inheritance techniques
    5. Encapsulation and using getter/setter methods to retrieve objects from the page object classes
    6. Exception handling and synchronization in page object class methods
      1. Implicit exception handling
        1. TestNG difference viewer
      2. Explicit exception handling
      3. Try...catch exception handling
      4. Synchronizing methods
    7. Table classes
    8. Summary
  17. Defining WebDriver and AppiumDriver Page Object Elements
    1. Introduction
    2. Inspecting page elements on browser applications
      1. Types of locators
      2. Inheriting WebElements
      3. Inspecting WebElements
      4. Third-party plugins/tools
    3. Inspection of page elements on mobile applications
      1. Appium inspector
      2. Inspecting mobile elements
    4. Standards for using static locators
      1. Rules for using standard locators
        1. Simple locators
        2. CSS locators
        3. XPath query locators
      2. Referencing static elements in methods
      3. Retrieving static elements from other classes
    5. Standards for using dynamic locators
      1. Single attribute XPath versus CSS locators
        1. WebElements
        2. MobileElements
      2. Multiple attribute XPath versus CSS locators
      3. Using dynamic locators in methods
    6. Summary
  18. Building a JSON Data Provider
    1. Introduction
      1. What you will learn
    2. The TestNG Data Provider class
      1. The @DataProvider annotation
      2. The @Test annotation
    3. Extracting JSON data into Java objects
    4. Filtering test data
      1. Filtering include and exclude patterns
    5. JSON Data File formats
    6. The JSONObject class
    7. Summary
  19. Developing Data-Driven Test Classes
    1. Introduction
    2. Annotating test class methods using TestNG
      1. TestNG annotations
        1. @Test
    3. TestNG setup/teardown methods
      1. Setup methods
        1. @BeforeSuite, @BeforeTest, @BeforeGroups, @BeforeClass, and @BeforeMethod
      2. Teardown methods
        1. @AfterSuite, @AfterTest, @AfterGroups, @AfterClass, and @AfterMethod
      3. Order of precedence
    4. Naming conventions for test methods
      1. Test classes and data files
      2. Test methods
      3. Test parameters
      4. Test groups
      5. Test setup/teardown methods
    5. Using the TestNG DataProvider
    6. Calling page object methods in test classes
    7. Exception handling in test classes
      1. Test methods
      2. The setup/teardown methods
      3. The ITestResult class
      4. Test listener/reporter classes
    8. Designing base setup classes
    9. TestNG suite file structure
      1. Suite section: <suite>
      2. Groups section: <groups>
      3. Listeners section: <listeners>
      4. Test section: <test>
    10. Suite parameters
      1. @Parameters
    11. Summary
  20. Encapsulating Data in Data-Driven Testing
    1. Introduction
    2. Casting JSON data to Java objects
      1. JSON object
      2. Sequential numbering of row IDs in the data file
      3. Using Java object getter/setter methods
      4. Passing data to page object methods
    3. Building in positive, negative, boundary, and limit testing
      1. Negative testing
    4. Confirmation and exception property files
      1. Property files
      2. Lookup method in DataProvider
      3. JSON data file data
      4. Converting confirmation/error code on the fly
    5. Property files and parsing test data on the fly
      1. Environment property files
      2. System properties
      3. Initializing property file data
    6. Global variables versus dynamic data
    7. Processing JVM args
    8. Retrieving JSON data outside of test methods
    9. Supporting multibranded applications
      1. Multilocators
      2. Conditional code
      3. Runtime flags
    10. Multiple driver support
      1. Dual WebDriver testing
      2. Dual WebDriver and AppiumDriver testing
    11. Parallel testing
      1. Suite XML file
      2. Parallel properties method
      3. Common setup
    12. Summary
  21. Designing a Selenium Grid
    1. Introduction
    2. Virtual grids
      1. Grid structure
      2. Single browser nodes
      3. Multibrowser nodes
      4. Single mobile device nodes
      5. Multimobile/browser nodes
    3. Selenium driver class – WebDriver versus RemoteWebDriver
      1. The setDriver method for browser
      2. The setDriver method for mobile
      3. Overloaded setDriver method for browser
    4. Switching from local to remote driver
      1. Suite parameters
      2. JVM argument
      3. Default global variables
      4. Processing runtime parameters
    5. Selenium standalone server and client drivers
      1. Local use of drivers
      2. Remote use of drivers
    6. Selenium standalone server and browser driver command-line options
      1. Selenium hub
      2. Selenium hub JSON configuration file
      3. Selenium nodes
      4. Selenium node JSON configuration file
    7. Appium server and mobile simulator/emulator command-line options
      1. Appium nodes
      2. Appium node JSON configuration file
    8. Selenium Grid console
    9. Directing traffic to Selenium nodes
      1. Multiple nodes of the same platform and version
      2. Directing traffic using desired capabilities
      3. Maintenance of the Selenium Grid
      4. Summary
  22. Third-Party Tools and Plugins
    1. Introduction
    2. IntelliJ IDEA Selenium plugin
      1. Sample project files
      2. Generating element locators
      3. Wrap-up on Selenium Plugin
    3. TestNG results in IntelliJ and Jenkins
      1. IntelliJ TestNG results
      2. Jenkins TestNG results
    4. HTML Publisher Plugin
      1. Installation
    5. BrowserMob Proxy Plugin
      1. Getting started
    6. ExtentReports Reporter API class
      1. ExtentHTMLReporter
      2. Dashboard page
      3. Categories page
      4. Tests page
      5. Code sample
    7. Sauce Labs Test Cloud services
      1. Sauce Labs Test Cloud features
        1. Browser and mobile platforms
        2. Driver code changes
        3. Dashboard
        4. SauceConnect tunnel
        5. TestObject Real Device Cloud
        6. Jenkins plugin
      2. Advantages and disadvantages of using in-house versus third-party grids
    8. Summary
  23. Working Selenium WebDriver Framework Samples
    1. Introduction
    2. Selenium driver and DataProvider classes
      1. CreateDriver.java
      2. JSONDataProvider class
    3. Selenium utility classes
      1. BrowserUtils.java
      2. Global_VARS.java
      3. TestNG_ConsoleRunner.java
      4. selenium.properties
    4. ExtentReports classes
      1. ExtentTestNGIReporterListener.java
      2. extent-config.xml
    5. Browser page object base and subclasses
      1. PassionTeaCoBasePO.java
      2. PassionTeaCoWelcomePO.java
    6. Browser test class and data files
      1. PassionTeaCoTest.java
      2. PassionTeaCo.json
    7. Browser Suite XML and Maven Pom XML files
      1. PassionTeaCo.xml
      2. pom.xml file
    8. Summary
  24. 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
  25. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Learn Selenium
  • Author(s): Unmesh Gundecha, Carl Cocchiaro
  • Release date: July 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781838983048