TestNG Project Setup

Description on how to prepare a TestNG project to be used in CloudBeat

Plugin Integration

Add the cb-framework-plugin-testng plugin to your project. For Maven base projects, this requires adding plugin repository and the plugin dependency.

Gradle based projects are not currently supported .

First add the repository to your pom.xml:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
  </repositories>

And add the plugin dependency itself:

<dependency>
    <groupId>com.github.oxygenhq</groupId>
    <artifactId>cb-framework-plugin-testng</artifactId>
    <version>0.10.1</version>
</dependency>

In addition, if running multiple parallel tests is required, maven surefire plugin with version equal or higher than 2.22.0 should be added to the plugins section:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.0</version>
    </plugin>
  </plugins>
</build>

Code Level Integration

Add plugin listener to your test class and extend the test class from CbTestNg

@Listeners(io.cloudbeat.testng.Plugin.class)
public class SeleniumTest extends CbTestNg  {
    
}

Working with Selenium

When using Selenium it might be beneficiary to be able to take browser screenshots in case of failures.

Providing WebDriver instance

import io.cloudbeat.testng.CbTestNg;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SeleniumTest extends CbTestNg {
    @BeforeClass
    public static void setUp() {
        DesiredCapabilities capabilities = ... // User capabilities                

        // For default web browser initialization based on CloudBeat capabilities
        setupWebDriver();
                
        // For default web browser initialization based on user capabilities and CloudBeat capabilities
        initWebDriver(capabilities);
    
        // For default mobile driver initialization based on CloudBeat capabilities
        setupMobDriver();
        
        // For default web browser initialization based on user capabilities and CloudBeat capabilities
        initMobDriver(capabilities);
        
        //Or just setup your own driver
        WebDriver driver = ... // Your driver initialization
        setupDriver(driver); // Set up driver        

        this.driver; // Created driver
    }
}

Custom steps

In order for CloudBeat to produce nicer repots, startStep and endStep methods can be used to designate test actions

import org.testng.annotations.Test;

public class SeleniumTest extends CbTestNg {
    
    @Test
    public void Test1() {
       startStep("Step");
       startStep("Inner step");
       endStep("Inner step");
       endStep("Step");
    }
}

Last updated