TestProject AddOn

What is TestProject Addon

From testproject addon page – an addon is a collection of coded actions you can use within any test. It’s all stored in TestProject’s collaborative addons library. More details can be found from above link.

Create an addon

Step by step guide to create an addon using Test Project java SDK. What we need:

  • IntelliJ IDE (or any other IDE e.g. Eclipse)
  • Test Project Java SDK
  • manifest.json file
  • descriptor.xml file
  • Good understanding of Maven
  • Good understanding of Selenium automation
  • Reference to https://github.com/testproject-io/java-sdk-examples
  • DEV_TOKEN
  • To create Addon, we will follow the samples mentioned in above github url.

Sample Scenario

Think of a scanario, where we have to create an addon to fill the 3 fields: Address, eMail and Phone in https://example.testproject.io/web/.

Create a Test case in TestProject to fill up the Name, Password, Country, Address, eMail and Phone fields.

And with the help of addon, we will fill up Address, eMail and Phone fields. Though its not an ideal candidate for addon but this blog is just an example on how to create add on and use it.

Create Project in IntelliJ

Create a maven project and make sure the structure is similar to the screenshot attached.

We should have Addon folder (any class within this with @Action annotation will go to TestProject as Action), resources and Runners (to test addon locally) folders

Download Manifest.json file

Create an AddOn in TestProject, provide a name and select File System and Environment and click on Generate & Download manifest button to download the manifest.json file.
Copy the manifest.json file and copy to resources folder.

The manifest.json file content may look different in your case. version no might be 0.1. For me its 0.4 as I have updated the addon actions multiple times. And also we have to focus on guid, which will be discussed later in the blog.

Download the testproject sdk and get the DEV KEY

Go to Integration Menu in the testproject and download the SDK and store it in a folder of your choice.

And store the DEV Token somewhere safe 🙂

Update the pom.xml

Navigate to https://github.com/testproject-io/java-sdk-examples/tree/master/Web/Addon and copy the content of pom.xml file and update in the project.

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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>TestProjectAddon</artifactid>
    <version>1.1</version>
 
    <properties>
        <tp .sdk.path="">${project.basedir}/../../io.testproject.sdk.java.jar</tp>
        <project .build.sourceencoding="">UTF-8</project>
    </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>C:/testproject/TestProject_SDK_0.61.0.jar</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>
                <configuration>
                    <skiptests>true</skiptests>
                </configuration>
            </plugin>
            <!-- Compile Plugin -->
            <plugin>
                <artifactid>maven-compiler-plugin</artifactid>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
   </build>
 
</project>

Notice the line no 46 in the pom.xml file. Make sure systempath is updated with the path where the testproject sdk is stored in your local machine.

Descriptor.xml file

Now we have the manifest file added, pom file updated. testproject sdk download and DEV KEY saved, time to get the descriptor.xml file and add to the project.

Navigate to https://github.com/testproject-io/java-sdk-examples/tree/master/Web/Addon/src/main and copy the descriptor.xml file and add to the project in main folder.

Create addon

Create a class named FillUpThreeFiledsTestProject (any name of your choice) and make sure it implements WebAction interface.
Make sure include the @Action annotation as this will be listed as Action name in Test Project.

package main.Addon;
 
import io.testproject.java.annotations.v2.Action;
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.WebElement;
 
/**
 * Created by Sisirkant on 4/11/2020.
 */
@Action(name = "Fill Up Three Fields")
public class FillUpThreeFieldsTestProject implements WebAction {
    @Override
    public ExecutionResult execute(WebAddonHelper webAddonHelper) throws FailureException {
        WebDriver driver = webAddonHelper.getDriver();
 
        WebElement address = driver.findElementByXPath("//input[@id='address']");
        address.sendKeys("My Address one");
 
        WebElement eMailId = driver.findElementByXPath("//input[@id='email']");
        eMailId.sendKeys("test@test.com");
 
        WebElement phoneNo = driver.findElementByXPath("//input[@id='phone']");
        phoneNo.sendKeys("1111111111");
 
        return ExecutionResult.PASSED;
    }
}

Its a simple addon which will fill up the fields and make sure it returns ExecutionResult.PASSED or FAILED based on your requirement.

Test the addon

In Runners folder, create a class ActionRunnerFillUpThreeFields and write the following

package main.Runners;
 
import io.testproject.java.classes.DriverSettings;
import io.testproject.java.enums.DriverType;
import io.testproject.java.sdk.v2.Runner;
import io.testproject.java.sdk.v2.drivers.WebDriver;
import main.Addon.FillUpThreeFieldsTestProject;
import org.openqa.selenium.support.ui.Select;
 
/**
 * Created by Sisirkant on 4/11/2020.
 */
public class ActionRunnerFillUpThreeFields {
    private static final String DEV_TOKEN = "PASTE YOUR DEV TOKEN HERE";
 
    public static void main(String[] args) throws Exception {
        DriverSettings driverSettings = new DriverSettings(DriverType.Chrome);
        try (Runner runner = new Runner(DEV_TOKEN, driverSettings)) {
            FillUpThreeFieldsTestProject fillUpThreeFieldsTestProject = new FillUpThreeFieldsTestProject();
            WebDriver driver = runner.getDriver(fillUpThreeFieldsTestProject);
            driver.navigate().to("https://example.testproject.io/web/");
            Thread.sleep(5000);
 
            driver.findElementByXPath("//input[@id='name']").sendKeys("Sisirkant");
            driver.findElementByXPath("//input[@id='password']").sendKeys("12345");
            driver.findElementByXPath("//button[@id='login']").click();
            Thread.sleep(5000);
            Select country = new Select(driver.findElementByXPath("//select[@id='country']"));
            country.selectByVisibleText("Algeria");
            runner.run(fillUpThreeFieldsTestProject);
        }
    }
}

Right click on the ActionRunnerFillUpThreeFields and run to make sure that addon works fine.

Create package

Go to Terminal and type the run the following command

mvn clean validate compile test package

The necessary addon package should have been created in target folder as mentioned in the screenshot

Import the AddOn to your project

Go to your project in TestProject and import the addon and it will be similar to the following screen shot. I see 2 add ons as I have created 2 add ons. In case of your project, you may see one.

Upon finish you see the following

All set, now you have your own add to use.

Use it in Test case
If you remember, we have created a Test case in TestProject to fill up the Name, Password, Country, Address, eMail and Phone fields. Not its time to replace the steps filling up Address, eMail and Phone fields with the addon that we have created.

Add the Addon action

Move the added step up (place it just before Step which saves the form) and Save & Exit

Now Run the test case and see if its working or not. It should be working perfectly.

Hopefully this blog is useful for you.

About This Site

The main aim of this site is to share knowledge with fellow software test specialists who are keen to grow both technically and professionally.

Categories