Links

Java

Java SDK (v1)
This repository contains code examples based on TestProject Java SDK.

Briefing

This document describes the bare minimum steps to start developing tests using the Java SDK. TestProject provides a unified test automation SDK with support for Android, iOS and Web applications by utilizing the open-source Selenium and Appium frameworks. TestProject is OS agnostic and can run on Windows, Linux or Mac. It is a full stack automation framework with capabilities that allow automation test management, remote and local test execution, job scheduling, reporting dashboards, collaboration and more.

Preparations

To kick-off automation development with TestProject, it is necessary to have an active TestProject account and the TestProject Agent installed. TestProject's Agent is a cross-platform desktop application, allowing you to create, debug and execute your test automation locally. TestProject Agent can be downloaded from Agents page.

Getting Java SDK

You can download TestProject SDK for Java from the Developers page and reference it in your project.

Installing SDK

To use TestProject SDK you have to add it as a reference to your project. Here are some examples for how it should be done using Maven or Gradle.
Maven:
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<systemPath>/path/to/sdk/io.testproject.sdk.java.jar</systemPath>
<scope>system</scope>
</dependency>
Gradle:
compile files("/path/to/sdk/io.testproject.sdk.java.jar")
Refer to pom.xml and build.gradle files in the provided examples for more details.

Test Development

The best way to start developing automated tests with TestProject is by reviewing the source code of a basic test that performs a login and updates a profile form, expecting the save to succeed.
There is also a Generic test, representing a dummy scenario that can be automated. It can be used as a reference for real scenarios that automate a non-UI sequences (those that do not require a Selenium or Appium driver).

Test Class

In order to build a Test that can be executed by TestProject, the class has to implement on of the interfaces that the SDK provides. Interface implementation requires an implementation of the execute() method, that will be be invoked by the platform to run the Test. The execute() method returns ExecutionResult enum which can be PASSED or FAILED.
Below are some examples for Test implementation on different platforms:
Web Test
BasicTest class implements the WebTest interface:
public class BasicTest implements WebTest
Test entry point is the execute method:
public ExecutionResult execute(WebTestHelper helper) throws FailureException
The following line of code retrieves a driver to automate the browser.
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
WebDriver driver = helper.getDriver();
Following code is used to navigate the browser to the relevant URL. After it is executed, TestProject Demo page is loaded.
// Navigate to TestProject Demo website
driver.navigate().to("https://example.testproject.io/web/");
The following code uses the Page Object Model pattern to login in and complete a profile form, saving it:
// Login using provided credentials
LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
loginPage.login(name, password);
// Complete profile forms and save it
ProfilePage profilePage = PageFactory.initElements(driver, ProfilePage.class);
profilePage.updateProfile(country, address, email, phone);
The following return statement will assert test result:
return profilePage.isSaved() ? ExecutionResult.PASSED : ExecutionResult.FAILED;
Android Test
BasicTest class implements the AndroidTest interface:
public class BasicTest implements AndroidTest
Test entry point is the execute method:
public ExecutionResult execute(AndroidTestHelper helper) throws FailureException
The following line of code retrieves a driver to automate the App.
// Get driver initialized by TestProject Agent
AndroidDriver driver = helper.getDriver();
The following code resets the App and uses the Page Object Model pattern to login in and complete a profile form, saving it:
driver.resetApp();
LoginPage loginPage = new LoginPage(driver);
loginPage.login(name, password);
ProfilePage profilePage = new ProfilePage(driver);
profilePage.updateProfile(country, address, email, phone);
The following return statement will assert test result:
return profilePage.isSaved() ? ExecutionResult.PASSED : ExecutionResult.FAILED;
iOS Test
BasicTest class implements the IOSTest interface:
public class BasicTest implements IOSTest
Test entry point is the execute method:
public ExecutionResult execute(IOSTestHelper helper) throws FailureException
The following line of code retrieves a driver to automate the App.
// Get driver initialized by TestProject Agent
IOSDriver driver = helper.getDriver();
The following code resets the App and uses the Page Object Model pattern to login in and complete a profile form, saving it:
driver.resetApp();
LoginPage loginPage = new LoginPage(driver);
loginPage.login(name, password);
ProfilePage profilePage = new ProfilePage(driver);
profilePage.updateProfile(country, address, email, phone);
The following return statement will assert test result:
return profilePage.isSaved() ? ExecutionResult.PASSED : ExecutionResult.FAILED;
Generic Test
BasicTest class implements the GenericTest interface:
public class BasicTest implements GenericTest
Test entry point is the execute method:
public ExecutionResult execute(TestHelper helper) throws FailureException
The following code adds the value stored in 'a' variable to the value in 'b' and if equals 2, asserts success:
int a = 1, b = 1;
if (a + b == 2) {
return ExecutionResult.PASSED;
} else {
return ExecutionResult.FAILED;
}

