Continuous Testing of a Java Web App in VSTS using Selenium

Posted by: Gouri Sohoni , on 12/2/2017, in Category VSTS & TFS (Azure DevOps)
Views: 22854
Abstract: How VSTS can be effectively used for CI/CD and Continuous Testing (CT) of a Java Web App using a non-Microsoft tool like Selenium.

Visual Studio Team Services (VSTS) is a cloud based service which provides features like Work Item Tracking, Source and Version Control (with Team Foundation Version Control as well as Git), Build and Release Management and Test Management. It is a fast and easy way for software and project creation, as a team.

It is a common perception that VSTS is a set of DevOps tools for developing software only on the Microsoft stack.

But that is a misconception!

VSTS is not just for the Microsoft platform, but for many others as well, for eg: for Java Development.

In this article I will show you how VSTS can be effectively used for CI/CD and Continuous Testing (CT) using a non-Microsoft tool like Selenium.

This article will provide the following guidance:

  • How a small Java Web Application can be created (using Eclipse IDE) which uses VSTS as source control.
  • How to write JUnit and Selenium Test for the same application.
  • How to create a Web App Service in Azure that is supported by Java and deploy the application on it.
  • How to run the Selenium Test on the deployed application.

We will use Source Control, Build and Release Management Services of VSTS for executing the above mentioned activities. We will also use the Microsoft Azure Portal to create a Java Web App Service. I will use Ant for building Java Application.

Here are the pre-requisites for this article:

1. Visual Studio Team Services (VSTS) Account with one Team Project created in it (it can be of any process template)

2. Account for Azure Portal to create Java Web App

3. Java SDK installed and added in JAVA_HOME environment variable.

4. Eclipse IDE, Ant and Apache Tomcat (if we want to view the application using Tomcat)

Using Eclipse with VSTS

1. Using Eclipse IDE create a Dynamic Web Project


2. I have added index.jsp in the WebContent folder which is in the src folder


3. Let us add some code to the project.

I have written a Validate method in the Validator class. I have also written code to call the method. Just some very basic functionality.


Connect to Team Explorer Everywhere

4. As we are going to use Visual Studio Team Services as our code repository, we need to connect to VSTS. Go to help in Eclipse, browse to the Eclipse Marketplace and search for Team Explorer Everywhere. Install and then you can open perspective for Team Foundation Server Exploring.



5. After adding code, we need to connect to VSTS and use TFVS as Source Control. Connect to VSTS and the Team Project in it.


6. Right click on the project > select Team > Check in pending changes. Provide the comment for check in and check in your code.


Write a JUnit Test and execute it in Eclipse IDE

7. We have created and checked in code for our Web Project. Now is the time to write the JUnit test.

JUnit is a framework for Java Programming Language. It helps in writing tests for functionality tests, and also for Test Drive Development (TDD).

If you are new to Unit Testing, check these tutorials:

Live Unit Testing in Visual Studio 2017

NUnit Testing with Visual Studio 2015

Smart Unit Tests in Visual Studio 2015

8. There are a few annotations for writing JUnit Tests. Firstly, we need to download the .jar files for JUnit. Provide the required import statements.

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

9. Let us write the actual code for the JUnit test.

public class ValidatorTest {
public static void main()

 public void TestValidate()
    Boolean actual, expected=true;
    Validator val = new Validator();
    actual = val.Validate("Gouri", "Sohoni");

10. We can execute the JUnit in Eclipse IDE itself. Right click on the test > select Run As > JUnit Test and you can see the result in runner.


The result looks as follows:


Add Ant for Build – xml file with targets

11. As I have already mentioned, I will be using Ant to build the code. We can Export the Ant Build files by right clicking on project and selecting Export > Ant Buildfiles


Ant provides build.xml file which consists of target and tasks. It has a project, which can have any number of targets and various tasks in it.

We can specify which is the default target (required) and the dependent target for the same. The build will then go on fetching the dependent target and execute the tasks in each one of them.

The build target can have tasks for compiling, the test target can have tasks for test execution and report task can be for creating test reports.

Following is an example of java compilation task:


12. Following is the example for a test target:


Observe this target depends on the pack target. The location to the .jar files is specified. I am creating a directory where the test results are stored. The test results will be put in an xml file.

Do not forget to check-in this file.

13. I have deployed the web app to Apache Tomcat server (optional) and started the server (to deploy and check if required).

14. Let us add code for Selenium test. Download selenium jar files from and unzip the files. Add support to external jar files.

