Set up Running Java Selenium Tests in BuildWise CT Server

A quick guide to run Java Selenium Tests in BuildWise, an international award-winning, free & open-source Continuous Testing server.

Courtney Zhan
5 min readOct 7, 2023

This article shows you how to set up Selenium WebDriver tests written in Java on a Continuous Testing (CT) server, BuildWise.

Before you start

Make sure you have JDK installed (version 8+), some JUnit tests and BuildWise ready to go.

1. Install JDK

Verify by running java -version command in a terminal window.

2. Install Apache Ant

Verify by running ant -v command.

3. Chrome browser and ChromeDriver

Download the Chrome browser. To allow Selenium scripts to automate Chrome, you’ll also need ChromeDriver.

For Selenium v4.11 and greater, the installation of ChromeDriver is already taken care of, so you can skip this step.

Manually installing ChromeDriver (optional)
Download it here (selecting the version matching your Chrome) and put chromedriver.exe into a folder in PATH, e.g. C:\Ruby32-x64\bin.

4. Clone Sample Selenium Java tests

There are sample Selenium JUnit4 tests available on Github, under the e2e-junit-selenium. (You should also install Git if you do not have it. If you are unfamiliar with Git, check out the 10-Minute Guide to Git Version Control for Testers).

> git clone https://github.com/testwisely/buildwise-samples
> cd buildwise-samples/e2e-junit-selenium

5. Verify compilation succeeds

This is to verify that JDK, Apache Ant work and the libraries (.jar files) exist.

% ant clean compile
Buildfile: /Users/ME/work/buildwise-samples/e2e-junit-selenium/build.xml

clean:

compile:
[mkdir] Created dir: /Users/ME/work/buildwise-samples/e2e-junit-selenium/build/classes
[javac] Compiling 8 source files to /Users/ME/work/buildwise-samples/e2e-junit-selenium/build/classes

BUILD FAILED
/Users/ME/work/buildwise-samples/e2e-junit-selenium/build.xml:41: /Users/ME/work/buildwise-samples/e2e-junit-selenium/lib/junit4 does not exist.

Total time: 0 seconds

It is failing because the libraries are not set up yet. In the build.xml, the libraries folder, lib, is a symbolic link to lib@ -> /Users/Shared/Java.lib.

<property name="lib.dir" value="lib"/>

Create the folder /Users/Shared/Java.lib.

Then, download JUnit4 and Selenium Java libraries, and Java.lib should look like like below at the end.

Inside junit4, download:

Download Selenium Java from Selenium’s website (this will be Java.lib/selenium-java-4.x.x).

The newly downloaded selenium-java-4.x.x folder has a lib subfolder. Move the subfolder out of selenium-java-4.x.x and into a new sibling folder called selenium-dependent. Your set up should look like the screenshot above.

Now, your set up will match the build.xml (view it on Github).

<path id="classpath">
<fileset dir="${lib.dir}/junit4" includes="*.jar"/>
<fileset dir="${lib.dir}/selenium-dependent" includes="*.jar"/>
<fileset dir="${lib.dir}/selenium-java-4.13.0" includes="*.jar"/>
<pathelement location="${classes.dir}" />
</path>

If you run ant clean compile again, you should see a successful output like below.

Buildfile: /Users/ME/work/sandbox/buildwise-samples/e2e-junit-selenium/build.xml

clean:

compile:
[mkdir] Created dir: /Users/ME/work/sandbox/buildwise-samples/e2e-junit-selenium/build/classes
[javac] Compiling 8 source files to /Users/ME/work/sandbox/buildwise-samples/e2e-junit-selenium/build/classes

BUILD SUCCESSFUL

5. Verify Test Execution

This is to verify ChromeDriver, and the whole thing.

> ant go

A Chrome browser window will open and begin executing the test.

Sample output:

compile:

runAll:
[mkdir] Created dir: /Users/ME/work/buildwise-samples/e2e-junit-selenium/tmp
[mkdir] Created dir: /Users/ME/work/buildwise-samples/e2e-junit-selenium/reports
[echo] Test results (xml files) shall be in /Users/ME/work/buildwise-samples/e2e-junit-selenium/reports

verifyNoError:

verifyNoFailure:

go:

BUILD SUCCESSFUL
Total time: 16 seconds

6. Install and run BuildWise

Then, install BuildWise (v2.3.7+), a CT server. You can follow this article’s 3rd and 4th steps to install and run the server.

Set Up the CT Server for Executing Selenium-JUnit tests

First, create a new BuildWise project for the sample tests.

You can ignore the test framework on the bottom-right, we will change that shortly.

After the project is created, click on the project name to edit the project.

Under Build Steps, create a new Compile step. This will clean and compile the project before every build (test execution).

One the step is created, change it’s type to “Command” to execute cd e2e-junit-selenium; ant clean compile. Then, drag the Compile step to the top so it executes first. Uncheck the “UI Test” step and set the framework drop-down to “JUnit Ant (Java)”. Save the project configuration.

The build steps should now look like the below:

On the BuildWise home page, click “Build Now”.

You should see the build and the compile step complete successfully.

Now that we can compile the project, we can move on to running it. Go back to the project edit page and add another build step “UI Test (Ant)” that runs ant go.

Save the changes, and trigger a new build. You should see the tests open a new Chrome browser and execute.

Screenshot after the build completes successfully.

--

--