This document provides 9 tips for using Selenium best practices and patterns for testing Java applications. It discusses using JSON for configuration, managing nodes with VisGrid, creating an ephemeral grid, managing driver binaries with WebDriverManager, alternatives to XPath such as providing predictable IDs, using the ISelect interface effectively, how the Action Builder can help, continuous testing for microservices using Jenkins as an orchestrator, and considering Selenium tests as their own application. Credits are provided for related GitHub repositories and a previous presentation on the topic.
3. REVISITING SELENIUM BEST PRACTICES AND PATTERNS
Copyright 2017 Accenture. All rights reserved. 3
SELENIUM RELOADED
Tips for Setting up a Selenium Grid
XPath and Testability
Effective use of APIs and Interfaces
Continuous Testing for Microservices
4. #TIP 1:
USING JSON FOR
CONFIGURATION
Copyright 2017 Accenture. All rights reserved. 4
5. #TIP 1: USING JSON FOR CONFIGURATION
Copyright 2017 Accenture. All rights reserved. 5
7. #TIP 2: MANAGING NODES WITH VISGRID
Copyright 2017 Accenture. All rights reserved. 7
VISGRID
DESKTOP JAVA APPLICATION THAT HELPS MANAGING HUBS AND
NODES
• Download from https://codoid.com/wp-content/uploads/2017/09/Visgrid-<version>.zip
• Decompress Visgrid-<version>.zip
• java –jar visgrid-1.14.jar
VisGrid is provided by Codoid (https://codoid.com/) under Apache License
9. #TIP 3: CREATING AN EPHEMERAL GRID
Copyright 2017 Accenture. All rights reserved. 9
YOU CAN CONFIGURE AND LAUNCH NODES FROM YOUR
CODE
• Add the Selenium Server dependency to your POM
10. #TIP 3: CREATING AN EPHEMERAL GRID
Copyright 2017 Accenture. All rights reserved. 10
Use the GridLauncher to create server instances with different roles
12. #TIP 4: MANAGING DRIVERS BINARIES
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 12
WebDriverManager
An OpenSource Project that helps one of the most commons
nightmares while using Selenium:
Managing the webdriver binaries.
https://github.com/bonigarcia/webdrivermanager
13. #TIP 4: MANAGING DRIVERS WITH
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 13
Add the dependency
Use the DriverManager
14. #TIP 4: MANAGING DRIVERS WITH
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 14
Fully configurable using the API
Or parameters
15. #TIP 5:
XPATH IS NOT
UNDER YOUR
CONTROL
Copyright 2017 Accenture. All rights reserved. 15
16. XPath usage in Selenium depends on:
Native capabilities for XPath of each browser
If not available, Selenium provides its own implementation
#TIP5: XPATH IS NOT UNDER YOUR CONTROL
17. An example from the Selenium documentation
#TIP5: XPATH IS NOT UNDER YOUR CONTROL
20. Instead of investing a lot in creating highly
complicated ways to interact with the elements in
your application, consider change the application
instead
- Overriding ID of your web elements
- Creating anchor elements that helps on
accessing your elements
#TIP6: ALTERNATIVES: PROVIDE
PREDICTABLE ID TO YOUR WEB ELEMENTS
23. The ISelect Interface provide methods to interact
with elements of type Select.
The Select implementation provides methods for:
• Select (by Index, by Value, by Text)
• Deselect (All, by Index, by Value, by Text)
Works with MultiSelect
#TIP7: USING API EFFECTIVELY: THE ISELECT
INTERFACE
25. We are using Selenium to emulate human
interaction with the application under test
The Action Interface Builder can be useful when
try to explicitly guide the interaction through your
web page
#TIP8: THE ACTION BUILDER CAN ALSO
HELPS