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:
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:
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:
//Chrome driver - Using Native Selenium WebDriver System.setProperty("webdriver.chrome.driver", "/Users/ChromeDriver/chromedriver"); WebDriver driver = new ChromeDriver();
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:
- Create a free TestProject account
- Download and install the TestProject agent
- Install the SDK from your favorite package manager:
- Explore our SDK documentation to understand available functions:
- Create your automated tests! 🤩
Go ahead and share your feedback in the comments below – Have you tried TestProject’s OpenSDK yet?