This repository shows how to do cross-browser testing with Selenium WebDriver in Java in four different ways:
- Using a local machine
- Using Selenium Grid
- Using a cloud testing platform (LambdaTest)
- Using visual testing (Applitools)
I chose to develop this project using Selenium WebDriver and Java because they are very popular choices for test automation. However, these techniques could be done with other tools (like Cypress and Playwright) and languages (like C#, JavaScript, Python, and Ruby) as well.
This repository contains one main test case that is implemented once for each of the four ways to do cross-browser testing.
The main test case is a login test for the Applitools demo app. The steps are:
- Load the login page.
- Verify that the login page loads correctly.
- Perform login.
- Verify that the main page loads correctly.
This repository is a Java Maven project. To build the project and run the tests, you will need to install the Java Development Kit (JDK) 17. It is recommended to use an IDE like IntelliJ IDEA.
All tests are located under src/test/java/com/automationpanda/
.
They are written using the JUnit 5 framework.
There are 4 test case classes, one for each cross-browser testing method:
Each test has unique setup needs and environment variables (documented below).
You can run tests individually from an IDE like IntelliJ IDEA.
You can also run tests using mvn test
(including single tests).
Just remember to set the required environment variables first!
Test class: LocalMachineTest
Extra setup:
- Install target browsers (Chrome, Firefox, Edge, Safari)
- Install target browser drivers (ChromeDriver, geckodriver, EdgeDriver)
Environment variables:
BROWSER
: (optional)chrome
,edge
,firefox
, orsafari
EDGE_DRIVER_PATH
: (required for Edge) the absolute path to EdgeDriver
Test class: SeleniumGridTest
Extra setup:
- You must set up your own Selenium Grid instance
- You could use VMs, containers, or Kubernetes for Selenium Grid infrastructure
- Read the Selenium Grid docs to learn how to set it up
- I used Ubuntu VMs on Digital Ocean
- 1 VM for the hub
- 2 VMs for 2 nodes
- Each node had Chrome and Firefox
- Config file and launch script copies are located under
segrid/
Environment variables:
BROWSER
: (optional)chrome
orfirefox
GRID_URL
: the URL for the Selenium Grid instance
Test class: CloudPlatformTest
Extra setup:
- You must have a LambdaTest account, which you can register for free
- Test results will appear in the LambdaTest dashboard
- Use LambdaTest's capabilities generator for env variable values
Environment variables:
LT_USERNAME
: your LambdaTest usernameLT_ACCESS_KEY
: your LambdaTest access keyGRID_URL
: (optional) the LambdaTest grid URLBROWSER_NAME
: (optional) the browser nameVERSION
: (optional) the browser versionPLATFORM
: (optional) the operating system or deviceRESOLUTION
: (optional) the viewport size
Test class: VisualSnapshotTest
Extra setup:
- You must have an Applitools account, which you can register for free
- You can change the cross-browser configurations in the
setUpVisualAI
method - Test results will appear in the Applitools dashboard
- The first time you run tests will save baseline snapshots
- The second time you run tests will compare the latest snapshots against baselines
- Change
DEMO_SITE
fromoriginal
tochanged
to introduce visual bugs
Environment variables:
APPLITOOLS_API_KEY
: your Applitools API keyDEMO_SITE
: (optional)original
orchanged
; the changed site introduces visual bugs