logo logo

Getting Started with TestProject Java OpenSDK

Getting Started with TestProject Java OpenSDK

Test Automation is hard to do well! There are many different things to consider. Not only do you have to think about how to write good code, but you also need to understand how to create good tests. And of all the types of test automation that you might want to write, UI test automation is the hardest kind. It can be tempting to simply write UI tests that mimic what you would do by hand, but any experienced test automation engineer will be able to tell you the pitfalls of doing that.

That might make you think that you shouldn’t write automated UI tests, but that’s not the case either. When you have a powerful tool, you don’t need to avoid it. Rather, you need to learn how to wield it well. TestProject has a powerful test recorder built right into it that makes it easy to create and record tests. This is great for certain kinds of testing, but what do you do when you want to wield this powerful tool with maximum effect? ⚑ In order to do that, you will need to interact with it in more direct ways than you can via the test recorder. This is where the TestProject Software Development Kits (SDKs) come into the forefront.

TestProject has Java, C# and Python open sourced SDKs (and JavaScript is coming right around the corner!). In this article, we will look at how you can get started using the TestProject Java OpenSDK. We will get you from zero to a fully functioning test in just a few steps πŸš€

Getting Started with TestProject Java OpenSDK

  1. Pre-requisites
  2. Installing the OpenSDK with Maven
  3. Installing the OpenSDK with Gradle
  4. Creating Tests with the OpenSDK
  5. Development Token
  6. Running a Test with the OpenSDK
  7. Viewing Test Reports

Pre-Requisites

The configuration page should look something like this:
Maven Config Page
Now that you have a Maven project, you will need to add the TestProject SDK as a dependency in the pom.xml file for your project. If you expand the project in the navigation tree in Eclipse, you will see the pom.xml file and you can double click to open it in for editing.
β€ŒYou will need to add a <dependencies> section to the file and then add the TestProject dependency:
<dependencies>
  <dependency>
    <groupId>io.testproject</groupId>
    <artifactId>java-sdk</artifactId>
    <version>0.65.3-RELEASE</version>
  </dependency>
</dependencies>

Make sure to set the <version> to the name of the latest TestProject SDK version. You can find the list of versions in the Maven repository here.β€Œ

If you prefer to build with a Gradle project instead, you can do that as well. If you have already installed the SDK with Maven, skip ahead to the next section. As with using Maven, let’s look at how to set up a project in Eclipse. Use the following steps to setup a Grade project in Eclipse:β€Œ
Once you’ve done this, find the build.gradle file in your project and add the following into the dependencies section.
implementation 'io.testproject:java-sdk:0.63.4-RELEASE'
❗ Note that the Gradle addon usually comes installed with Eclipse. If you are using a different IDE you might need to install Gradle which you can do from here. If Eclipse did not install it, you can go the Help>Ecliple Marketplace and search for gradle and install the Buildship Gradle Integration addon.

Creating a New Test

You can create a new test in Eclipse by going to the src/tests/java folder and then right clicking and selecting Package from the New menu as shown in the following image:
Creating Tests with the OpenSDK
β€Œ
This creates a test that will go to the TestProject example page, login and check that the logout button is there, but you aren’t quite ready to run the test yet. You will need to first configure a development token before you can run this example πŸ‘‡
In order to run tests, the TestProject Agent on your machine needs to be able to communicate with the TestProject platform. This communication channel needs to be authorized with a development token. You can get a dev token from the sdk/integrations page in TestProject. There are a couple of ways to specify the development token, but for the purposes of this tutorial, we will look at how to explicitly provide it to your test. You can do this when calling the driver constructor. Simply pass in your token as an argument to the constructor. Instead of just setting the ChromeOptions() when creating a new driver, you can also specify the token as a string. If you wanted to take this approach, Line 10 in the example above would be replaced with something like this:
ChromeDriver driver = new ChromeDriver("your token", new ChromeOptions());
Once you have specified your development token in this way, you should be able to run the test! πŸƒβ€β™‚οΈ
In order to run the tests in Eclipse, all you need to do is click the green run button on the toolbar. When you do that, a chrome browser will load and it will open the https://example.testproject.io/web page and do the actions indicated in the test. Once it is done you should see the words Test Passed printed in the console in Eclipse. Don’t worry if there are a few warnings in there. As long as you see Test Passed printed, everything should be ok. If the test does not run, check the Console tab in Eclipse. You may see an exception in there saying that it could not connect to the Agent. You will need to start up the Agent on your local machine before you can run the tests.
β€ŒAnd there you have it! You have created and run a test with the TestProject Java OpenSDK. That was pretty easy, wasn’t it? 😎

Viewing Test Reports

By default, the TestProject OpenSDK automatically reports all driver commands and their results to the TestProject Hybrid Cloud. This allows you to see beautifully designed reports and statistics in the TestProject app dashboards. If you login to the TestProject App and mouse over the Reports menu item, you should see the SDK run that you just did listed there.
Screenshot of Recent Reports
β€ŒYou can click on this to go to the report for this test run. This will show you all the details of the run. You can explore it with all of the built in reporting features. You can see which steps might have passed or failed along with summary reports and all other features of the TestProject reports.
TestProject Test Reports
And with that you’ve done it! You created and run a test using the TestProject Java OpenSDK! You are well on your way to wielding a powerful tool with skill and grace. There is, of course, a lot more to learn with this. You can check out the documentation to get more details on using this, or you can go directly to the open source GitHub repository to see more details and examples of how to use this OpenSDK.

About the author

Dave Westerveld

Dave Westerveld is an experienced tester who has been involved in various aspects of the testing role. As a strong exploratory tester, he has learned how to leverage many different tools to enhance his testing powers. He has also been involved in many automation projects including building out new automation frameworks. In addition he has helped transition several large and expensive automation suites into lighter weight, higher value systems. A speaker at several conferences, Dave also blogs about his thoughts and experiences at offbeattesting.com

Leave a Reply

FacebookLinkedInTwitterEmail