Customizing your tests - Cloud

Talend Cloud API Tester User Guide

EnrichVersion
Cloud
EnrichProdName
Talend Cloud
EnrichPlatform
Talend API Tester
task
Design and Development > Testing APIs
Edit your pom.xml to customize your API test configuration.

Create your custom test configuration

If you want to benefit from the webhooks or customize the test runs, you can configure the pom yourself.

Here is an example pom.xml, the configurable options are detailed below.

<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>org.talend.ci.api-tester</groupId>
    <artifactId>petstore_api</artifactId>
    <version>1.0.0</version>
    <build>
        <plugins>
            <plugin>

                <!-- The Talend maven plugin -->
                <groupId>org.talend.ci</groupId>
                <artifactId>api-tester-maven-plugin</artifactId>
                <version>1.0.0</version>

                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                          <file>Petstore_API.json</file>
                          <selectedEnvironment>API Services's context</selectedEnvironment>

                          <!-- Put your Account ID here. Consult your Account Information in Talend Management Console Subscription page -->
                          <accountId>${account_id}</accountId>

                          <instance>dw</instance>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
        <!-- Put your plugin repository configuration here -->
    </pluginRepositories>
</project>

Pom configuration

The following attributes can be added to the pom to tweak the plugin's behavior. They can be added two different ways:

  • In the configuration tag of the pom (see example above with the attribute file)
  • Passed to the plugin via JVM arguments

If the attribute is defined with a value ${attributeName} in the pom, then you can pass it a value when running the mvn command via a JVM plugin. In the case of the accountId in the pom above, you can pass it as follows:

mvn clean test -Daccount_id=492b2ecd-888d-4087-8ab5-42cab17334ad
Note: The second option is recommended for sensitive information such as the Account ID, to make sure that it never gets committed along with the pom to a public place by mistake.

Pom attributes

The following table describes the available customization options.

Name Type Mandatory Default Description
file File Yes X File path pointing to the Talend Cloud API Tester export file from the pom's location.
selectedEnvironment String No X The name of the environment to be used (make sure it was exported to the JSON file).
accountId String Yes X

A valid Account ID.

You can find your Account ID in the Talend Cloud Management ConsoleSubscription page.

stopOnFailure boolean No false Stops processing build if an error/failure occurs.
httpclientTimeoutInMs Integer No 60000 Time before HTTP time-out in milliseconds.
variables Properties No X Custom variables.
xhrEmulation boolean No true Mimics the Chrome extension behavior by adding the headers that the browser automatically adds, such as accept-*.
followRedirects String No NONE Indicates whether or not the Maven plugin should follow the redirections as it is possible through the Chrome extension settings in the browser. Possible values are NONE or ALL.
beforeTest URL No X URL where a notification should be sent before a test starts.
afterTest URL No X URL where a notification should be sent after a test is completed.
begin URL No X URL where a notification should be sent before the first test is executed.
end URL No X URL where a notification should be sent after the last test is executed.
useMavenProxies boolean No false Indicates whether the proxy configured in ~/.m2/settings.xml should be used for your test's HTTP calls or not.

See the full configuration example below:

<configuration>
    <file>/path/to/json/configuration/file.json</file>
    <selectedEnvironment>QA</selectedEnvironment>
    <accountId>${account_id}</accountId>
    <stopOnFailure>true</stopOnFailure>
    <httpclientTimeoutInMs>30000</httpclientTimeoutInMs>
    <xhrEmulation>false</xhrEmulation>
    <followRedirects>ALL</followRedirects>
    <beforeTest>https://my-ci-api.com/api1/notifications</beforeTest>
    <afterTest>https://my-ci-api.com/api1/notifications</afterTest>
</configuration>

Override environment variables

You can override an environment variable by adding a variables tag in the plugin's configuration.

If you must run your API on a different port on a specific machine, even though the environment is set to 443 via an environment variable host, you will have to make it run on port on 1337. You can do that simply by overriding the environment variable port as shown below.

<configuration>
    <file>test.json</file>
    <selectedEnvironment>localhost</selectedEnvironment>
    <variables>
        <!-- The variable port's value will be overwritten to 1337 -->
        <property>
            <name>port</name>
            <value>1337</value>
        </property>
        <!-- The variable apiEndpoint's value can be set when invoking Maven -->
        <property>
            <name>apiEndpoint</name>
            <value>${api.endpoint}</value>
        </property>
    </variables>
</configuration>
You can set Maven properties as environment variables and define them when launching the plugin. For example, you can set the apiEndpoint value to ${api.endpoint} and define it with the following command:
mvn test -Dapi.endpoint=https://httpbin.org

Use a proxy

Your API may be accessible only through a proxy. In this case, Talend provides you with simple ways to configure a proxy for all HTTP calls made by the maven plugin.

System proxy configuration

If the proxy is configured system-wide on the test computer, then just launch the plugin with a simple:

mvn test -Djava.net.useSystemProxies=true

This argument is available on recent Windows systems and on Gnome 2.x systems. For more information, see Networking Properties.

Maven proxy configuration

The Maven plugin can reuse the Maven's installation proxy configuration, defined in your settings.xml, simply by using the following configuration:

<configuration>
  <file>/test.json</file>
  <useMavenProxies>true</useMavenProxies>
</configuration>
Note: For now, the nonProxyHosts attribute is not supported.

For more information on Maven proxy configuration, see Configuring a proxy.

JVM proxy configuration

The proxy configuration can also be configured at runtime using the standard JVM arguments.

For more information on JVM networking arguments, see Oracle Networking Properties.

The JVM proxy configuration will be applied to all the JVM, which will impact all the requests performed even by other Maven plugins and/or targets.

HTTP proxy configuration

If your proxy is using the http protocol then the following arguments are available.

Name Default Description
http.proxyHost "" The hostname, or address, of the proxy server
http.proxyPort 80 The port number of the proxy server
http.proxyUser "" If the proxy used basic authentication, the authentication's username
http.proxyPassword "" If the proxy used basic authentication, the authentication's password
http.nonProxyHosts localhost|127.*|[::1] Not supported. Indicates the hosts that should be accessed without going through the proxy

Given the previous arguments, the maven plugin can be used:

mvn test -Dhttp.proxyHost=192.168.1.127

HTTPS proxy configuration

If your proxy is using the https protocol then the following arguments are available.

Name Default Description
https.proxyHost "" The hostname, or address, of the proxy server.
https.proxyPort 443 The port number of the proxy server.
http.proxyUser "" If the proxy used basic authentication, the authentication's username.
http.proxyPassword "" If the proxy used basic authentication, the authentication's password.
http.nonProxyHosts localhost|127.*|[::1] Not supported. Indicates the hosts that should be accessed without going through the proxy.

Given the previous arguments, the maven plugin can be used.

mvn test -Dhttps.proxyHost=192.168.1.127

Notifications format

Before/After test notifications

You can make the maven plugin send notifications to a URL of your choice before and/or after each test. If you configure the parameters beforeTest and afterTest in the pom, a POST request is sent to the URL you specified in the configuration at the beginning and end of each test.

The request's body will look like this:

{
  "name":[test name],
  "event":[BeforeTest|AfterTest],
  "result":[Ok|Failure|Error] &Tab;&lt;- present only if event=afterTest
}

Begin/End notifications

You can make the maven plugin send notifications to a URL of your choice when it starts and ends. If you configure the parameters begin and end in the pom, a POST request is sent to the URL you specified in the configuration when the plugin execution starts and ends.

The request's body will look as follows:

{
  "event":[Begin|End]
}