Java with Selenium/TestNG Examples
These examples show how to run the rulesets using a Selenium/TestNG framework:
We assume the following are installed:
$ chromedriver --version ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) $ java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode) $ mvn --version Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700) Maven home: C:\apache-maven-3.1.1 Java version: 1.8.0_144, vendor: Oracle Corporation Java home: C:\Program Files\Java\jdk1.8.0_144\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
Note: Java 8 and Maven 3 are required but other than that, versions may vary.
If the prerequisite has not been installed, first use the information below to install, then run the appropriate commands to print the version (ie verify the installation by running the commands above).
See Chrome Driver Help for more information about installation.
Note: Make sure the "$HOME/bin" directory exists, it is on the system path and that ChromeDriver is placed within the directory.
Maven is used to download the following libraries, which are needed to run this example:
Running Rulesets Against a Website
Step 0: Download Code and Change the Directory
Run the following commands:
git clone https://github.com/eBay/accessibility-ruleset-runner/ cd accessibility-ruleset-runner/examples/java
Note: If you are working from a forked repository, you might use slightly different commands than those given above. Also, if you have already downloaded the code, you can skip step.
Step 1: Install Package Dependencies
To install dependencies, run the following command from the examples/java directory:
mvn install -e -DskipTests=true -s settings_apache_maven_repo.xml
Step 2: Invoke the Ruleset Runner
To run the Rulesets, run the following command from the examples/java directory:
mvn test -e -Dtest=arr.AccessibilityRulesetRunnerTest -s settings_apache_maven_repo.xml
The above command explicitly defines the location of the settings file and test but the following command should also work:
Test Another Website
The examples are setup to be run without any configuration necessary. However, users can test a different url by modifying the following line:
mvn test -e -DURLS_TO_TEST="[Google] http://www.google.com"
In addition, sometimes users need to sign in, load urls, click buttons, etc before testing a View. Consider making the appopriate modifications necessary for your use case.
Include in Your Project
The Test NG Test follows the steps outlined in General Steps for Running Rulesets. For each of these steps, we add some additional comments.
Various parameters/properties were included to give examples of possible parameters that would be needed in a test environment. In addition, code is included to ensure that default properties are overridden by system properties and Jenkins parameters.
This example includes a simple example of how to create an HTML report from the results JSON object.
In practice, multiple Views are tested simultaneously using a <a href='#selenium-grid">Selenium Grid. To run multiple Views, try something like:
mvn test -e -DURLS_TO_TEST="[EBay] http://www.ebay.com, [PayPal] http://www.paypal.com"
Results from multiple Views may be also be combined into a single JSON object. Then, an HTML report could be created which includes these Views, by modifying the JSONToHTMLConverter class and HTMLReportTemplate.html file appropriately.
Integrated Development Environments
Building a selenium grid provides a lot more capability in terms of testing. You will see some additional utility files included (need modification to work) that help with the following:
- Loading Jenkins Job, System and Default Properties
- Configuring Chrome, Firefox and Remote Web Driver
- Downloading ChromeDriver, GeckoDriver, InternetExplorerDriver
These utility files work in various environments:
- Developer Desktop/Laptop
- Jenkins Server
- Selenium Grid