Test Automation is hard to do well! There are many different things to consider. Not only do you have to think about how to write good code, but you also need to understand how to create good tests. And of all the types of test automation that you might want to write, UI test automation is the hardest kind. It can be tempting to simply write UI tests that mimic what you would do by hand, but any experienced test automation engineer will be able to tell you the pitfalls of doing that.
That might make you think that you shouldn’t write automated UI tests, but that’s not the case either. When you have a powerful tool, you don’t need to avoid it. Rather, you need to learn how to wield it well. TestProject has a powerful test recorder built right into it that makes it easy to create and record tests. This is great for certain kinds of testing, but what do you do when you want to wield this powerful tool with maximum effect? β‘ In order to do that, you will need to interact with it in more direct ways than you can via the test recorder. This is where the TestProject Software Development Kits (SDKs) come into the forefront.
TestProject has Java, C# and Python open sourced SDKs (and JavaScript is coming right around the corner!). In this article, we will look at how you can get started using the TestProject Java OpenSDK. We will get you from zero to a fully functioning test in just a few steps π
Getting Started with TestProject Java OpenSDK
- Pre-requisites
- Installing the OpenSDK with Maven
- Installing the OpenSDK with Gradle
- Creating Tests with the OpenSDK
- Development Token
- Running a Test with the OpenSDK
- Viewing Test Reports
Pre-Requisites
Before getting started with using the TestProject Java OpenSDK, there are a few things you need to have in place:
-
If you don’t have a TestProject account yet, you will need to signup for one. And don’t worry, TestProject accounts are free to setup! If you already have an account, make sure you are logged in to your account at https://app.testproject.io/.
-
Download and install an Agent for your operating system or pull a container from Docker Hub.
-
Run the Agent and register it with your Account. If you already have an Agent installed, make sure it is currently running on your machine.
-
Get a development token from Integrations / SDK page.
-
When using the Java SDK, you must also have the Java Development Kit (JDK) 11 or newer installed on your machine. If you do not have JDK installed, you can download and install the latest version from the Oracle website by following the JDK Download link on the oracle Java page.
-
You can work with your Integrated Development Environment (IDE) of choice, but if you are new to developing tests through an SDK, we would recommend that you use Eclipse. This is an open source IDE that has great support for Java. You can download it from the Eclipse website and then insall it setup of Java Development.
You will also need a way to add the TestProject OpenSDK into your project. You can do this in several ways, but the most common ways in Java are with Maven or Gradle. These are software tools that help you manage your Java projects and automate your builds. In this article I’ll show you how to use both of them, so that you can pick whichever one you prefer.
Let’s start with using Maven. If you want to install with Maven, you will of course need to have it installed on your computer. If you do not yet have it, you can download it from here and you can find install instructions for it here. Once you’ve done that, you can create a project in Eclipse with the following steps:
-
Go to File>New and select the Other option from the list.
-
Type Maven in the filter field and choose the Maven Project option.
-
Click Next.
-
Select the Create a simple project option and click Next again.
-
Put in a Group Id and Artifact Id and click Finish.
pom.xml
file for your project. If you expand the project in the navigation tree in Eclipse, you will see the pom.xml
file and you can double click to open it in for editing.<dependencies>
section to the file and then add the TestProject dependency:<dependencies> <dependency> <groupId>io.testproject</groupId> <artifactId>java-sdk</artifactId> <version>0.65.3-RELEASE</version> </dependency> </dependencies>
Make sure to set the <version>
to the name of the latest TestProject SDK version. You can find the list of versions in the Maven repository here.β
Once you have added that dependency to the pom.xml
files you will need to build your package so that the dependencies get installed. Eclipse will automatically rebuild for you as soon as you save your pom.xml
file. This will install the TestProject Java OpenSDK and all its dependencies for you. Once the build has completed you will see a Maven Dependencies folder in your project and you should be ready to start creating tests in your project! πͺ
-
Go to File>New and select the Other option from the list.
-
Type Gradle in the filter field and choose the Gradle Project option.
-
Click Next and if you get the Welcome page, click Next again.
-
Name your project and click Finish
build.gradle
file in your project and add the following into the dependencies section.implementation 'io.testproject:java-sdk:0.63.4-RELEASE'
Once you have the SDK installed, you can start creating tests with it. If you are familiar with using the Selenium driver, doing this will feel very familiar since TestProject inherits all of the commands from Selenium and Appium and does not override them with any proprietary commands. Generally speaking, the only thing you will need to do differently is to change to the import
statement to use the TestProject SDK rather than the Selenium based import.
The following examples are based on the ChromeDriver
. However they are applicable to any other supported drivers, just change the name as appropriate for the browser you are using.
Creating a New Test
src/tests/java
folder and then right clicking and selecting Package from the New menu as shown in the following image:Name this package something like TestProjectDemo and click Finish. This will create a new project for you, and you can then right click on this project and select Class from the new menu to create a new class. Name the class WebTest and click Finish. This creates a class file that you can fill out. Replace the contents of the file with the following code:
package TestProjectDemo; import io.testproject.sdk.drivers.web.ChromeDriver; import org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeOptions; public class WebTest { public static void main(final String[] args) throws Exception { ChromeDriver driver = new ChromeDriver(new ChromeOptions()); driver.navigate().to("https://example.testproject.io/web/"); driver.findElement(By.cssSelector("#name")).sendKeys("John Smith"); driver.findElement(By.cssSelector("#password")).sendKeys("12345"); driver.findElement(By.cssSelector("#login")).click(); boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed(); if (passed) { System.out.println("Test Passed"); } else { System.out.println("Test Failed"); } driver.quit(); } }
ChromeOptions()
when creating a new driver, you can also specify the token as a string. If you wanted to take this approach, Line 10 in the example above would be replaced with something like this:ChromeDriver driver = new ChromeDriver("your token", new ChromeOptions());
πΒ Kick-off powerful test automation without limitationsΒ π
GET YOUR FREE ACCOUNT TODAY