Skip to main content

SDK

Introduction

Valido now has an SDK which we can integrate into the code of our projects to create visual validation tests and see the status and result in the app.

Credentials

First, we need to have the two types of credentials necessary to work with the SDK so contact Valido to get them in case you don't have them.

AWS credentials

AWS credentials are required to write data to S3 and to access the S3 Maven repository. You have three ways to set up this credentials:

  • Add them to the ~/.aws/config file. In case you don't have it, you can create it:
    [default]
    aws_access_key_id= value from AWS access portal
    aws_secret_access_key= value from AWS access portal
  • Setting environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
  • Using AWS CLI.

ℹ️ You can go to Provide temporary credentials to the AWS SDK for Java to get more details about AWS IAM credentials.

Valido crendentials

In order to access the Valido API and send execution results, you must create a Java properties file with the following structure:

username=myusername
password=supersecretpassword
secretHash=supersecrethash

On the other hand, you have also the option to add them by environment variables: VALIDO_USERNAME, VALIDO_PASSWORD and VALIDO_SECRETHASH.

Project setup

The SDK is stored in the private Maven repository in S3, that's why you need the following configuration in the POM file of your project. In this .pom file example, the only tags you should care about are: <repositories>, <distributionManagement>, extensions and the valido-framework dependency

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.orienteed.valido</groupId>
<artifactId>sdk-test</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<repositories>
<repository>
<id>s3.release</id>
<name>Orienteed S3 Maven Release Repo</name>
<url>s3://maven-repo.orienteed.com/release</url>
</repository>
<repository>
<id>s3.snapshot</id>
<name>Orienteed S3 Maven Snapshot Repo</name>
<url>s3://maven-repo.orienteed.com/snapshot</url>
</repository>
</repositories>

<distributionManagement>
<snapshotRepository>
<id>s3.snapshot</id>
<url>s3://maven-repo.orienteed.com/snapshot</url>
</snapshotRepository>
<repository>
<id>s3.release</id>
<url>s3://maven-repo.orienteed.com/release</url>
</repository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.orienteed.valido</groupId>
<artifactId>valido-framework</artifactId>
<version>0.13.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>11</source>
<target>11</target>
<fork>true</fork>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>com.allogy.maven.wagon</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.2.0</version>
</extension>
</extensions>
</build>

</project>

Create SDK test

Set up flow properties

First, before to starting with the code, we need to create a Java .properties file for each flow. For Valido a flow is a test.

env=pro
secretsPath=location/of/valido-credentials.properties
region=ES
resolution=DESKTOP
device=1400x800
os=windows
browser=chrome
driverPath=location/of/driver

Definition of the properties keys:

  • env The Valido environment to be targeted.

  • secretsPath The location of your valido credentials file.

  • region Should be a two letter ISO country code.

  • resolution The resolution is determined by the device: DESKTOP, MOBILE, TABLET.

  • device You can specify a device ID or a resolution with the format width x height.

  • os Operating system for the execution test.

  • browser Specify the browser where the test will run. chrome, firefox,safari...

  • driverPath The location of the browser driver to be used to execute the test.

It is possible that for your projects this configuration can be generic, so to make it easier you should know that these properties can be set as environment variables. To set them as environment variables, they must follow the following format: VALIDO_PROPERTY_KEY, all capital letters.

Test implementation

Go to the valido app and click to the Valido lab [beta] located in the left sidebar. In this section you should give a name to your test and select the brand on were this test will be, and click on create button. The application returns a flow ID, you must save it, because you will need it to reference this flow within our SDK project.

Valido lab section for SDK test creation

Now if you want to implement the SDK in you test, you should:

  • Extend the ValidoCore class.
  • Pass the flow ID and the path of the properties files to the constructor.
package com.orienteed.valido.cores;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.URISyntaxException;

import org.junit.jupiter.api.Test;

import com.orienteed.valido.api.ValidoAPIException;

public class SdkExecutor {

String flowId = "00000xx0-x000-00xx-0000-0x0x0x0d0xx0";
String path = "src/test/resources/valido/chrome-flow-specs.properties";

@Test
public void test1() throws IOException, ValidoAPIException, URISyntaxException {
new SdkFlow(flowId, path).run();
}
}

To access the driver, use the getDriver() method. An example:

package com.orienteed.valido.cores;

import java.io.IOException;
import java.net.URISyntaxException;

import com.orienteed.valido.api.ValidoAPIException;

public class SdkFlow extends ValidoCore {

public SdkFlow(String flowId, String path) throws IOException, ValidoAPIException, URISyntaxException {
super(flowId, path);
}

@Override
public void flow() throws IOException, ValidoAPIException {
getDriver().get("www.valido.ai");
compare("Home page");
}
}