Powerful SDK

Supports all your test automation needs

TestProject provides a powerful SDK for creating tests and addons using standard open source libraries (Selenium & Appium) for Web, Android and iOS applications.

TestProject’s SDK supports standard Selenium and Appium API commands, so you don’t have to change your test logic or learn new APIs if you want to develop tests for web or mobile applications. This makes the development of new tests or porting existing ones as easy and straightforward as possible.

Currently, TestProject’s SDK has a Java and C# (.NET Core) implementation. Soon, we will provide support for additional programming languages, such as: Python, JavaScript, etc.

TestProject Java Code TestProject csharp code
  • Previous
  • Next

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 of how it should be done using Maven or Gradle.

Maven:

Code - java

<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>

Refer to pom.xml in the provided examples for more details.

 

Gradle:

Code - java

compile files("/path/to/sdk/io.testproject.sdk.java.jar")

Refer to build.gradle files in the provided examples for more details.

 

There we go, now we’re all set! Let’s see what comes next.

Table of contents
  • Getting Java SDK
  • Installing SDK

Getting C# SDK

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

Minimum Requirements

  • In order to develop TestProject C# tests/addons, you must have .Net Core SDK version v2.1 or greater (Can be downloaded here)
  • In order to execute C# tests/addons, you must have .Net Runtime v2.1 or greater (Can be downloaded here)
  • If you are developing with visual studio, you must use Visual Studio 2017 (Can be downloaded here)

Installing SDK

To begin, let’s create a .Net Core project and add TestProject SDK as a reference:

  • Open Visual studio and create a new project
  • From the left side select Visual C# => .Net Core. Then, select Class Library.
  • Once the project has been created, right-click the project and select Manage Nuget Packages….
  • Search for TestProject SDK and install it into your project.

There we go, now we’re all set! Let’s see what comes next.

Table of contents
  • Getting C# SDK
  • Minimum Requirements
  • Installing SDK

Android 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 expects a logout button to appear.

This test is executed on TestProject Demo App for Android.

Test Class

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the AndroidTest interface:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.sdk.v2.drivers.AndroidDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.tests.AndroidTest;
import io.testproject.java.sdk.v2.tests.helpers.AndroidTestHelper;
import org.openqa.selenium.By;

public class BasicTest implements AndroidTest {

public ExecutionResult execute(AndroidTestHelper helper) {
// Get driver initialized by TestProject Agent
AndroidDriver driver = helper.getDriver();

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
driver.findElement(By.id("login")).click();

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() == 1) {
return ExecutionResult.PASSED;
}

return ExecutionResult.FAILED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the IAndroidTest interface:

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;

namespace TestProject.SDK.Examples.Android.Test
{
public class BasicTest : IAndroidTest
{
public ExecutionResult Execute(AndroidTestHelper helper)
{
// Get driver initialized by TestProject Agent
var driver = helper.Driver;

// Login using provided credentials
driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;

return ExecutionResult.Failed;
}
}
}

Complete solution and full source code is available on GitHub

Android 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 a complicated UI element. Actions are used to design steps of automated tests.

Below is an example of an Action that can be executed on the TestProject Demo App’s Login screen.

Action Class

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the AndroidAction interface and clears a form:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;

import io.appium.java_client.android.AndroidElement;
import io.testproject.java.annotations.v2.Action;
import io.testproject.java.sdk.v2.addons.AndroidAction;
import io.testproject.java.sdk.v2.addons.helpers.AndroidAddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import org.openqa.selenium.By;

public class ClearFieldsAction implements AndroidAction {

public ExecutionResult execute(AndroidAddonHelper helper) throws FailureException {
for (AndroidElement element :
helper.getDriver().findElements(
By.className("android.widget.EditText"))) {
element.clear();
}

return ExecutionResult.PASSED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the IAndroidAction interface and clears a form:

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Android;
using TestProject.SDK.Addons.Actions;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.Android.Addon
{
public class ClearFieldsAction : IAndroidAction
{
public ExecutionResult Execute(AndroidAddonHelper helper)
{
foreach (AndroidElement element in
helper.Driver.FindElements(By
.ClassName("android.widget.EditText")))
element.Clear();

return ExecutionResult.Passed;
}
}
}

Complete solution and full source code is available on GitHub

Table of contents
  • Android Test Development
  • Test Class
  • Android Addon Development
  • Action Class

iOS 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 expects a logout button to appear.

This test is executed on TestProject Demo App for iOS.

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 expects a logout button to appear.

This test is executed on TestProject Demo App for iOS.

Test Class

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the IOSTest interface:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.sdk.v2.drivers.IOSDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.tests.IOSTest;
import io.testproject.java.sdk.v2.tests.helpers.IOSTestHelper;
import org.openqa.selenium.By;

public class BasicTest implements IOSTest {

public ExecutionResult execute(IOSTestHelper helper) {
IOSDriver driver = helper.getDriver();

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
driver.findElement(By.id("login")).click();

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() == 1) {
return ExecutionResult.PASSED;
}

return ExecutionResult.FAILED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the IIOSTest interface:

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;

namespace TestProject.SDK.Examples.IOS.Test
{
public class BasicTest : IIOSTest
{
public ExecutionResult Execute(IOSTestHelper helper)
{
// Get driver initialized by TestProject Agent
var driver = helper.Driver;

// Login using provided credentials
driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;

return ExecutionResult.Failed;
}
}
}

Complete solution and full source code is available on GitHub

iOS 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 a complicated UI element. Actions are used to design steps of automated tests.

Below is an example of an Action that can be executed on the TestProject Demo App’s Login screen.

Action Class

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the IOSAction interface and clears a form:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;

import io.appium.java_client.ios.IOSElement;
import io.testproject.java.sdk.v2.addons.IOSAction;
import io.testproject.java.sdk.v2.addons.helpers.IOSAddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import org.openqa.selenium.By;

public class ClearFieldsAction implements IOSAction {

public ExecutionResult execute(IOSAddonHelper helper) throws FailureException {
for (IOSElement element : helper.getDriver()
.findElements(By.className("XCUIElementTypeTextField"))) {
element.clear();
}

for (IOSElement element : helper.getDriver()
.findElements(By.className("XCUIElementTypeSecureTextField"))) {
element.clear();
}

return ExecutionResult.PASSED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the IIOSAction interface and clears a form:

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.iOS;
using TestProject.SDK.Addons.Actions;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.IOS.Addon
{
public class ClearFieldsAction : IIOSAction
{
public ExecutionResult Execute(IOSAddonHelper helper)
{
foreach (IOSElement element in helper.Driver
.FindElements(By.ClassName("XCUIElementTypeTextField")))
element.Clear();

foreach (IOSElement element in helper.Driver
.FindElements(By.ClassName("XCUIElementTypeSecureTextField")))
element.Clear();

return ExecutionResult.Passed;
}
}
}

Complete solution and full source code is available on GitHub

Table of contents
  • iOS Test Development
  • Test Class
  • iOS Addon Development
  • Action Class

Web 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 expects a logout button to appear.

This test is executed on TestProject Demo website.

Test Class

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the WebTest interface:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;
import org.openqa.selenium.By;

public class BasicTest implements WebTest {

public ExecutionResult execute(WebTestHelper helper) {

// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
WebDriver driver = helper.getDriver();

// Navigate to TestProject Demo website
driver.navigate().to("https://example.testproject.io/web/");

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
driver.findElement(By.id("login")).click();

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() == 1) {
return ExecutionResult.PASSED;
}

return ExecutionResult.FAILED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the IWebTest interface:

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;

namespace TestProject.SDK.Examples.Web.Test
{
public class BasicTest : IWebTest
{
public ExecutionResult Execute(WebTestHelper helper)
{
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
var driver = helper.Driver;

// Navigate to TestProject Demo website
driver.Navigate().GoToUrl("https://example.testproject.io/web/");

// Login using provided credentials
driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;

return ExecutionResult.Failed;
}
}
}

Complete solution and full source code is available on GitHub

Web 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 a complicated UI element. Actions are used to design steps of automated tests.

Action Class

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the WebAction interface and clears a form:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;

import io.testproject.java.sdk.v2.addons.WebAction;
import io.testproject.java.sdk.v2.addons.helpers.WebAddonHelper;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class ClearFieldsAction implements WebAction {

public ExecutionResult execute(WebAddonHelper helper) throws FailureException {

// Get Driver
WebDriver driver = helper.getDriver();

// Search for Form elements
for (WebElement form : driver
.findElements(By.tagName("form"))) {

// Ignore invisible forms
if (!form.isDisplayed()) {
continue;
}

// Clear all inputs
for (WebElement element : form
.findElements(By.tagName("input"))) {
element.clear();
}
}

return ExecutionResult.PASSED;
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build n Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Action.

Below is a simple action ClearFields that implements the IWebAction interface and clears a form:

Code - c#
  • java
  • c#

using System;
using OpenQA.Selenium;
using TestProject.SDK.Addons.Actions;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.Web.Addon
{
public class ClearFieldsAction : IWebAction
{
public ExecutionResult Execute(WebAddonHelper helper)
{
// Get Driver
var driver = helper.Driver;

// Search for Form elements
foreach (IWebElement form in driver
.FindElements(By.TagName("form")))
{
// Ignore invisible forms
if (!form.Displayed)
continue;

// Clear all inputs
foreach (IWebElement element in form
.FindElements(By.TagName("input")))
element.Clear();
}

return ExecutionResult.Passed;
}
}
}

Complete solution and full source code is available on GitHub

Table of contents
  • Web Test Development
  • Test Class
  • Web Addon Development
  • Action Class

Generic Test Development

Generic tests are automation tasks that do not interact with user interface elements.

The best way to start developing automated generic tests with TestProject is by reviewing the source code of a dummy generic test that performs an addition of two numbers and verifies the result.

Test Class

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the GenericTest interface:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.GenericTest;
import io.testproject.java.sdk.v2.tests.helpers.TestHelper;

public class BasicTest implements GenericTest {

public ExecutionResult execute(TestHelper helper) throws FailureException {

int a = 1, b = 1;

if (a + b == 2) {
return ExecutionResult.PASSED;
} else {
return ExecutionResult.FAILED;
}
}
}

Gradle/Maven project and full source code is available on GitHub

In order to build a Test that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Test.

Below is a basic test example that implements the IGenericTest interface:

Code - c#
  • java
  • c#

using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
namespace TestProject.SDK.Examples.Generic.Test
{
public class BasicTest : IGenericTest
{
public ExecutionResult Execute(GenericTestHelper helper)
{
int a = 1, b = 1;
if (a + b == 2)
return ExecutionResult.Passed;
else
return ExecutionResult.Failed;
}
}
}

Complete solution and full source code is available on GitHub

Generic 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 for generic actions would be actions that wrap external SDKs / APIs, perform network or I/O operations, etc. Actions are used to design steps of automated tests.

Action Class

In order to build an Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Action.

Below a simple action GreaterThanFiveAction that implements the GenericAction interface.
This action generates random number between 1 and 10, failing if it’s less than 5:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;

import io.testproject.java.annotations.v2.Action;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.addons.GenericAction;
import io.testproject.java.sdk.v2.addons.helpers.AddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;

import java.util.Random;

public class GreaterThanFiveAction implements GenericAction {

public ExecutionResult execute(AddonHelper helper) throws FailureException {

Random random = new Random();
if (random.nextInt(10) > 5) {
return ExecutionResult.PASSED;
}

return ExecutionResult.FAILED;
}
}

In order to build an Action that can be executed by TestProject, the class has to implement one of the interfaces that the SDK provides and an Execute() method, that will be be invoked by the platform to run the Action.

Below a simple action GreaterThanFiveAction that implements the IGenericAction interface.
This action generates random number between 1 and 10, failing if it’s less than 5:

Code - c#
  • java
  • c#

using System;
using TestProject.SDK.Addons.Actions;
using TestProject.SDK.Addons.Helpers;

namespace TestProject.SDK.Examples.Generic.Test
{
public class GreaterThanFive : IGenericAction
{
public ExecutionResult Execute(GenericAddonHelper helper)
{
var random = new Random();
int value = random.Next(1, 10);
if (value > 5)
{
return ExecutionResult.Passed
}

return ExecutionResult.Failed;
}
}
}

Table of contents
  • Generic Test Development
  • Test Class
  • Generic Addon Development
  • Action Class

Using Tests

Debugging / Running Tests

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 the Runner factory method:

Code - java
  • java
  • c#

Runner runner = Runner.createAndroid(
"YOUR_DEV_TOKEN",
"YOUR_DEVICE_UDID",
"YOUR_APP_PACKAGE",
"YOUR_ACTIVITY")

 

Here is a full JUnit test source:

Code - java
  • java
  • c#

import io.testproject.examples.sdk.tests.BasicTest;
import io.testproject.java.sdk.v2.Runner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
 
 
public class Tests {
 
private static final String DEV_TOKEN = "YOUR_DEV_TOKEN";
private static final String DEVICE_UDID = "ANDROID_DEVICE_UDID";
private static final String PACKAGE_NAME = "io.testproject.demo";
private static final String ACTIVITY_NAME = ".MainActivity";
 
private static Runner runner;
 
@BeforeAll
public static void setup() throws InstantiationException {
runner = Runner.createAndroid(DEV_TOKEN, DEVICE_UDID, PACKAGE_NAME, ACTIVITY_NAME);
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runTest() throws Exception {
 
// Create test
BasicTest test = new BasicTest();
 
// Run test
runner.run(test);
 
}
 
}

To debug or run the test locally, you will have to use the Runner class from TestProject SDK.

All code examples, have NUnit 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 Runnerfactory methods:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.CreateAndroid(
"YOUR_DEV_TOKEN",
"YOUR_EMULATOR_ID",
"YOUR_APP_PACKAGE",
"YOUR_ACTIVITY")

 

Here is a full NUnit test source:

Code - c#
  • java
  • c#

using NUnit.Framework;
using System.Reflection;
using TestProject.SDK.Examples.Android.Test;
 
namespace TestProject.SDK.Examples.Android.Runners.Nunit
{
[TestFixture]
public class AndroidTests
{
public static string DevToken = "YOUR_DEV_TOKEN";
public static string DeviceUDID = "DEVICE_UDID";
public static string PackageName = "io.testproject.demo";
public static string ActivityName = ".MainActivity";
 
Runner runner;
 
[SetUp]
public void SetUp()
{
runner = RunnerFactory.Instance.CreateAndroid(DevToken, DeviceUDID, PackageName, ActivityName);
}
 
[TearDown]
public void TearDown()
{
runner.Dispose();
}
 
[Test]
public void RunBasicTest()
{
runner.Run(new BasicTest());
}
}
}

Packaging Tests

In order to upload your Tests to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}

// JAR Task
jar {
assert file(“${TP_SDK}”).exists(): “TestProject SDK JAR file was not found, please update the TP_SDK variable”
archiveName “${rootProject.name}-${version}.jar”
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime – configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}

// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include ‘testproject-sdk.properties’
}
}
}
}

dependencies {
tpsdk files(“${TP_SDK}”)
compile files(‘src/main/proxy/android-example-addon.proxy.jar’)

testCompile ‘org.junit.jupiter:junit-jupiter-api:5.3.1’
testRuntime ‘org.junit.platform:junit-platform-runner:1.3.1’
testRuntime ‘org.junit.jupiter:junit-jupiter-engine:5.3.1’
testRuntime ‘org.junit.vintage:junit-vintage-engine:5.3.1’
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>android-test-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<tp.addon.proxy.path>${basedir}/src/main/proxy/android-example-addon.proxy.jar</tp.addon.proxy.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>example-addon-proxy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<systemPath>${tp.addon.proxy.path}</systemPath>
<scope>system</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/android-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Tests to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Tests

Find the JAR file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your JAR file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Find the DLL file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your DLL file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Using Addons

Debugging / Running Addons (Actions)

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full JUnit test source with UI state preparations below:

Code - java
  • java
  • c#

import io.testproject.examples.sdk.actions.ClearFieldsAction;
import io.testproject.java.sdk.v2.Runner;
import io.testproject.java.sdk.v2.drivers.AndroidDriver;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
 
import java.io.IOException;
 
public class Actions {
 
private static final String DEV_TOKEN = "YOUR_DEV_TOKEN";
private static final String DEVICE_UDID = "ANDROID_DEVICE_UDID";
private static final String PACKAGE_NAME = "io.testproject.demo";
private static final String ACTIVITY_NAME = ".MainActivity";
 
private static Runner runner;
private static AndroidDriver driver;
 
@BeforeAll
public static void setup() throws InstantiationException {
runner = Runner.createAndroid(DEV_TOKEN, DEVICE_UDID, PACKAGE_NAME, ACTIVITY_NAME);
driver = runner.getDriver();
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Before
public void prepareApp() {
driver.resetApp();
}
 
@Test
public void runAction() throws Exception {
 
// Create Action
ClearFieldsAction action = new ClearFieldsAction();
 
// Prepare state
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
 
// Run action
runner.run(action);
}
}

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full NUnit test source with UI state preparations below:

Code - c#
  • java
  • c#

using NUnit.Framework;
using OpenQA.Selenium;
using AndroidElement = OpenQA.Selenium.Appium.Android.AndroidElement;
using TestProject.SDK.Examples.Android.Addon;
using TestProject.SDK.Drivers;
 
namespace TestProject.SDK.Examples.Android.Runners.Nunit
{
[TestFixture]
public class AndroidActions
{
public static string DevToken = "YOUR_DEV_TOKEN";
public static string DeviceUDID = "DEVICE_UDID";
public static string PackageName = "io.testproject.demo";
public static string ActivityName = ".MainActivity";
 
private static Runner runner;
private static AndroidDriver driver;
 
[OneTimeSetUp]
public static void Setup()
{
runner = RunnerFactory.Instance.CreateAndroid(DevToken, DeviceUDID, PackageName, ActivityName);
driver = (AndroidDriver)runner.GetDriver();
}
 
[OneTimeTearDown]
public static void TearDown()
{
runner.Dispose();
}
 
[SetUp]
public void PrepareApp()
{
driver.ResetApp();
}
 
[Test]
public void RunAction()
{
// Create Action
var action = new ClearFieldsAction();
 
// Prepare state
driver.FindElement(By.Id("name")).SendKeys("John Smith");
driver.FindElement(By.Id("password")).SendKeys("12345");
 
// Run action
runner.Run(action);
}
}
}

Addon Manifest

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

Packaging Addons

In order to upload your Addon to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/android-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>android-addon-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/android-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Addons to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Addons

Find the JAR file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Find the DLL/ZIP file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

 

Table of contents
  • Using Tests
  • Debugging / Running Tests
  • Packaging Tests
  • Uploading Tests
  • Using Addons
  • Debugging / Running Addons (Actions)
  • Addon Manifest
  • Packaging Addons
  • Uploading Addons

Using Tests

Debugging / Running Tests

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 the Runner factory method:

Code - java
  • java
  • c#

Runner runner = Runner.createIOS(
"YOUR_DEV_TOKEN",
"YOUR_IOS_DEVICE_ID",
"YOUR_IOS_DEVICE_NAME",
"YOUR_IOS_APP")

 

Here is a full JUnit test source:

Code - java
  • java
  • c#

Runner runner = Runner.createIOS("YOUR_DEV_TOKEN");
 
Here is a full JUnit test source:
 
import io.testproject.examples.sdk.tests.BasicTest;
import io.testproject.java.sdk.v2.Runner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
 
 
public class Tests {
 
private static final String DEV_TOKEN = "YOUR_DEV_TOKEN";
private static final String DEVICE_UDID = "IOS_DEVICE_UDID";
private static final String DEVICE_NAME = "IOS_DEVICE_NAME";
private static final String BUNDLE_ID = "io.testproject.Demo";
 
private static Runner runner;
 
@BeforeAll
private static void setup() throws InstantiationException {
runner = Runner.createIOS(DEV_TOKEN, DEVICE_UDID, DEVICE_NAME, BUNDLE_ID);
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runTest() throws Exception {
 
// Create test
BasicTest test = new BasicTest();
 
// Run test
runner.run(test);
 
}
}

To debug or run the test locally, you will have to use the Runner class from TestProject SDK.

All code examples, have NUnit 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 Runnerfactory methods:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.CreateIOS(
"YOUR_DEV_TOKEN",
"YOUR_IOS_DEVICE_ID",
"YOUR_IOS_DEVICE_NAME",
"YOUR_IOS_APP")

 

Here is a full NUnit test source:

Code - c#
  • java
  • c#

using NUnit.Framework;
using System.Reflection;
using TestProject.SDK.Examples.IOS.Test;
 
namespace TestProject.SDK.Examples.IOS.Runners.Nunit
{
[TestFixture]
public class IOSTests
{
public static string DevToken = "YOUR_DEV_TOKEN";
public static string DeviceUDID = "DEVICE_UDID";
public static string DeviceName = "DEVICE_NAME";
public static string BundleId = "io.testproject.Demo";
 
Runner runner;
 
[SetUp]
public void SetUp()
{
runner = RunnerFactory.Instance.CreateIOS(DevToken, DeviceUDID, DeviceName, BundleId);
}
 
[TearDown]
public void TearDown()
{
runner.Dispose();
}
 
[Test]
public void RunBasicTest()
{
runner.Run(new BasicTest());
}
}
}

Packaging Tests

In order to upload your Tests to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/ios-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>ios-test-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<tp.addon.proxy.path>${basedir}/src/main/proxy/ios-example-addon.proxy.jar</tp.addon.proxy.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>example-addon-proxy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<systemPath>${tp.addon.proxy.path}</systemPath>
<scope>system</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/ios-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Tests to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Tests

Find the JAR file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your JAR file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Find the DLL file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your DLL file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Using Addons

Debugging / Running Addons (Actions)

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full JUnit test source with UI state preparations below:

Code - java
  • java
  • c#

import io.testproject.examples.sdk.actions.ClearFieldsAction;
import io.testproject.java.sdk.v2.Runner;
import io.testproject.java.sdk.v2.drivers.IOSDriver;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
 
import java.io.IOException;
 
public class Actions {
 
private static final String DEV_TOKEN = "YOUR_DEV_TOKEN";
private static final String DEVICE_UDID = "IOS_DEVICE_UDID";
private static final String DEVICE_NAME = "IOS_DEVICE_NAME";
private static final String BUNDLE_ID = "io.testproject.Demo";
 
private static Runner runner;
private static IOSDriver driver;
 
@BeforeAll
public static void setup() throws InstantiationException {
runner = Runner.createIOS(DEV_TOKEN, DEVICE_UDID, DEVICE_NAME, BUNDLE_ID);
driver = runner.getDriver();
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Before
public void prepareApp() {
driver.resetApp();
}
 
@Test
public void runAction() throws Exception {
 
// Create Action
ClearFieldsAction action = new ClearFieldsAction();
 
// Prepare state
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
 
// Run action
runner.run(action);
}
}

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full NUnit test source with UI state preparations below:

Code - c#
  • java
  • c#

using NUnit.Framework;
using OpenQA.Selenium;
using TestProject.SDK.Drivers;
using TestProject.SDK.Examples.IOS.Addon;
using IOSElement = OpenQA.Selenium.Appium.iOS.IOSElement;
 
namespace TestProject.SDK.Examples.IOS.Runners.Nunit
{
[TestFixture]
public class IOSTests
{
public static string DevToken = "YOUR_DEV_TOKEN";
public static string DeviceUDID = "DEVICE_UDID";
public static string DeviceName = "DEVICE_NAME";
public static string BundleId = "io.testproject.Demo";
 
private static Runner runner;
private static IOSDriver driver;
 
[OneTimeSetUp]
public static void Setup()
{
runner = RunnerFactory.Instance.CreateIOS(DevToken, DeviceUDID, DeviceName, BundleId);
driver = (IOSDriver)runner.GetDriver();
}
 
[OneTimeTearDown]
public static void TearDown()
{
runner.Dispose();
}
 
[SetUp]
public void PrepareApp()
{
driver.ResetApp();
}
 
[Test]
public void RunAction()
{
// Create Action
var action = new ClearFieldsAction();
 
// Prepare state
driver.FindElement(By.Id("name")).SendKeys("John Smith");
driver.FindElement(By.Id("password")).SendKeys("12345");
 
// Run action
runner.Run(action);
}
}
}

Addon Manifest

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

Packaging Addons

In order to upload your Addon to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/ios-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>ios-addon-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/ios-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Addons to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Addons

Find the JAR file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Find the DLL/ZIP file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Table of contents
  • Using Tests
  • Debugging / Running Tests
  • Packaging Tests
  • Uploading Tests
  • Using Addons
  • Debugging / Running Addons (Actions)
  • Addon Manifest
  • Packaging Addons
  • Uploading Addons

Using Tests

Debugging/Running Tests

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 the Runner factory method:

Code - java
  • java
  • c#

Runner runner = Runner.createWeb(
"YOUR_DEV_TOKEN",
AutomatedBrowserType.Chrome);

 

Here is a full JUnit test source:

Code - java
  • java
  • c#

package io.testproject.tests.desktop;
 
import io.testproject.examples.sdk.tests.BasicTest;
import io.testproject.java.enums.AutomatedBrowserType;
import io.testproject.java.sdk.v2.Runner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
 
import static io.testproject.tests.Configuration.DEV_TOKEN;
 
 
public class ChromeTests {
 
private static Runner runner;
 
@BeforeAll
private static void setup() throws InstantiationException {
runner = Runner.createWeb(DEV_TOKEN, AutomatedBrowserType.Chrome);
}
 
@AfterAll
private static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runTest() throws Exception {
BasicTest test = new BasicTest();
 
test.name = "John Smith";
test.password = "12345";
test.country = "United States";
test.address = "5000 Highway 7 East";
test.email = "[email protected]";
test.phone = "+1 (905) 515-2000";
 
runner.run(test);
 
}
 
}

 

Chrome on Android:

Code - java
  • java
  • c#

Runner runner = Runner.createAndroidWeb(
"YOUR_DEV_TOKEN",
"YOUR_DEVICE_UDID");

Here is the source for the JUnit test.

 

Safari on iOS:

Code - java
  • java
  • c#

Runner runner = Runner.createIOSWeb(
"YOUR_DEV_TOKEN",
"YOUR_DEVICE_UDID",
"YOUR_DEVICE_NAME");

Here is the source for the JUnit test.

To debug or run the test locally, you will have to use the Runner class from TestProject SDK.

All code examples, have NUnit 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 Runnerfactory methods:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.CreateWeb(
"YOUR_DEV_TOKEN",
AutomatedBrowserType.Chrome);

 

Here is a full JUnit test source:

Code - c#
  • java
  • c#

using NUnit.Framework;
using TestProject.SDK.Common.Enums;
using TestProject.SDK.Examples.Web.Runners.Nunit.Base;
 
namespace TestProject.SDK.Examples.Runners.Nunit
{
[TestFixture(AutomatedBrowserType.Chrome)]
public class ChromeTest
{
Runner runner;
 
public DesktopTests(AutomatedBrowserType automatedBrowserType)
{
runner = RunnerFactory.Instance.CreateWeb("YOUR_DEV_TOKEN", automatedBrowserType);
}
 
[Test]
public void RunTest()
{
var test = new BasicTest
{
name = "John Smith",
password = "12345",
country = "United States",
address = "5000 Highway 7 East",
email = "[email protected]",
phone = "+1 (905) 515-2000"
};
 
runner.Run(test);
}
 
[OneTimeTearDown]
public void TearDown()
{
runner.Dispose();
}
}
}

 

Chrome on Android:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.CreateAndroidWeb(
"YOUR_DEV_TOKEN",
"YOUR_EMULATOR_ID");

Here is the source for the NUnit test.

 

Safari on iOS:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.CreateIOSWeb(
"YOUR_DEV_TOKEN",
"YOUR_IOS_DEVICE_ID",
"YOUR_IOS_DEVICE_NAME")

Here is the source for the NUnit test.

Packaging Tests

In order to upload your Tests to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/web-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>web-test-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<tp.addon.proxy.path>${basedir}/src/main/proxy/web-example-addon.proxy.jar</tp.addon.proxy.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>example-addon-proxy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<systemPath>${tp.addon.proxy.path}</systemPath>
<scope>system</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/web-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Tests to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Tests

Find the JAR file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your JAR file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Find the DLL file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your DLL file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Using Addons

Debugging/Running Addons (Actions)

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full JUnit test source with UI state preparations below:

Code - java
  • java
  • c#

package io.testproject.tests.desktop;
 
import io.testproject.examples.sdk.actions.ClearFieldsAction;
import io.testproject.java.enums.AutomatedBrowserType;
import io.testproject.java.sdk.v2.Runner;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
 
import java.io.IOException;
 
import static io.testproject.tests.Configuration.DEV_TOKEN;
 
 
public class ChromeActions {
 
private static Runner runner;
 
@BeforeAll
public static void setup() throws InstantiationException {
runner = Runner.createWeb(DEV_TOKEN, AutomatedBrowserType.Chrome);
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runAction() throws Exception {
// Create Action
ClearFieldsAction action = new ClearFieldsAction();
 
// Prepare state
WebDriver driver = runner.getDriver();
driver.navigate().to("https://example.testproject.io/web/");
driver.findElement(By.id("name")).sendKeys("John Smith");
driver.findElement(By.id("password")).sendKeys("12345");
 
// Run action
runner.run(action);
}
 
}

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full NUnit test source with UI state preparations below:

Code - c#
  • java
  • c#

using NUnit.Framework;
using TestProject.SDK.Common.Enums;
using TestProject.SDK.Examples.Web.Runners.Nunit.Base;
 
namespace TestProject.SDK.Examples.Web.Runners.Nunit
{
[TestFixture(AutomatedBrowserType.Edge)]
[TestFixture(AutomatedBrowserType.Chrome)]
[TestFixture(AutomatedBrowserType.InternetExplorer)]
[TestFixture(AutomatedBrowserType.Firefox)]
[TestFixture(AutomatedBrowserType.Safari)]
public class WebTests
{
Runner runner;
 
public WebTests(AutomatedBrowserType automatedBrowserType)
{
runner = RunnerFactory.Instance.CreateWeb("YOUR_DEV_TOKEN", automatedBrowserType);
}
 
[Test]
public void RunAction()
{
// Create Action
var action = new ClearFieldsAction();
 
// Prepare state
var driver = (WebDriver)runner.GetDriver();
driver.Navigate().GoToUrl("https://example.testproject.io/web/");
driver.FindElement(By.Id("name")).SendKeys(name);
driver.FindElement(By.Id("password")).SendKeys(password);
 
// Run action
runner.Run(action);
 
Thread.Sleep(1000);
}
 
[OneTimeTearDown]
public void TearDown()
{
runner.Dispose();
}
}
}

Addon Manifest

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

Packaging Addons

In order to upload your Addon to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>web-addon-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/web-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Addons to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Addons

Find the JAR file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Find the DLL/ZIP file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Table of contents
  • Using Tests
  • Debugging/Running Tests
  • Packaging Tests
  • Uploading Tests
  • Using Addons
  • Debugging/Running Addons (Actions)
  • Addon Manifest
  • Packaging Addons
  • Uploading Addons

Using Tests

Debugging / Running Tests

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 the Runner factory method:

Code - java
  • java
  • c#

Runner runner = Runner.create("YOUR_DEV_TOKEN");

 

Here is a full JUnit test source:

Code - java
  • java
  • c#

package io.testproject;
 
import io.testproject.examples.sdk.tests.BasicTest;
import io.testproject.java.sdk.v2.Runner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
 
 
public class Tests {
 
private static Runner runner;
 
@BeforeAll
private static void setup() throws InstantiationException {
runner = Runner.create("YOUR_DEV_TOKEN");
}
 
@AfterAll
private static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runTest() throws Exception {
 
// Create test
BasicTest test = new BasicTest();
 
// Run test
runner.run(test);
 
}
 
}

To debug or run the test locally, you will have to use the Runner class from TestProject SDK.

All code examples, have NUnit 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 Runnerfactory methods:

Code - c#
  • java
  • c#

var runner = RunnerFactory.Instance.Create("YOUR_DEV_TOKEN")

 

Here is a full NUnit test source:

Code - c#
  • java
  • c#

using NUnit.Framework;
using System.Reflection;
using TestProject.SDK.Examples.Generic.Test;
 
namespace TestProject.SDK.Examples.Generic.Runners.Nunit
{
[TestFixture]
public class GenericTests
{
private static string DevToken = "YOUR_DEV_TOKEN";
 
Runner runner;
 
[SetUp]
public void SetUp()
{
runner = RunnerFactory.Instance.Create(DevToken);
}
 
[TearDown]
public void TearDown()
{
runner.Dispose();
}
 
[Test]
public void RunTest()
{
runner.Run(new BasicTest());
}
}
}

Packaging Tests

In order to upload your Tests to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/generic-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>generic-test-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/generic-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Tests to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Tests

Find the JAR file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your JAR file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Find the DLL file created, upload it to the platform. Here are the steps you need to follow in order to upload your JAR file to TestProject:

1. Click on the “NEW TEST” button, choose the “Code” test type and select your project:

 

2. Upload your DLL file:

 

3. Create the test package:

 

4. Now you are all set to start testing:

 

5. You can see here the test package you have just created. You can click to expand it and view its included tests and execute them:

Using Addons

Debugging / Running Addons (Actions)

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full JUnit test source with UI state preparations below:

Code - java
  • java
  • c#

import io.testproject.examples.sdk.actions.AdditionAction;
import io.testproject.java.sdk.v2.Runner;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
 
 
public class Actions {
 
private static Runner runner;
 
@BeforeAll
public static void setup() throws InstantiationException {
runner = Runner.create("YOUR_DEV_TOKEN");
}
 
@AfterAll
public static void tearDown() throws IOException {
runner.close();
}
 
@Test
public void runAction() throws Exception {
 
// Create Action
AdditionAction action = new AdditionAction();
action.a = 1;
action.b = 1;
 
// Run action
runner.run(action);
}
}

To debug or run the action 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.

Actions run in context of a test and assume that required UI state is already in place.
When the action will be used in a test it will be represented as a single step, usually preceded by other steps.

However, when debugging it locally, preparations should be done using the Runner class to start from expected UI state.

You can review a full NUnit test source with UI state preparations below:

Code - c#
  • java
  • c#

using NUnit.Framework;
using TestProject.SDK.Examples.Generic.Addon;
 
namespace TestProject.SDK.Examples.Generic.Runners.Nunit
{
[TestFixture]
public class GenericTests
{
private static string DevToken = "YOUR_DEV_TOKEN";
 
Runner runner;
 
[SetUp]
public void SetUp()
{
runner = RunnerFactory.Instance.Create(DevToken);
}
 
[TearDown]
public void TearDown()
{
runner.Dispose();
}
 
[Test]
public void RunAction()
{
// Create Action
var action = new AdditionAction();
action.a = 1;
action.b = 1;
 
// Run action
runner.Run(action);
}
}
}

Addon Manifest

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

The manifest is a descriptor of your Addon, it contains a unique GUID for the addon and a list of required permissions.

Create an Addon in the Addons screen and download the generated manifest, placing it in your project resources folder (e.g. src/main/resources).

Packaging Addons

In order to upload your Addon to TestProject, you have to package it as JAR file.
Export your code as an uber JAR file with dependencies, excluding TestProject SDK.

Packaging using Gradle

Here’s an example of build.gradle file:

Code - java
  • java
  • c#

group 'io.testproject'
version '1.1'
 
apply plugin: 'java'
 
// If necessary, update the location of TestProject SDK JAR file
def TP_SDK = '../../io.testproject.sdk.java.jar'
 
compileJava.options.encoding = 'UTF-8'
 
sourceCompatibility = 1.8
 
repositories {
mavenCentral()
}
 
// Configurations
configurations {
tpsdk
compile.extendsFrom tpsdk
}
 
// JAR Task
jar {
assert file("${TP_SDK}").exists(): "TestProject SDK JAR file was not found, please update the TP_SDK variable"
archiveName "${rootProject.name}-${version}.jar"
dependsOn configurations.runtime
from {
// Removes TestProject SDK
(configurations.runtime - configurations.tpsdk).collect {
it.isDirectory() ? it : zipTree(it)
}
}
 
// Extract SDK version
from {
(configurations.tpsdk).collect {
zipTree(it).matching {
include 'testproject-sdk.properties'
}
}
}
}
 
dependencies {
tpsdk files("${TP_SDK}")
compile files('src/main/proxy/generic-example-addon.proxy.jar')
 
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntime 'org.junit.platform:junit-platform-runner:1.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testRuntime 'org.junit.vintage:junit-vintage-engine:5.3.1'
}

 

Packaging using Maven

Here’s an example of pom.xml file:

Code - java
  • java
  • c#

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testproject</groupId>
<artifactId>generic-addon-example</artifactId>
<version>1.1</version>

<properties>
<tp.sdk.path>${project.basedir}/../../io.testproject.sdk.java.jar</tp.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.platform/junit-platform-runner –>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.1</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine –>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine –>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<!– TestProject SDK –>
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0</version>
<!– Update the location of the sdk as required –>
<systemPath>${tp.sdk.path}</systemPath>
<scope>system</scope> <!– Local file won't be assembled by maven-assembly-plugin –>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<!– Assembly Plugin – Create a JAR with dependencies for uploading to TestProject –>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!–Tests Plugin–>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!– Compile Plugin –>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

 

And a descriptor file referenced in pom.xml:

Code - java
  • java
  • c#

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!–Assemble all runtime dependencies–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<!–Exclude Addon Example Proxy JAR–>
<exclude>**/generic-example-addon.proxy.jar</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
<!–Extract TestProject SDK Properties–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>system</scope>
<unpack>true</unpack>
<includes>
<include>io.testproject:java-sdk</include>
</includes>
<unpackOptions>
<includes>
<include>testproject-sdk.properties</include>
</includes>
</unpackOptions>
</dependencySet>
<!–Exclude TestProject SDK from the resulting JAR–>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
<excludes>
<exclude>io.testproject:java-sdk</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

In order to upload your Addons to TestProject you must prepare either a DLL file or a ZIP file:

  • If your package only depends on TestProject SDK, you can upload the built DLL file to TestProject UI.
  • If your package has other dependencies (e.g. DropBox API), Create a zip file from your project output (including dependencies, excluding TestProject SDK) and upload it to TestProject UI.

Uploading Addons

Find the JAR file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Find the DLL/ZIP file created and upload it to the platform. Actions developed will appear in the relevant lists (element inspector / recorder widget).

Table of contents
  • Using Tests
  • Debugging / Running Tests
  • Packaging Tests
  • Uploading Tests
  • Using Addons
  • Debugging / Running Addons (Actions)
  • Addon Manifest
  • Packaging Addons
  • Uploading Addons

Android Examples

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Extended Test

TestProject SDK provides extra features:

  • Parametrization by simply adding fields with relevant annotations.
  • Step reports separating the different stages of the test (each report will appear as a separate step in the future execution reports).

Here is a code example for a Test using these features:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.sdk.v2.drivers.AndroidDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.tests.AndroidTest;
import io.testproject.java.sdk.v2.tests.helpers.AndroidTestHelper;
import org.openqa.selenium.By;

@Test(name = "Extended Test")
public class ExtendedTest implements AndroidTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

public ExecutionResult execute(AndroidTestHelper helper) throws FailureException {
AndroidDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() > 0) {
report.result("Logged in successfully");
return ExecutionResult.PASSED;
}

report.result("Login failed");
return ExecutionResult.FAILED;
}
}

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.Android.Test
{
[Test(Name = "Extended Test")]
public class ExtendedTest : IAndroidTest
{
[Parameter(DefaultValue = "John Smith")]
public string name;

[Parameter(DefaultValue = "12345")]
public string password;

public ExecutionResult Execute(AndroidTestHelper helper)
{
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
var driver = helper.Driver;
var report = helper.Reporter;

// Login using provided credentials
driver.FindElementById("name").SendKeys(name);
report.Step("Typed username");

driver.FindElementById("password").SendKeys(password);
report.Step("Typed password");

driver.FindElementById("login").Click();
report.Step("Clicked login");

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
{
report.Result = "Logged in successfully";
return ExecutionResult.Passed;
}

report.Result = "Login failed";
return ExecutionResult.Failed;
}
}
}

Extended Action

 

TestProject SDK provides extra features using Annotations.

  1. The Action annotation is used to better describe your action and define how it will appear later in TestProject UI:
    • name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • version – A version string which is used for future reference.
  2. The Parameter annotation is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • description – The description of the parameter
    • direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • defaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

TestProject SDK provides attributes to describe the action:

  1. The Action attribute is used to better describe your action and define how it will appear later in TestProject UI:
    • Name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • Version – A version string which is used for future reference.
  2. The Parameter attribute is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • Description – The description of the parameter
    • Direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • DefaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

Element Actions

Actions can be element based, when their scope is limited to operations on a specific element and not the whole DOM.
This allows creating smart crowd based addons for industry common elements and libraries.

TypeRandomPhone is an example of an Element Action:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;
 
import io.appium.java_client.android.AndroidElement;
import io.testproject.java.annotations.v2.ElementAction;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.addons.AndroidElementAction;
import io.testproject.java.sdk.v2.addons.helpers.AndroidAddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
 
@ElementAction(name = "Type Random Phone Number")
public class TypeRandomPhoneAction implements AndroidElementAction {
 
@Parameter
public String countryCode = "1";
 
@Parameter
public int maxDigits;
 
@Parameter(direction = ParameterDirection.OUTPUT)
public String phone;
 
public ExecutionResult execute(AndroidAddonHelper helper, AndroidElement element) throws FailureException {
long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - java
  • java
  • c#

long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;

 

It also stores the result in an output field (see the annotation and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner, via JUnit test, it’s important to pass the element search criteria into the action:

Code - java
  • java
  • c#

runner.run(action, By.id("phone"));

After the Addon is uploaded to TestProject platform this will be done via UI.

Code - c#
  • java
  • c#

using System;
using OpenQA.Selenium.Appium.Android;
using TestProject.SDK.Addons.ElementAction;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Common.Attributes;
using TestProject.SDK.Common.Enums;
 
namespace TestProject.SDK.Examples.Android.Addon
{
[Action(Name = "Type Random Phone Number")]
public class TypeRandomPhoneAction : IAndroidElementAction
{
[Parameter]
public string countryCode = "1";
 
[Parameter]
public int maxDigits;
 
[Parameter(Direction = ParameterDirection.Output)]
public string phone;
 
public ExecutionResult Execute(AndroidAddonHelper helper, AndroidElement element)
{
var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;
}
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - c#
  • java
  • c#

var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;

 

It also stores the result in an output field (see the attribute and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner via NUnit test, it’s important to pass the element search criteria into the action:

Code - c#
  • java
  • c#

runner.Run(action, By.Id("phone"));

 

After the Addon is uploaded to TestProject platform this will be done via UI.

Element Type

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be simple definitions such as:

Code - java
  • java
  • c#

//android.widget.Button

 

Or a more complex one, such as:

Code - java
  • java
  • c#

//android.support.v7.widget.RecyclerView[contains(@resource-id, 'my_view') and .//android.widget.TextView[not(contains(@resource-id, 'average_value'))]]

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be a simple definitions such as:

Code - c#
  • java
  • c#

//android.widget.Button

 

Or a more complex one, such as:

Code - c#
  • java
  • c#

//android.support.v7.widget.RecyclerView[contains(@resource-id, 'my_view') and .//android.widget.TextView[not(contains(@resource-id, 'average_value'))]]

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

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 its code in your Test.
To do so, you can download its proxy JAR and use it like this:

Code - java
  • java
  • c#

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:

Code - java
  • java
  • c#

ExecutionResult result = helper.executeProxy(clearFieldsAction);

 

Here is a full source of a Test using an Action Proxy:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.appium.java_client.android.AndroidKeyCode;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.enums.TakeScreenshotConditionType;
import io.testproject.java.sdk.v2.drivers.AndroidDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.tests.AndroidTest;
import io.testproject.java.sdk.v2.tests.helpers.AndroidTestHelper;
import io.testproject.proxy.addon.AndroidExampleAddon;
import io.testproject.proxy.addon.io.testproject.examples.sdk.actions.TypeRandomPhoneAction;
import org.openqa.selenium.By;

@Test(name = "Test with Addon proxy")
public class ProxyTest implements AndroidTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

@Parameter(defaultValue = "Earth")
public String country;

@Parameter(defaultValue = "Address")
public String address;

@Parameter(defaultValue = "[email protected]")
public String email;

public ExecutionResult execute(AndroidTestHelper helper) throws FailureException {
AndroidDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

// Login using provided credentials
if (driver.findElementsByClassName("UIAKeyboard")
.size() > 0) {
driver.pressKeyCode(AndroidKeyCode.KEYCODE_ESCAPE);
}
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

if (driver.findElementsById("greetings").size() == 0) {
report.result("Failed to login");
return ExecutionResult.FAILED;
}

// Complete Profile
report.step(String.format("Logged in with %s:%s",
name, password));

if (driver.findElementsByClassName("UIAKeyboard")
.size() > 0) {
driver.pressKeyCode(AndroidKeyCode.KEYCODE_ESCAPE);
}

driver.findElementById("country").sendKeys(country);
report.step("Typed country");

driver.findElementById("address").sendKeys(country);
report.step("Typed address");

driver.findElementById("email").sendKeys(country);
report.step("Typed email");

// Type random phone number using Addon proxy
TypeRandomPhoneAction actionProxy =
AndroidExampleAddon.typeRandomPhoneAction("1", 7);
ExecutionResult result = helper.executeProxy(actionProxy,
By.id("phone"));
report.step("Type random phone number using Addon proxy",
result.equals(ExecutionResult.PASSED));

// Save profile
driver.findElementById("save").click();

boolean saved = driver.findElementsById("saved").size() > 0;
report.step("Profile information saved", saved,
TakeScreenshotConditionType.Always);

report.result("Test completed successfully");
return ExecutionResult.PASSED;
}
}

This functionality is currently not supported. It is in our 2019 roadmap.

Table of contents
  • Android Examples
  • Extended Test
  • Extended Action
  • Element Actions
  • Element Type
  • Addon Proxy

iOS Examples

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Extended Test

TestProject SDK provides extra features:

  • Parametrization by simply adding fields with relevant annotations.
  • Step reports separating the different stages of the test (each report will appear as a separate step in the future execution reports).

Here is a code example for a Test using these features:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.sdk.v2.drivers.IOSDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.tests.IOSTest;
import io.testproject.java.sdk.v2.tests.helpers.IOSTestHelper;
import org.openqa.selenium.By;

@Test(name = "Extended Test")
public class ExtendedTest implements IOSTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

public ExecutionResult execute(IOSTestHelper helper) throws FailureException {
IOSDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() > 0) {
report.result("Logged in successfully");
return ExecutionResult.PASSED;
}

report.result("Login failed");
return ExecutionResult.FAILED;
}
}

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.IOS.Test
{
[Test(Name = "Extended Test")]
public class ExtendedTest : IIOSTest
{
[Parameter(DefaultValue = "John Smith")]
public string name;

[Parameter(DefaultValue = "12345")]
public string password;

public ExecutionResult Execute(IOSTestHelper helper)
{
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
var driver = helper.Driver;
var report = helper.Reporter;

// Login using provided credentials
driver.FindElementById("name").SendKeys(name);
report.Step("Typed username");

driver.FindElementById("password").SendKeys(password);
report.Step("Typed password");

driver.FindElementById("login").Click();
report.Step("Clicked login");

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
{
report.Result = "Logged in successfully";
return ExecutionResult.Passed;
}

report.Result = "Login failed";
return ExecutionResult.Failed;
}
}
}

Extended Action

TestProject SDK provides extra features using Annotations.

 

  1. The Action annotation is used to better describe your action and define how it will appear later in TestProject UI:
    • name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • version – A version string which is used for future reference.
  2. The Parameter annotation is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • description – The description of the parameter
    • direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • defaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

TestProject SDK provides attributes to describe the action:

  1. The Action attribute is used to better describe your action and define how it will appear later in TestProject UI:
    • Name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • Version – A version string which is used for future reference.
  2. The Parameter attribute is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • Description – The description of the parameter
    • Direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • DefaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

Element Action

Actions can be element based, when their scope is limited to operations on a specific element and not the whole DOM.
This allows creating smart crowd based addons for industry common elements and libraries.

TypeRandomPhone is an example of an Element Action:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;
 
import io.appium.java_client.ios.IOSElement;
import io.testproject.java.annotations.v2.ElementAction;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.addons.IOSElementAction;
import io.testproject.java.sdk.v2.addons.helpers.IOSAddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
 
@ElementAction(name = "Type Random Phone Number")
public class TypeRandomPhoneAction implements IOSElementAction {
 
@Parameter
public String countryCode = "1";
 
@Parameter
public int maxDigits;
 
@Parameter(direction = ParameterDirection.OUTPUT)
public String phone;
 
public ExecutionResult execute(IOSAddonHelper helper, IOSElement element) throws FailureException {
long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - java
  • java
  • c#

long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;

 

It also stores the result in an output field (see the annotation and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner, via JUnit test, it’s important to pass the element search criteria into the action:

Code - java
  • java
  • c#

runner.run(action, By.id("phone"));

 

After the Addon is uploaded to TestProject platform this will be done via UI.

Code - c#
  • java
  • c#

using System;
using OpenQA.Selenium.Appium.iOS;
using TestProject.SDK.Addons.ElementAction;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Common.Attributes;
using TestProject.SDK.Common.Enums;
 
namespace TestProject.SDK.Examples.IOS.Addon
{
[Action(Name = "Type Random Phone Number")]
public class TypeRandomPhoneAction : IIOSElementAction
{
[Parameter]
public string countryCode = "1";
 
[Parameter]
public int maxDigits;
 
[Parameter(Direction = ParameterDirection.Output)]
public string phone;
 
public ExecutionResult Execute(IOSAddonHelper helper, IOSElement element)
{
var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;
}
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - c#
  • java
  • c#

var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;

 

It also stores the result in an output field (see the attribute and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner via NUnit test, it’s important to pass the element search criteria into the action:

Code - c#
  • java
  • c#

runner.Run(action, By.Id("phone"));

 

After the Addon is uploaded to TestProject platform this will be done via UI.

Element Type

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be a simple definitions such as:

Code - java
  • java
  • c#

//XCUIElementTypeButton

 

Or a more complex one, such as:

Code - java
  • java
  • c#

//XCUIElementTypeSearchField[contains(@label = 'Categories')]

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be a simple definition such as:

Code - c#
  • java
  • c#

//XCUIElementTypeButton

 

Or a more complex one, such as:

Code - c#
  • java
  • c#

//XCUIElementTypeSearchField[contains(@label = 'Categories')]

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

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 its code in your Test.
To do so, you can download its proxy JAR and use it like this:

Code - java
  • java
  • c#

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:

Code - java
  • java
  • c#

ExecutionResult result = helper.executeProxy(clearFieldsAction);

 

Here is a full source of a Test using an Action Proxy:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.enums.TakeScreenshotConditionType;
import io.testproject.java.sdk.v2.drivers.IOSDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.tests.IOSTest;
import io.testproject.java.sdk.v2.tests.helpers.IOSTestHelper;
import io.testproject.proxy.addon.iOSExampleAddon;
import io.testproject.proxy.addon.io.testproject.examples.sdk.actions.TypeRandomPhoneAction;
import org.openqa.selenium.By;

@Test(name = "Test with Addon proxy")
public class ProxyTest implements IOSTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

@Parameter(defaultValue = "Earth")
public String country;

@Parameter(defaultValue = "Address")
public String address;

@Parameter(defaultValue = "[email protected]")
public String email;

public ExecutionResult execute(IOSTestHelper helper) throws FailureException {
IOSDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

if (driver.findElementsById("greetings").size() == 0) {
report.result("Failed to login");
return ExecutionResult.FAILED;
}

// Complete Profile
report.step(String.format("Logged in with %s:%s",
name, password));

driver.findElementById("country").sendKeys(country);
report.step("Typed country");

driver.findElementById("address").sendKeys(country);
report.step("Typed address");

driver.findElementById("email").sendKeys(country);
report.step("Typed email");

// Type random phone number using Addon proxy
TypeRandomPhoneAction actionProxy =
iOSExampleAddon.typeRandomPhoneAction("1", 7);
ExecutionResult result = helper.executeProxy(actionProxy,
By.id("phone"));
report.step("Type random phone number using Addon proxy",
result.equals(ExecutionResult.PASSED));

driver.hideKeyboard();

// Save profile
driver.findElementById("save").click();

boolean saved = driver.findElementsById("saved").size() > 0;
report.step("Profile information saved", saved,
TakeScreenshotConditionType.Always);

report.result("Test completed successfully");
return ExecutionResult.PASSED;
}
}

This functionality is currently not supported. It is in our 2019 roadmap.

Table of contents
  • iOS Examples
  • Extended Test
  • Extended Action
  • Element Action
  • Element Type
  • Addon Proxy

Web Examples

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Extended Test

TestProject SDK provides extra features:

  • Parametrization by simply adding fields with relevant annotations.
  • Step reports separating the different stages of the test (each report will appear as a separate step in the future execution reports).

Here is a code example for a Test using these features:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;
import org.openqa.selenium.By;

@Test(name = "Extended Test")
public class ExtendedTest implements WebTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

public ExecutionResult execute(WebTestHelper helper) throws FailureException {
WebDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

driver.navigate().to("https://example.testproject.io/web/");

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

// Verify 'logout' is displayed
if (driver.findElements(By.id("logout")).size() > 0) {
report.result("Logged in successfully");
return ExecutionResult.PASSED;
}

report.result("Login failed");
return ExecutionResult.FAILED;
}
}

Code - c#
  • java
  • c#

using OpenQA.Selenium;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
using TestProject.SDK.Common.Attributes;

namespace TestProject.SDK.Examples.Web.Test
{
[Test(Name = "Extended Test")]
public class ExtendedTest : IWebTest
{
// Test parameters
[Parameter(DefaultValue = "John Smith")]
public string name;

[Parameter(DefaultValue = "12345")]
public string password;

public ExecutionResult Execute(WebTestHelper helper)
{
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
var driver = helper.Driver;
var report = helper.Reporter;

// Navigate to TestProject Demo website
driver.Navigate().GoToUrl("https://example.testproject.io/web/");

// Login using provided credentials
driver.FindElementById("name").SendKeys(name);
report.Step("Typed username");

driver.FindElementById("password").SendKeys(password);
report.Step("Typed password");

driver.FindElementById("login").Click();
report.Step("Clicked login");

// Verify 'logout' is displayed
if (driver.FindElements(By.Id("logout")).Count > 0)
{
report.Result = "Logged in successfully";
return ExecutionResult.Passed;
}

report.Result = "Login failed";
return ExecutionResult.Failed;
}
}
}

Extended Action

TestProject SDK provides extra features using Annotations.

 

  1. The Action annotation is used to better describe your action and define how it will appear later in TestProject UI:
    • name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • version – A version string which is used for future reference.
  2. The Parameter annotation is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • description – The description of the parameter
    • direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • defaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

TestProject SDK provides attributes to describe the action:

  1. The Action attribute is used to better describe your action and define how it will appear later in TestProject UI:
    • Name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • Version – A version string which is used for future reference.
  2. The Parameter attribute is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • Description – The description of the parameter
    • Direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • DefaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

Element Actions

Actions can be element based, when their scope is limited to operations on a specific element and not the whole DOM.
This allows creating smart crowd based addons for industry common elements and libraries.

TypeRandomPhone is an example of an Element Action:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.actions;
 
import io.testproject.java.annotations.v2.ElementAction;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.addons.WebElementAction;
import io.testproject.java.sdk.v2.addons.helpers.WebAddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import org.openqa.selenium.WebElement;
 
@ElementAction(name = "Type Random Phone Number")
public class TypeRandomPhoneAction implements WebElementAction {
 
@Parameter
public String countryCode = "1";
 
@Parameter
public int maxDigits;
 
@Parameter(direction = ParameterDirection.OUTPUT)
public String phone;
 
public ExecutionResult execute(WebAddonHelper helper, WebElement element) throws FailureException {
long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - java
  • java
  • c#

long number = (long) (Math.random() * Math.pow(10, maxDigits));
phone = String.format("+%s%s", countryCode, number);
element.sendKeys(phone);
return ExecutionResult.PASSED;

 

It also stores the result in an output field (see the annotation and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner, via JUnit test, it’s important to pass the element search criteria into the action:

Code - java
  • java
  • c#

runner.run(action, By.id("phone"));

 

After the Addon is uploaded to TestProject platform this will be done via UI.

Code - c#
  • java
  • c#

using System;
using OpenQA.Selenium;
using TestProject.SDK.Common.Attributes;
using TestProject.SDK.Common.Enums;
using TestProject.SDK.Addons.Helpers;
using TestProject.SDK.Addons.ElementAction;
 
namespace TestProject.SDK.Examples.Web.Addon
{
[Action(Name = "Type Random Phone Number")]
public class TypeRandomPhoneAction : IWebElementAction
{
// Action parameters
[Parameter]
public string countryCode = "1";
 
[Parameter]
public int maxDigits;
 
[Parameter(Direction = ParameterDirection.Output)]
public string phone;
 
public ExecutionResult Execute(WebAddonHelper helper, IWebElement element)
{
var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;
}
}
}

 

This action generates a random phone number based on provided country code and max digits amount, typing it in a text field:

Code - c#
  • java
  • c#

var randomer = new Random();
long number = randomer.Next(1, (int)Math.Pow(10, maxDigits));
phone = $"+{countryCode}{number}";
element.SendKeys(phone);
return ExecutionResult.Passed;

It also stores the result in an output field (see the attribute and ParameterDirection.OUTPUT configuration) for further use later in the test.
When the action is debugged using a Runner via NUnit test, it’s important to pass the element search criteria into the action:

Code - c#
  • java
  • c#

runner.Run(action, By.Id("phone"));

 

After the Addon is uploaded to TestProject platform this will be done via UI.

Element Type

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be a simple definition such as:

Code - java
  • java
  • c#

//div

 

Or a more complex one, such as:

Code - java
  • java
  • c#

//div[contains(@class, 'progressbar') and contains(@class, 'widget') and @role = 'progressbar']

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

Element Actions are made to be used on a specific Element Types. Element Types are defined in TestProject using XPath to describe target elements similarities. It can be a simple definitions such as:

Code - c#
  • java
  • c#

//div

 

Or a more complex one, such as:

Code - c#
  • java
  • c#

//div[contains(@class, 'progressbar') and contains(@class, 'widget') and @role = 'progressbar']

 

It is up to the Action developer how to narrow and limit the list of element types that the action developed will be applicable to.

Addons 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 its code in your Test.
To do so, you can download its proxy JAR and use it like this:

Code - java
  • java
  • c#

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:

Code - java
  • java
  • c#

ExecutionResult result = helper.executeProxy(clearFieldsAction);

 

Here is a full source of a Test using an Action Proxy:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;

import io.testproject.examples.sdk.pages.LoginPage;
import io.testproject.examples.sdk.pages.ProfilePage;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.enums.TakeScreenshotConditionType;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.TestReporter;
import io.testproject.java.sdk.v2.support.PageFactory;
import io.testproject.java.sdk.v2.tests.WebTest;
import io.testproject.java.sdk.v2.tests.helpers.WebTestHelper;
import io.testproject.proxy.addon.WebExampleAddon;
import io.testproject.proxy.addon.io.testproject.examples.sdk.actions.TypeRandomPhoneAction;
import org.openqa.selenium.By;

@Test(name = "Test with Addon proxy")
public class ProxyTest implements WebTest {

@Parameter(defaultValue = "John Smith")
public String name;

@Parameter(defaultValue = "12345")
public String password;

@Parameter(defaultValue = "United States")
public String country;

@Parameter(defaultValue = "Address")
public String address;

@Parameter(defaultValue = "[email protected]")
public String email;

public ExecutionResult execute(WebTestHelper helper) throws FailureException {

// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
WebDriver driver = helper.getDriver();
TestReporter report = helper.getReporter();

// Navigate to TestProject Demo website
driver.navigate().to("https://example.testproject.io/web/");
report.step("Navigated to TestProject Demo",
driver.findElementsById("login").size() > 0);

// Login using provided credentials
driver.findElement(By.id("name")).sendKeys(name);
report.step("Typed username");

driver.findElement(By.id("password")).sendKeys(password);
report.step("Typed password");

driver.findElement(By.id("login")).click();
report.step("Clicked Login");

if (driver.findElementsById("greetings").size() == 0) {
report.result("Failed to login");
return ExecutionResult.FAILED;
}

// Complete Profile
report.step(String.format("Logged in with %s:%s",
name, password));

driver.findElementById("country").sendKeys(country);
report.step("Typed country");

driver.findElementById("address").sendKeys(country);
report.step("Typed address");

driver.findElementById("email").sendKeys(country);
report.step("Typed email");

// Type random phone number using Addon proxy
TypeRandomPhoneAction actionProxy =
WebExampleAddon.typeRandomPhoneAction("1", 7);
ExecutionResult result = helper.executeProxy(actionProxy,
By.id("phone"));
report.step("Type random phone number using Addon proxy",
result.equals(ExecutionResult.PASSED));

// Save profile
driver.findElementById("save").click();

boolean saved = driver.findElementsById("saved").size() > 0;
report.step("Profile information saved", saved,
TakeScreenshotConditionType.Always);

report.result("Test completed successfully");
return ExecutionResult.PASSED;
}
}

This functionality is currently not supported. It is in our 2019 roadmap.

Table of contents
  • Web Examples
  • Extended Test
  • Extended Action
  • Element Actions
  • Element Type
  • Addons Proxy

Generic Examples

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Now that you are familiar with creating basic tests and addons, here you can find more examples.

The code parts below demonstrate how to use TestProject SDK and don’t reflect the full source code.
A complete example can be found in TestProject GitHub examples repository.

Extended Test

Generic tests are automation tasks that do not interact with user interface elements.
TestProject SDK provides extra features:

  • Parametrization by simply adding fields with relevant annotations.
  • Step reports separating the different stages of the test (each report will appear as a separate step in the future execution reports).

Here is a code example for a Test using these features:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;
 
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.GenericTest;
import io.testproject.java.sdk.v2.tests.helpers.TestHelper;
 
@Test(name = "Extended Test")
public class ExtendedTest implements GenericTest {
 
@Parameter(defaultValue = "1")
public int a;
 
@Parameter(defaultValue = "1")
public int b;
 
@Parameter(description = "Calculation expected result")
public int expectedResult;
 
@Parameter(description = "Calculation actual result", direction = ParameterDirection.OUTPUT)
public int actualResult;
 
public ExecutionResult execute(TestHelper helper) throws FailureException {
 
this.actualResult = a + b;
helper.getReporter().step(String.format("%d + %d == %d?", this.a, this.b, this.expectedResult), this.actualResult == this.expectedResult);
 
helper.getReporter().result("Addition result is: " + this.actualResult);
 
return this.actualResult == this.expectedResult ? ExecutionResult.PASSED : ExecutionResult.FAILED;
}
}

Code - c#
  • java
  • c#

using TestProject.SDK.Common.Attributes;
using TestProject.SDK.Common.Enums;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
 
namespace TestProject.SDK.Examples.Generic.Test
{
[Test(Name = "Extended Test")]
public class ExtendedTest : IGenericTest
{
 
[Parameter(DefaultValue = "1")]
public int a;
 
[Parameter(DefaultValue = "1")]
public int b;
 
[Parameter(Description = "Calculation expected result")]
public int expectedResult;
 
[Parameter(Description = "Calculation actual result", Direction = ParameterDirection.Output)]
public int actualResult;
 
public ExecutionResult Execute(GenericTestHelper helper)
{
actualResult = a + b;

helper.Reporter.Step($"{a} + {b} == {expectedResult}?", actualResult == expectedResult);

helper.Reporter.Result = "Addition result is: " + actualResult;

return actualResult == expectedResult ? ExecutionResult.Passed : ExecutionResult.Failed;
}
}
}

Extended Action

TestProject SDK provides extra features using Annotations.

  1. The Action annotation is used to better describe your action and define how it will appear later in TestProject UI:
    • name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • version – A version string which is used for future reference.
  2. The Parameter annotation is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • description – The description of the parameter
    • direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • defaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

TestProject SDK provides attributes to describe the action:

  1. The Action attribute is used to better describe your action and define how it will appear later in TestProject UI:
    • Name – The name of the action (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 (reports for example). The description can use placeholders {{propertyName}} do dynamically change the text according to test properties.
    • Version – A version string which is used for future reference.
  2. The Parameter attribute is used to better describe your action’s inputs and outputs, in the example above there are two parameters – question and answer.
    • Description – The description of the parameter
    • Direction – Defines the parameter as an input (default if omitted) or an output parameter. An input parameter will able to receive values when it is being executed while the output parameter value will be retrieved at the end of test execution (and can be used in other places later on in the automation scenario).
    • DefaultValue – Defines a default value that will be used for the parameter.

NOTE: Unlike tests, actions cannot use assertions because an action is a single generic reusable unit.

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 its code in your Test.
To do so, you can download its proxy JAR and use it like this:

Code - java
  • java
  • c#

AdditionAction actionProxy = GenericExampleAddon.additionAction(a, b);

 

Implemented execute() method receives a Helper instance as a parameter.
Via this helper, you can execute the proxy by invoking the executeProxy method:

Code - java
  • java
  • c#

ExecutionResult result = helper.executeProxy(actionProxy);

 

Here is a full source of a Test using an Action Proxy:

Code - java
  • java
  • c#

package io.testproject.examples.sdk.tests;
 
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.annotations.v2.Test;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.tests.GenericTest;
import io.testproject.java.sdk.v2.tests.helpers.TestHelper;
import io.testproject.proxy.addon.GenericExampleAddon;
import io.testproject.proxy.addon.io.testproject.examples.sdk.actions.AdditionAction;
 
@Test(name = "Test with Addon proxy")
public class ProxyTest implements GenericTest {
 
@Parameter(defaultValue = "1")
public int a;
 
@Parameter(defaultValue = "1")
public int b;
 
@Parameter(description = "Calculation expected result")
public int expectedResult;
 
@Parameter(description = "Calculation actual result", direction = ParameterDirection.OUTPUT)
public int actualResult;
 
@Override
public ExecutionResult execute(TestHelper helper) throws FailureException {
AdditionAction actionProxy = GenericExampleAddon.additionAction(a, b);
ExecutionResult result = helper.executeProxy(actionProxy);
 
this.actualResult = actionProxy.result;
 
boolean passed = result.equals(ExecutionResult.PASSED) && this.actualResult == this.expectedResult;
 
helper.getReporter().step(String.format("%d + %d == %d?", this.a, this.b, this.expectedResult),
passed);
 
helper.getReporter().result("Addition result is: " + this.actualResult);
 
return passed ? ExecutionResult.PASSED : ExecutionResult.FAILED;
}
}

This functionality is currently not supported. It is in our 2019 roadmap.

Table of contents
  • Generic Examples
  • Extended Test
  • Extended Action
  • Addon Proxy