  • Right click on project – Select Properties – Java Build Path
  • Navigate to Libraries tab and click Add External JARS
  • Add jar file from the unzipped folder and all jar files from the unzipped folder

Add code for Selenium Test

15. The code for selenium test looks as follows:

public void TestSSGSWeb() throws InterruptedException{
    ChromeOptions options = new ChromeOptions();
    WebDriver driver = new ChromeDriver(options);
    WebElement elementName = driver.findElement("uname"));
    WebElement elementPwd= driver.findElement("pwd"));
    WebElement elementLogin =     driver.findElement("submoit"));

This code creates instance for chrome driver, navigates to the local tomcat server (later I will change the url to Java Web Service created using Azure). It also enters values for user name and password and clicks on the submit button.

This test can be executed with Eclipse IDE, it will be running on the local tomcat server (if you have installed and started the server).

Next step is to create a server-side build.

Create Build Definition

16. We can create a build definition in VSTS by using the template for Ant.

In order to execute the build, we need a build agent. Build Agent is a computer where a specialized software is installed to run the workflow containing many tasks, as the steps for build or the release process.

VSTS can use an agent which is on premises of the customer or hosted in Azure. Build, Release Management and Test all can use the same agent. In this case I am going to use on premises build agent and not in cloud (as we need to execute JUnit tests as well as Selenium Test later).

We also will have to add the capability for running ant script.


17. In order to install build agent, we have to download the zip file for agent from Agent Queues.

After un zipping the file, we can configure the agent by running config from command prompt. Provide the url for VSTS account, PAT (Personal Access Token), the work folder, pool name. Run it as an interactive process and not as a service (this is required because we will be running UI test later).

18. In the build definition for Ant, it will add tasks for Get Sources, Ant, Copy and Publish files. Provide the link to the build.xml file in ant task as follows:


19. Click the check box for publishing test results. This will execute the tests and publish the result in the xml file.


Create Azure App Service supporting Java

20. Let us create a Java Web App Service for Azure. Login to azure portal, select New and select Web + Mobile and select Web App.


21. As we are going to use this web app service for Java, we do the following configuration:


I have selected Java version as 8.0, minor as latest and Tomcat version 9.0.0. I have also provided the deployment credentials for the web app service. Now is the time to change the url for Selenium Test to the newly created Web Service App and check in this changed code.

22. Trigger the build so as to create and publish the artifacts. Now we will proceed to deploying of the Web app by creating a Release.

Create Release Definition

23. Let us create a release definition and add FTP upload task. This task will upload the application to the Web App Service. We need to provide the credentials as variables so that the actual values will not be displayed. You can add variables by selecting Variables tab.


Source folder is the artifact drop folder where we need to copy the .war file. Tomcat Server requires the path to be site/wwwroot/WebApps as shown in remote directory.


24. We need the test results to be published so we will use ant specific build file which will not do any compilation, but will only run tests and publish reports. Add another .xml file for ant and change the targets so as to have only test and reports related targets in it.

Check in the file. Ensure that this file gets dropped in the drop artifacts via build.

25. Add Ant build task and configure it to execute the new .xml file (the one which has targets for only test and report). Save the release definition. The release definition looks as follows:


26. Create a release. After successful upload of the web app to Web App Service, the Selenium test gets executed. The test results can be found from the Test tab of release.


I have purposely failed one of the tests. The result is shown in the summary. The zip file which is provided as attachment shows the following:



In this article I discussed

  • how a Java Web application can be created,
  • added to Source Control on VSTS,
  • how to create JUnit and Selenium Tests for it,
  • how to create Azure Web App Services which supports Java,
  • how to deploy the app on this service.

We also discussed how build, release definitions can be created and triggered. We have seen how Ant build file can be used with the build as well as release definition.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Gouri is a Trainer and Consultant on Azure DevOps and Azure Development. She has an experience of three decades in software training and consulting. She is a graduate from Pune University and PGDCA from Pune University. Gouri is a Microsoft Most Valuable Professional (MVP)  - Developer Technologies (Azure DevOps), Microsoft Certified Trainer (MCT) and a Microsoft Certified Azure DevOps Engineer Expert. She has conducted over 150 corporate trainings on various Microsoft technologies. She is a speaker with Pune User Group and has conducted sessions on Azure DevOps, SQL Server Business Intelligence and Mobile Application Development. Gouri has written more than 75 articles on Azure DevOps, TFS, SQL Server Business Intelligence and SQL Azure which are published on and You can connect with her on LinkedIn.

Page copy protected against web site content infringement 	by Copyscape

Feedback - Leave us some adulation, criticism and everything in between!