# TestNG Project Setup

#### 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.

{% hint style="info" %}
Gradle based projects are not currently supported .
{% endhint %}

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");
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloudbeat.io/references/projects/java-+-testng-project.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