Debugging / Running Test

To debug or run the test locally, you will have to use the Runner class from TestProject SDK. All code examples, have JUnit tests that use Runner to debug the automation locally. Debugging or running a test locally with the Runner class, requires authentication before communication with the TestProject Agent (since it is the execution engine). Development token for authentication can be easily obtained from the Developers page. It should be used as a parameter in one of the Runner factory methods:
Web
Runner runner = Runner.createWeb("YOUR_DEV_TOKEN", ...
Android
Runner runner = Runner.createAndroid("YOUR_DEV_TOKEN", ...
Chrome on Android
Runner runner = Runner.createAndroidWeb("YOUR_DEV_TOKEN", ...
iOS
Runner runner = Runner.createIOS("YOUR_DEV_TOKEN", ...
Safari on iOS
Runner runner = Runner.createIOSWeb("YOUR_DEV_TOKEN", ...
Generic
Runner runner = Runner.create("YOUR_DEV_TOKEN"...

Using parameters and step reports in your tests

Let's make our example more advanced by adding parameters. To add parameters to your test, you simply need to add fields with relevant annotations. In addition, we will create step reports to separate the different stages of the test (each report will appear as a separate step in the future execution reports).
See the relevant platform link for full source code:

Test Annotations

TestProject SDK provides annotations to describe the test and its parameters:
  1. 1.
    The Test annotation is used to better describe the Test and define how it will appear later in TestProject UI:
    • name - The name of the test (if omitted, the name of the class will be used).
    • description - A description of the test which is shown in various places in TestProject platform (e.g. reporting dashboard). The description may contain placeholders {{propertyName}} that will be changed dynamically according to test parameters.
    • version - A version string which is used for future reference.
  2. 2.
    The Parameter annotation is used to better describe your Test inputs and outputs, in the example above there are two inputs - url and expectedTitle.
    • description - The description of the parameter
    • direction - Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will receive values when the test is executed while the output parameter value will be retrieved at the end of test execution (and can be used in following steps later on in the automation scenario).
    • defaultValue - Defines a default value that will be used for the parameter.

Reports

Implemented execute() method receives a Helper instance as a parameter. Via this helper, you can obtain an instance of TestReporter class.
TestReporter report = helper.getReporter();
Notice the following line in the Extended Test example. This line reports a step based on provided condition and takes a screenshot:
report.step("Profile information saved", profilePage.isSaved(), TakeScreenshotConditionType.Always);
Using the following code one can set test result message:
report.result("Test completed successfully");

Addon development

Much like tests, you can develop custom Addons to extend TestProject and shape your automated testing solution for your needs. An Addon is a set of Actions (one or more) where each Action does a specific task. A common Addon scenario will be to extend basic set of Actions on complicated UI elements or make wrappers for user defined API. Once created, Actions can be used to design steps of automated tests.
You can learn more about how to create your own addons, here in the documentation.

Crowd Code / Addon Proxy

One of the greatest features of the TestProject environment is the ability to execute a code written by someone else. It can be your account colleagues writing actions that you can reuse, or TestProject community users. Developer must download a binary file with the proxy class for the Action he wants to execute.
Assuming your account member uploaded the example Addon, named it Example and you want to reuse it's code your Test. To do so, you can download it's proxy JAR and use it like this:
ClearFields clearFieldsAction = ExampleAddon.clearFields();
Implemented execute() method receives a Helper instance as a parameter. Via this helper, you can execute the proxy by invoking the executeProxy method:
StepExecutionResult result = helper.executeProxy(clearFieldsAction);
See examples:

Packaging

To package and upload coded tests written using the TestProject V1 SDK in Java, you will need to package it as a .jar file.
Export your code as an uber .jar file with dependencies, excluding the TestProject SDK.
Once the jar is compiled and uploaded, TestProject will display your project as a package with all the tests inside of it.
Please note that once uploaded, the tests cannot be edited unless reuploaded after performing the changes in your local development environment.
The following examples have been created using IntelliJ.
Gradle
Open the Gradle tab in your IDE, you will need to compile a jar using Tasks/build/jar.
After running the task, the jar will be created in the build/libs directory.
Maven
Open the Maven tab, select Lifecycle, and execute the following in order:
  • clean
  • compile
  • package
Once the package command ends; the jar will be created in the target directory.
To upload the package, head to your project on the TestProject platform, and create a new test.
Select the code option.
Upload your jar.
Press next.
Give your package a name, description and choose an application and press next to complete the process.
See build.gradle or pom.xml files in code examples for details on how to include the TestProject V1 SDK dependency in your project.

Support

For any further inquiries, please use TestProject support channels: