Comprehensive Scripting SDK

A single SDK to script any test for web, mobile, and even API’s.
100% compatible with Selenium and Appium.

100% Native Selenium and Appium

Continue using your existing scripts. Simply add one line to include TestProject’s scripting OpenSDK and you're ready to go. Save a bunch of time and enjoy a handful of out of the box benefits, including automatic HTML/PDF test reports!

Cross Language Support

Script in whatever programming language you prefer (Java, Python or C#), within the same automation platform.

Familiar Scripting Syntax

Why reinvent the wheel? We use the industry standard Selenium and Appium syntax to make onboarding easy.

Mobile and Web Testing in a Single Executable

Quickly jump from testing your mobile app to validating data in your web app. One solution for end to end testing.

Store Your Tests With Your Code

No need to manage test case versions separately of code changes. Keep your tests right alongside your application code.

Getting Java SDK

To get started, you need to complete the following prerequisites checklist:

You must have Java Development Kit (JDK) 11 or newer installed.

Installing SDK

Java SDK is available as a Maven dependency. Refer to the instructions in Maven Central on how to include it in your project: https://search.maven.org/artifact/io.testproject/java-sdk.

That's it - you're ready to go!

Table of contents
  • Getting Java SDK
  • Installing SDK

Getting C# SDK

To get started, you need to complete the following prerequisites checklist:

Installing SDK

C# SDK is available as a NuGet package. Use Visual Studio IDE to search for TestProject SDK and add it to your project: https://www.nuget.org/packages/TestProject.SDK.

That's it - you're ready to go!

Table of contents
  • Getting C# SDK
  • Installing SDK

Getting Python SDK

To get started, you need to complete the following prerequisites checklist:

Installing SDK

The TestProject Python SDK is available as a PyPI package. Refer to the instructions in PyPI on how to add it as a package in your project: https://pypi.org/project/testproject-python-sdk/

All you need to do is add it as a Python module using:

Code - Python

pip install testproject-python-sdk

That's it - you're ready to go!

Table of contents
  • Getting Python SDK
  • Installing SDK

Web Test Development

Already registered your TestProject Agent? Great! Now you can create your Web test by using familiar Selenium APIs, without the need of installing or configuring Selenium, or any 3rd party libraries.

TestProject’s Agent is a single executable that already includes all the libraries, drivers and configs you need, and makes sure you are always up-to-date with the latest versions. All that's left for you to do is to start writing your test cases.

Let's get started!

Simple Web Test Example

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.testproject.sdk.drivers.web.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;

/**
* Web Test Basic Example.
*/
public final class WebTest {

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
ChromeDriver driver = new ChromeDriver(new ChromeOptions());

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

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

boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private WebTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace WebExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsWeb(AutomatedBrowserType.Chrome)
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name="main")]
public class MainTest : 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;
var reporter = helper.Reporter;

driver.Navigate().GoToUrl("https://example.testproject.io/web/");

driver.FindElementByCssSelector("#name").SendKeys("John Smith");
driver.FindElementByCssSelector("#password").SendKeys("12345");
driver.FindElementByCssSelector("#login").Click();

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver
from selenium.webdriver.chrome.options import Options

# Web Test Basic Example.
def web_test():
options = Options()
driver = webdriver.Chrome(chrome_options=options)

# Navigate to the TestProject example website.
driver.get("https://example.testproject.io/web/")

# Login using provided credentials.
driver.find_element_by_css_selector("#name").send_keys("John Smith")
driver.find_element_by_css_selector("#password").send_keys("12345")
driver.find_element_by_css_selector("#login").click()

passed = driver.find_element_by_css_selector("#logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
web_test()

Observe Test Reports

TestProject automatically creates the test reports for you. Once your test has been executed, you can navigate to your TestProject account, go to the "Reports" tab and observe the test report that has been created for you on the fly.

WebReport

Customize Test Reports

You can customize the default test reports that were created for you, by changing them to have a unique Project name, unique Job name and include in unique step messages and screenshots. Here is an example of how to customize your test reports:

Custom Report Message and Screenshot

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.testproject.sdk.drivers.web.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;

/**
* Web Test Basic Example.
*/
public final class WebTest {

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
ChromeDriver driver = new ChromeDriver(new ChromeOptions(),
// Custom Project & Job names
"Custom Project", "Custom Job");

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

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

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private WebTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace WebExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsWeb(AutomatedBrowserType.Chrome)
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name="main")]
public class MainTest : 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;
var reporter = helper.Reporter;

driver.Navigate().GoToUrl("https://example.testproject.io/web/");

driver.FindElementByCssSelector("#name").SendKeys("John Smith");
driver.FindElementByCssSelector("#password").SendKeys("12345");
driver.FindElementByCssSelector("#login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# Web Test Basic Example.
def web_test():
# Custom project & job names.
driver = webdriver.Chrome(projectname="Custom Project", jobname="Custom Job")

# Navigate to the TestProject example website.
driver.get("https://example.testproject.io/web/")

# Login using provided credentials.
driver.find_element_by_css_selector("#name").send_keys("John Smith")
driver.find_element_by_css_selector("#password").send_keys("12345")
driver.find_element_by_css_selector("#login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_css_selector("#logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
web_test()

Observe Custom Reports

Web

Custom Capabilities

In addition to customizing your test reports as demonstrated above, you can also add to your tests Custom Capabilities as seen in the code example below.

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.testproject.sdk.drivers.web.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;

/**
* Web Test Basic Example.
*/
public final class WebTest {

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
ChromeOptions chromeOptions = new ChromeOptions();

// Setting custom capability - Chrome binary path
chromeOptions.setBinary("/path/to/my/custom/chrome");

ChromeDriver driver = new ChromeDriver(chromeOptions,
// Custom Project & Job names
"Custom Project", "Custom Job");

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

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

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private WebTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace WebExample
{
public class Program
{
public static void Main(string[] args)
{
var options = new ChromeOptions();
// Setting custom capability - Chrome binary path
options.SetBinary("/path/to/my/custom/chrome");

using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsWeb(AutomatedBrowserType.Chrome)
.WithOptions(options)
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name="main")]
public class MainTest : 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;
var reporter = helper.Reporter;

driver.Navigate().GoToUrl("https://example.testproject.io/web/");

driver.FindElementByCssSelector("#name").SendKeys("John Smith");
driver.FindElementByCssSelector("#password").SendKeys("12345");
driver.FindElementByCssSelector("#login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver
from selenium.webdriver.chrome.options import Options

# Web Test Basic Example.
def web_test():
# Setting custom capability - Chrome binary path.
options = Options()
options.binary_location = "/path/to/my/custom/chrome"

# Custom project & job names.
driver = webdriver.Chrome(chrome_options=options, projectname="Custom Project", jobname="Custom Job")

# Navigate to the TestProject example website.
driver.get("https://example.testproject.io/web/")

# Login using provided credentials.
driver.find_element_by_css_selector("#name").send_keys("John Smith")
driver.find_element_by_css_selector("#password").send_keys("12345")
driver.find_element_by_css_selector("#login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_css_selector("#logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
web_test()

Run Tests part of CI/CD Flow

You can run your tests within your CI/CD flow by following the official documentation here: https://docs.testproject.io/testproject-sdk/using-testproject-scripted-tests-within-ci-cd

Table of contents
  • Web Test Development
  • Simple Web Test Example
  • Observe Test Reports
  • Customize Test Reports
  • Custom Report Message and Screenshot
  • Observe Custom Reports
  • Custom Capabilities
  • Run Tests part of CI/CD Flow

Android Test Development

Already registered your TestProject Agent? Great! Now you can create your Android test by using familiar Appium APIs, without the need of installing or configuring Appium, or any 3rd party libraries, such as: Android Studio, ADBs, etc.

TestProject’s Agent is a single executable that already includes all the libraries, drivers and configs you need, and makes sure you are always up-to-date with the latest versions. All that's left for you to do is to start writing your test cases.

Let's get started!

Simple Android Test Example

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* Android Test Basic Example.
*/
public final class AndroidTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.UDID, "{YOUR_DEVICE_UDID}");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.APP,
"https://github.com/testproject-io/android-demo-app/raw/master/APK/testproject-demo-app.apk");

AndroidDriver driver = new AndroidDriver<>(capabilities);
driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private AndroidTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace AndroidExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsAndroid("MY_UDID", "MY_APP_PACKAGE", "MY_ACTIVITY")
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IAndroidTest
{
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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# Android Test Basic Example.
def android_test():
desired_capabilities = {
"appPackage": "io.testproject.demo",
"appActivity": "io.testproject.demo.MainActivity",
"platformName": "Android",
"udid": "{{MY_UDID}}"
}

driver = webdriver.Remote(desired_capabilities=desired_capabilities)

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
android_test()

Observe Test Reports

TestProject automatically creates the test reports for you. Once your test has been executed, you can navigate to your TestProject account, go to the "Reports" tab and observe the test report that has been created for you on the fly.

AndroidReport

Customize Test Reports

You can customize the default test reports that were created for you, by changing them to have a unique Project name, unique Job name and include in unique step messages and screenshots. Here is an example of how to customize your test reports:

Custom Report Message and Screenshot

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* Android Test Basic Example.
*/
public final class AndroidTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.UDID, "emulator-5554");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.APP,
"https://github.com/testproject-io/android-demo-app/raw/master/APK/testproject-demo-app.apk");

AndroidDriver driver = new AndroidDriver<>(capabilities,
// Custom Project & Job names
"Custom Project", "Custom Job");
driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private AndroidTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace AndroidExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsAndroid("MY_UDID", "MY_APP_PACKAGE", "MY_ACTIVITY")
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IAndroidTest
{
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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# Android Test Basic Example.
def android_test():
desired_capabilities = {
"appPackage": "io.testproject.demo",
"appActivity": "io.testproject.demo.MainActivity",
"platformName": "Android",
"udid": "{{MY_UDID}}"
}

# Custom project & job names.
driver = webdriver.Remote(desired_capabilities=desired_capabilities, projectname="Custom Project",
jobname="Custom Job")

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
android_test()

Observe Custom Reports

Android

Custom Capabilities

In addition to customizing your test reports as demonstrated above, you can also add to your tests Custom Capabilities as seen in the code example below.

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* Android Test Basic Example.
*/
public final class AndroidTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.UDID, "emulator-5554");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.APP,
"https://github.com/testproject-io/android-demo-app/raw/master/APK/testproject-demo-app.apk");

// Setting custom capability - auto-accept all permission prompts
capabilities.setCapability(AndroidMobileCapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.ACCEPT);

AndroidDriver driver = new AndroidDriver<>(capabilities,
// Custom Project & Job names
"Custom Project", "Custom Job");
driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private AndroidTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace AndroidExample
{
public class Program
{
public static void Main(string[] args)
{
var options = new AppiumOptions();
options.SetCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
options.SetCapability(MobileCapabilityType.UDID, "emulator-5554");
options.SetCapability(CapabilityType.BROWSER_NAME, "");
options.SetCapability(MobileCapabilityType.APP,
"https://github.com/testproject-io/android-demo-app/raw/master/APK/testproject-demo-app.apk");

// Setting custom capability - auto-accept all permission prompts
options.SetCapability(AndroidMobileCapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.ACCEPT);

using (var runner = new RunnerBuilder("MY_TOKEN")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.AsAndroid("MY_UDID", "MY_APP_PACKAGE", "MY_ACTIVITY")
.WithOptions(options)
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IAndroidTest
{
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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# Android Test Basic Example.
def android_test():
desired_capabilities = {
"appPackage": "io.testproject.demo",
"appActivity": "io.testproject.demo.MainActivity",
"platformName": "Android",
"udid": "{{MY_UDID}}",
# Setting custom capability - auto-accept all permission prompts.
'autoGrantPermissions': "true"
}

# Custom project & job names.
driver = webdriver.Remote(desired_capabilities=desired_capabilities, projectname="Custom Project",
jobname="Custom Job")

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
android_test()

Run Tests part of CI/CD Flow

You can run your tests within your CI/CD flow by following the official documentation here: https://docs.testproject.io/testproject-sdk/using-testproject-scripted-tests-within-ci-cd

Table of contents
  • Android Test Development
  • Simple Android Test Example
  • Observe Test Reports
  • Customize Test Reports
  • Custom Report Message and Screenshot
  • Observe Custom Reports
  • Custom Capabilities
  • Run Tests part of CI/CD Flow

iOS Test Development

Already registered your TestProject Agent? Great! Now you can create your iOS test by using familiar Appium APIs, without the need of installing or configuring Appium, or any 3rd party libraries.

TestProject’s Agent is a single executable that already includes all the libraries, drivers and configs you need, and makes sure you are always up-to-date with the latest versions. All that's left for you to do is to start writing your test cases.

Let's get started!

Simple iOS Test Example

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* iOS Test Basic Example.
*/
public final class IOSTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.UDID, "{YOUR_DEVICE_UDID}");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "{YOUR_DEVICE_NAME}");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

// Compile and deploy the App from source https://github.com/testproject-io/ios-demo-app
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "io.testproject.Demo");

IOSDriver driver = new IOSDriver<>(capabilities);
driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private IOSTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace IOSExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.AsIOS("MY_UDID", "MY_DEVICE_NAME", "MY_BUNDLE")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IIOSTest
{

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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# iOS Test Basic Example.
def ios_test():
desired_capabilities = {
"bundleId": "io.testproject.Demo",
"deviceName" : "{{MY_DEVICE_NAME}}",
"platformName": "iOS",
"udid": "{{MY_UDID}}"
}

driver = webdriver.Remote(desired_capabilities=desired_capabilities)

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
ios_test()

Observe Test Reports

TestProject automatically creates the test reports for you. Once your test has been executed, you can navigate to your TestProject account, go to the "Reports" tab and observe the test report that has been created for you on the fly.

iOSReport

Customize Test Reports

You can customize the default test reports that were created for you, by changing them to have a unique Project name, unique Job name and include in unique step messages and screenshots. Here is an example of how to customize your test reports:

Custom Report Message and Screenshot

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* iOS Test Basic Example.
*/
public final class IOSTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.UDID, "00008020-000C68A834B9002E");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "{YOUR_DEVICE_NAME}");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

// Compile and deploy the App from source https://github.com/testproject-io/ios-demo-app
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "io.testproject.Demo");

IOSDriver driver = new IOSDriver<>(capabilities,
// Custom Project & Job names
"Custom Project", "Custom Job");

driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private IOSTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace IOSExample
{
public class Program
{
public static void Main(string[] args)
{
using (var runner = new RunnerBuilder("MY_TOKEN")
.AsIOS("MY_UDID", "MY_DEVICE_NAME", "MY_BUNDLE")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IIOSTest
{

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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# iOS Test Basic Example.
def ios_test():
desired_capabilities = {
"bundleId": "io.testproject.Demo",
"deviceName" : "{{MY_DEVICE_NAME}}",
"platformName": "iOS",
"udid": "{{MY_UDID}}"
}

# Custom project & job names.
driver = webdriver.Remote(desired_capabilities=desired_capabilities, projectname="Custom Project",
jobname="Custom Job")

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
ios_test()

Observe Custom Reports

iOS

Custom Capabilities

In addition to customizing your test reports as demonstrated above, you can also add to your tests Custom Capabilities as seen in the code example below.

Code - java
  • java
  • c#
  • python

package io.testproject.sdk.tests.examples.simple;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.testproject.sdk.drivers.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

/**
* iOS Test Basic Example.
*/
public final class IOSTest {

/**
* Default implicit timeout.
*/
public static final int TIMEOUT = 5;

/**
* Main executable method.
* @param args N/A
* @throws Exception is thrown when driver initialization fails.
*/
public static void main(final String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
capabilities.setCapability(MobileCapabilityType.UDID, "00008020-000C68A834B9002E");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "{YOUR_DEVICE_NAME}");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

// Setting custom capability - auto-accept all permission prompts
capabilities.setCapability(IOSMobileCapabilityType.AUTO_DISMISS_ALERTS, true);

// Compile and deploy the App from source https://github.com/testproject-io/ios-demo-app
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "io.testproject.Demo");

IOSDriver driver = new IOSDriver<>(capabilities,
// Custom Project & Job names
"Custom Project", "Custom Job");

driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);

// Reset App
driver.resetApp();

// 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();

// Custom step with screenshot
driver.report().step("Login Performed", true, true);

boolean passed = driver.findElement(By.id("logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}

driver.quit();
}

private IOSTest() { }
}

Code - c#
  • java
  • c#
  • python

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

namespace IOSExample
{
public class Program
{
public static void Main(string[] args)
{
Desiredoptions options = new Desiredoptions();

options.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
options.setCapability(MobileCapabilityType.UDID, "00008020-000C68A834B9002E");
options.setCapability(MobileCapabilityType.DEVICE_NAME, "{YOUR_DEVICE_NAME}");
options.setCapability(CapabilityType.BROWSER_NAME, "");

// Setting custom capability - auto-accept all permission prompts
options.setCapability(IOSMobileCapabilityType.AUTO_DISMISS_ALERTS, true);

// Compile and deploy the App from source https://github.com/testproject-io/ios-demo-app
options.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "io.testproject.Demo");
using (var runner = new RunnerBuilder("MY_TOKEN")
.AsIOS("MY_UDID", "MY_DEVICE_NAME", "MY_BUNDLE")
.WithProjectName("Custom Project").WithJobName("Custom Job")
.Build())
{
runner.Run(new MainTest());
}
}
}

[Test(Name = "main")]
public class MainTest : IIOSTest
{

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 reporter = helper.Reporter;

driver.ResetApp();

driver.FindElementById("name").SendKeys("John Smith");
driver.FindElementById("password").SendKeys("12345");
driver.FindElementById("login").Click();

// Custom step with screenshot
reporter.Step("Login Performed", true, TakeScreenshotConditionType.Always);

if (driver.FindElements(By.Id("logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}

Code - python
  • java
  • c#
  • python

from src.testproject.sdk.drivers import webdriver

# iOS Test Basic Example.
def ios_test():
desired_capabilities = {
"bundleId": "io.testproject.Demo",
"deviceName" : "{{MY_DEVICE_NAME}}",
"platformName": "iOS",
"udid": "{{MY_UDID}}",
# Setting custom capability - auto-accept all permission prompts.
'autoGrantPermissions': "true"
}

# Custom project & job names.
driver = webdriver.Remote(desired_capabilities=desired_capabilities, projectname="Custom Project",
jobname="Custom Job")

# Login using provided credentials.
driver.find_element_by_id("name").send_keys("John Smith")
driver.find_element_by_id("password").send_keys("12345")
driver.find_element_by_id("login").click()

# Custom step with screenshot.
driver.report().step(description="Login Performed", message="Login", passed=True, screenshot=True)

passed = driver.find_element_by_id("logout").is_displayed()
print("Test passed") if passed else print("Test failed")

driver.quit()

if __name__ == "__main__":
ios_test()

Run Tests part of CI/CD Flow

You can run your tests within your CI/CD flow by following the official documentation here: https://docs.testproject.io/testproject-sdk/using-testproject-scripted-tests-within-ci-cd

Table of contents
  • iOS Test Development
  • Simple iOS Test Example
  • Observe Test Reports
  • Customize Test Reports
  • Custom Report Message and Screenshot
  • Observe Custom Reports
  • Custom Capabilities
  • Run Tests part of CI/CD Flow
Want to See TestProject in Action?

Sign Up for
Your Free Account!