Learn Selenium
Unmesh Gundecha Carl Cocchiaro更新时间:2021-06-24 13:26:48
最新章节:Leave a review - let other readers know what you thinkcoverpage
Title Page
Copyright
Learn Selenium
Contributors
About the authors
Packt is searching for authors like you
About Packt
Why subscribe?
Packt.com
Preface
Who this book is for
What this book covers
To get the most out of this book
Installing Java
Installing Eclipse
Download the example code files
Conventions used
Get in touch
Reviews
Introducing WebDriver and WebElements
Selenium Testing Tools
Selenium WebDriver
Selenium Server
Selenium IDE
Differences between Selenium 2 and Selenium 3
Handling the browser
Having better APIs
Having developer support and advanced functionalities
Testing Mobile Apps with Appium
Setting up a project in Eclipse with Maven and TestNG using Java
WebElements
Locating WebElements using WebDriver
The findElement method
The findElements method
Inspecting Elements with Developer Tools
Inspecting pages and elements with Mozilla Firefox
Inspecting pages and elements in Google Chrome with Developer Tools
Using the By locating mechanism
The By.id() method
The By.name() method
The By.className() method
The By.linkText() method
The By.partialLinkText() method
The By.tagName() method
The By.xpath() method
The By.cssSelector() method
Interacting with WebElements
Getting element properties and attributes
The getAttribute() method
The getText() method
The getCssValue() method
The getLocation() method
The getSize() method
The getTagName() method
Performing actions on WebElements
The sendKeys() method
The clear() method
The submit() method
Checking the WebElement state
The isDisplayed() method
The isEnabled() method
The isSelected() method
Summary
Questions
Further information
Using Java 8 Features with Selenium
Introducing Java 8 Stream API
Stream.filter()
Stream.sort()
Stream.map()
Stream.collect()
Stream.min() and Stream.max()
Stream.count()
Using Stream API with Selenium WebDriver
Filtering and counting WebElements
Filtering element attributes
Using the Map function to get the text value from elements
Filtering and performing actions on WebElements
Summary
Questions
Further information
Exploring the Features of WebDriver
Taking screenshots
Locating target windows and Frames
Switching among windows
Switching between frames
Handling alerts
Exploring Navigate
Waiting for WebElements to load
Implicit wait time
Explicit wait time
Handling cookies
Summary
Questions
Further information
Exploring Advanced Interactions of WebDriver
Understanding the build and perform actions
Learning mouse based interactions
The moveByOffset action
The click at current location action
The click on a WebElement action
The click and hold at current location action
The click and hold a WebElement action
The release at current location action
The release on another WebElement action
The moveToElement action
The dragAndDropBy action
The dragAndDrop action
The double click at current location action
The double click on WebElement action
The context click on WebElement action
The context click at current location action
Learning keyboard-based interactions
The keyDown and keyUp actions
The sendKeys method
Summary
Questions
Further information
Understanding WebDriver Events
Introducing the eventFiringWebDriver and eventListener classes
Creating an instance of EventListener
Implementing WebDriverEventListener
Extending AbstractWebDriverEventListener
Creating a WebDriver instance
Creating EventFiringWebDriver and EventListener instances
Registering EventListener with EventFiringWebDriver
Executing and verifying the events
Registering multiple EventListeners
Exploring different WebDriver event listeners
Listening for WebElement value changes
Listening for the clicked WebElement
Listening for a WebElement search event
Listening for browser back-navigation
Listening for browser forward-navigation
Listening for browser NavigateTo events
Listening for script execution
Listening for an exception
Unregistering EventListener with EventFiringWebDriver
Performing accessibility testing
Capturing page-performance metrics
Summary
Questions
Further information
Exploring RemoteWebDriver
Introducing RemoteWebDriver
Understanding Selenium Standalone Server
Downloading Selenium Standalone Server
Running the server
Understanding the RemoteWebDriver client
Converting an existing test script to use the RemoteWebDriver server
Using RemoteWebDriver for Firefox
Using RemoteWebDriver for Internet Explorer
Understanding the JSON wire protocol
Summary
Questions
Further information
Setting up Selenium Grid
Exploring Selenium Grid
Understanding the hub
Understanding the node
Modifying the existing test script to use Selenium Grid
Requesting for non-registered capabilities
Queuing up the request if the node is busy
Dealing with two nodes with matching capabilities
Configuring Selenium Grid
Specifying node-configuration parameters
Setting supported browsers by a node
Setting node timeouts
Setting the limit on browser instances
Reregistering the node automatically
Setting node health-check times
Unregistering an unavailable node
Setting the browser timeout
Hub-configuration parameters
Waiting for a match of the desired capability
Customized CapabilityMatcher
WaitTimeout for a new session
Different ways to specify the configuration
Using cloud-based grids for cross-browser testing
Summary
Questions
Further information
Data-Driven Testing with TestNG
Overview of data-driven testing
Parameterizing Tests using suite parameters
Parameterizing Tests with a Data Provider
Reading data from a CSV file
Reading data from an Excel file
Summary
Questions
Further information
Building a Scalable Selenium Test Driver Class for Web and Mobile Applications
Introduction
Data-driven testing
Selenium Page Object Model
DRY
What you will learn
The singleton driver class
Requirements
The class signature
Class variables
JavaDoc
Parameters
Class methods
Using preferences to support browsers and platforms
Browser preferences
Platforms
Using preferences to support mobile device simulators emulators and real devices
iOS preferences
Android preferences
Multithreading support for parallel and distributed testing
Passing optional arguments and parameters to the driver
varargs
The parameter for setDriver
JVM argument – -Dswitch
Parameter processing methods
Selenium Grid Architecture support using the RemoteWebDriver and AppiumDriver classes
Third-party grid architecture support including the Sauce Labs Test Cloud
Using property files to select browsers devices versions platforms languages and many more
Summary
Selenium Framework Utility Classes
Introduction
Global variables
Synchronization utility classes
Selenium synchronization classes
The ExpectedConditions class
WebDriverWait/FluentWait classes
Custom synchronization methods
The JavascriptExecutor class
The TestNG Listener class
Building the test listener class
Logging the results to the console or log file
Including the test runner in the test class or suite
File I/O class
Property files
Lookup table files
CSV files
Log files
The image capture class
The capture screen method
The capture image method
The compare image method
The reporter class
The JavaMail class
Summary
Best Practices for Building Selenium Page Object Classes
Introduction
What you will learn
Best practices for naming conventions comments and folder structures
Naming conventions
Comments
Folder names and structures
Designing and building the abstract base classes for the AUT
The abstract class
Abstract methods
Common locators
Common methods
Wrap up on base classes
Designing and building subclasses for feature-specific pages using inheritance techniques
Encapsulation and using getter/setter methods to retrieve objects from the page object classes
Exception handling and synchronization in page object class methods
Implicit exception handling
TestNG difference viewer
Explicit exception handling
Try...catch exception handling
Synchronizing methods
Table classes
Summary
Defining WebDriver and AppiumDriver Page Object Elements
Introduction
Inspecting page elements on browser applications
Types of locators
Inheriting WebElements
Inspecting WebElements
Third-party plugins/tools
Inspection of page elements on mobile applications
Appium inspector
Inspecting mobile elements
Standards for using static locators
Rules for using standard locators
Simple locators
CSS locators
XPath query locators
Referencing static elements in methods
Retrieving static elements from other classes
Standards for using dynamic locators
Single attribute XPath versus CSS locators
WebElements
MobileElements
Multiple attribute XPath versus CSS locators
Using dynamic locators in methods
Summary
Building a JSON Data Provider
Introduction
What you will learn
The TestNG Data Provider class
The @DataProvider annotation
The @Test annotation
Extracting JSON data into Java objects
Filtering test data
Filtering include and exclude patterns
JSON Data File formats
The JSONObject class
Summary
Developing Data-Driven Test Classes
Introduction
Annotating test class methods using TestNG
TestNG annotations
@Test
TestNG setup/teardown methods
Setup methods
@BeforeSuite @BeforeTest @BeforeGroups @BeforeClass and @BeforeMethod
Teardown methods
@AfterSuite @AfterTest @AfterGroups @AfterClass and @AfterMethod
Order of precedence
Naming conventions for test methods
Test classes and data files
Test methods
Test parameters
Test groups
Test setup/teardown methods
Using the TestNG DataProvider
Calling page object methods in test classes
Exception handling in test classes
Test methods
The setup/teardown methods
The ITestResult class
Test listener/reporter classes
Designing base setup classes
TestNG suite file structure
Suite section: <suite>
Groups section: <groups>
Listeners section: <listeners>
Test section: <test>
Suite parameters
@Parameters
Summary
Encapsulating Data in Data-Driven Testing
Introduction
Casting JSON data to Java objects
JSON object
Sequential numbering of row IDs in the data file
Using Java object getter/setter methods
Passing data to page object methods
Building in positive negative boundary and limit testing
Negative testing
Confirmation and exception property files
Property files
Lookup method in DataProvider
JSON data file data
Converting confirmation/error code on the fly
Property files and parsing test data on the fly
Environment property files
System properties
Initializing property file data
Global variables versus dynamic data
Processing JVM args
Retrieving JSON data outside of test methods
Supporting multibranded applications
Multilocators
Conditional code
Runtime flags
Multiple driver support
Dual WebDriver testing
Dual WebDriver and AppiumDriver testing
Parallel testing
Suite XML file
Parallel properties method
Common setup
Summary
Designing a Selenium Grid
Introduction
Virtual grids
Grid structure
Single browser nodes
Multibrowser nodes
Single mobile device nodes
Multimobile/browser nodes
Selenium driver class – WebDriver versus RemoteWebDriver
The setDriver method for browser
The setDriver method for mobile
Overloaded setDriver method for browser
Switching from local to remote driver
Suite parameters
JVM argument
Default global variables
Processing runtime parameters
Selenium standalone server and client drivers
Local use of drivers
Remote use of drivers
Selenium standalone server and browser driver command-line options
Selenium hub
Selenium hub JSON configuration file
Selenium nodes
Selenium node JSON configuration file
Appium server and mobile simulator/emulator command-line options
Appium nodes
Appium node JSON configuration file
Selenium Grid console
Directing traffic to Selenium nodes
Multiple nodes of the same platform and version
Directing traffic using desired capabilities
Maintenance of the Selenium Grid
Summary
Third-Party Tools and Plugins
Introduction
IntelliJ IDEA Selenium plugin
Sample project files
Generating element locators
Wrap-up on Selenium Plugin
TestNG results in IntelliJ and Jenkins
IntelliJ TestNG results
Jenkins TestNG results
HTML Publisher Plugin
Installation
BrowserMob Proxy Plugin
Getting started
ExtentReports Reporter API class
ExtentHTMLReporter
Dashboard page
Categories page
Tests page
Code sample
Sauce Labs Test Cloud services
Sauce Labs Test Cloud features
Browser and mobile platforms
Driver code changes
Dashboard
SauceConnect tunnel
TestObject Real Device Cloud
Jenkins plugin
Advantages and disadvantages of using in-house versus third-party grids
Summary
Working Selenium WebDriver Framework Samples
Introduction
Selenium driver and DataProvider classes
CreateDriver.java
JSONDataProvider class
Selenium utility classes
BrowserUtils.java
Global_VARS.java
TestNG_ConsoleRunner.java
selenium.properties
ExtentReports classes
ExtentTestNGIReporterListener.java
extent-config.xml
Browser page object base and subclasses
PassionTeaCoBasePO.java
PassionTeaCoWelcomePO.java
Browser test class and data files
PassionTeaCoTest.java
PassionTeaCo.json
Browser Suite XML and Maven Pom XML files
PassionTeaCo.xml
pom.xml file
Summary
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Other Books You May Enjoy
Leave a review - let other readers know what you think
更新时间:2021-06-24 13:26:48