logo logo

TestProject OpenSDK with Cucumber, TestNG and ExtentReport

main post image

In this post, we will discuss working with all new TestProject OpenSDK to write native Selenium code of an existing code which is powered by the following:

Note

The native Selenium code which we will be using in this post is available in GitHub.

Native Selenium Code

The native Selenium code that we have as mentioned before is written in BDD format using Cucumber and running the test via the test runner of TestNG. The structure of the code looks pretty much like a regular test code, as below:

Native Selenium Code Structure

The code also uses Selenium Page Object Model, TestNG Listeners, and generates reports via Extent reporting. Well, this whole code uses Native Selenium Webdriver to perform UI testing and in fact, with this “usual” approach, we have the following things to be taken care of as a tester 🤯:

  • Maintain ChromeDriver/Gheckodriver/EdgeDriver, etc with latest versions.
  • Write your own code for reporting (like extent reporting in this case).
  • Maintain browser drivers in CI/CD deployment machines.

Using TestProject’s OpenSDK

Using TestProject‘s OpenSDK, now things are much simpler and it addresses the above pain points along with a lot of fascinating features! ✨

  • Automatic test reports in HTML/PDF format (including screenshots).
  • Collaborative reporting dashboards with execution history and RESTful API support.
  • Always up-to-date with the latest and stable Selenium driver version.
  • A simplified, familiar syntax for both web and mobile applications.
  • Complete test runner capabilities for both local and remote executions, anywhere.
  • Cross-platform support for Mac, Windows, Linux and Docker.
  • Ability to store and execute tests locally on any source control tool, such as Git.

Migrating Native code to TestProject OpenSDK

The first and foremost operation before beginning with our code migration is to get the OpenSDK itself. Since this is a Java Maven project, the reference we are going to set in the POM.xml file is going to look something like this:

<dependency>
    <groupId>io.testproject</groupId>
    <artifactId>java-sdk</artifactId>
    <version>0.63.2-RELEASE</version>
</dependency>

Next, the only code change we need to make in our native selenium code to use TestProject’s OpenSDK is this:

Native code

//Chrome driver - Using Native Selenium WebDriver
System.setProperty("webdriver.chrome.driver", "/Users/ChromeDriver/chromedriver");
WebDriver driver = new ChromeDriver();

TestProject OpenSDK

WebDriver driver = new DriverBuilder<ChromeDriver>(new ChromeOptions())
        // Get Project Name from environment variable - CI/CD
        .withProjectName(System.getenv("BuildNumber"))
        // Get Job Name as Release Name from environment variable - CI/CD
        .withJobName(System.getenv("ReleaseName"))
        // Get TestProject Auth Token from environment variable - CI/CD
        .withToken(System.getenv("token"))
        .build(ChromeDriver.class);

As you can see from the above code, the DriverBuilder sets the following parameters to invoke TestProject agent running in the target machine:

  • Project Name – Which can be any name, but since TestProject’s OpenSDK is going to automatically create the reports, it’s better to set a unique name as the project name. In this case, we are using CI/CD environment variables to set the project name.
  • Job Name – Which can be any name as well, but we are setting the release number as job name from CI/CD environment variable.
  • Token – This is a super-secret token to authenticate our TestProject agent with the TestProject platform and MUST need to come from CI/CD environment variable.

With this, we can now run our test and get the automatic test report generated in the TestProject Platform as shown below

Here is the complete migrated project with TestProject’s OpenSDK in GitHub.

This entire tutorial is also available in a video tutorial format for you to enjoy 😉👇

Users interested to try TestProject’s new OpenSDK can follow these steps to get started:

  1. Create a free TestProject account
  2. Download and install the TestProject agent
  3. Install the SDK from your favorite package manager:
    1. Java – Maven
    2. C# – NuGet
    3. Python – PyPI
  4. Explore our SDK documentation to understand available functions:
  5. Create your automated tests! 🤩

Go ahead and share your feedback in the comments below – Have you tried TestProject’s OpenSDK yet? 

Avatar

About the author

Karthik KK

I am Karthik K.K. I do consulting, blogging, and researching on various tools and technologies which inspire my interest. I have been into Software Automation Testing for over 14 years now and my interest in learning new stuff which enables automation has never been compromised.

Due to my passion in automation testing I got fully exposed to tools and languages like

Desktop & Web : QTP, Selenium, Specflow, VS Coded UI, Ranorex ,Test Complete and Cucumber
Mobile : Appium, Robotium,Calabash, Espresso, Selendroid
Languages : C#, Java, Ruby, Powershell, Javascript, VBScript
Cloud Tools : Azure, Dockers
Misc Tools: Mockito, Rest-assured, Bound-Box,FluentAutomation
Interested in: MVC, Entity framework, LINQ, Fakes, Distributed deployment, SAAS

Follow on YouTube – https://youtube.com/executeautomation
Follow on Twitter – https://twitter.com/executeauto
Follow on linkedIn – https://www.linkedin.com/company/executeautomation/
Follow on Facebook – https://www.facebook.com/executeautomation/

 

Join TestProject Community

Get full access to the world's first cloud-based, open source friendly testing community. Enjoy TestProject's end-to-end test automation Platform, Forum, Blog and Docs - All for FREE.

Join Us Now  

Leave a Reply

popup image

Selenium for Teams

Sharing and distributing Selenium tests has never been so easy! With TestProject's FREE Selenium based platform, you can finally create awesome tests with the freedom to collaborate with your team effortlessly.
Sign Up Now right arrow
FacebookLinkedInTwitterEmail