# Java JUnit

## Installation

First we need to include the Cloudbeat dependencies inside our pom.xml:

```
<dependency>
    <groupId>io.cloudbeat</groupId>
    <artifactId>cb-kit-selenium4</artifactId>
    <version>LATEST</version>
</dependency>
<dependency>
    <groupId>io.cloudbeat</groupId>
    <artifactId>cb-kit-common</artifactId>
    <version>LATEST</version>
</dependency>
<dependency>
    <groupId>io.cloudbeat</groupId>
    <artifactId>cb-kit-junit5</artifactId>
    <version>LATEST</version>
</dependency>
```

If you want to use a specific version, include it inside properties:

```
<cloudbeat.version>1.0.11</cloudbeat.version>
```

Then instead of LATEST, use cloudbeat.version

```xml
<dependency>
    <groupId>io.cloudbeat</groupId>
    <artifactId>cb-kit-selenium4</artifactId>
    <version>${cloudbeat.version}</version>
</dependency>
```

{% hint style="info" %}
For on-prem, we can install the Cloudbeat kit using files stored locally
{% endhint %}

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FrdSh378V0lo9egSQCEpg%2Fimage.png?alt=media&#x26;token=4fb6eb6b-3185-440b-b1c9-17a49e5a70f9" alt=""><figcaption></figcaption></figure>

We need to specify the version of the jar files:

```
<cloudbeat.version>1.0.11-SNAPSHOT</cloudbeat.version>
```

Then install the dependencies:

```
mvn clean install
```

## Implementing Cloudbeat Reporting

We need to start by importing the Cloudbeat step extension inside our methods file:

```
import io.cloudbeat.common.annotation.CbStep;
```

Then, add CbStep above your method:

```
@CbStep("Open Base URL")
public void open() {
    driver.get(baseUrl);
}
```

Import CloudBeat Junit extension in our tests:

```
import io.cloudbeat.junit.CbJunitExtension;
```

Extend Cloudbeat JUnit extension class:

```
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith({ CbJunitExtension.class })
public class LoginTest {
    private WebDriver driver;
    private LoginPage loginPage;

    @BeforeEach
    public void setUp() {
        driver = DriverManager.getDriver();
        loginPage = new LoginPage(driver);
    }
}
```

Wrap your test steps using startStep & endLastStep:

```
@Test
@DisplayName("Standard User Login Behaviour")
public void standardUserLoginBehaviour() {
    CbJunitExtension.startStep("Open Main Page");
    loginPage.open();
    loginPage.assertPageOpen();
    CbJunitExtension.endLastStep();
}
```

## Creating a Java JUnit project in Cloudbeat

Under Manage, open projects and click on add project, choose a name and select Java JUnit.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FCHOuR6lqSqhPokCdxLPj%2Fimage.png?alt=media&#x26;token=4c7a92c3-3959-4233-bb55-d99596d73862" alt=""><figcaption></figcaption></figure>

### Connect your test project to CloudBeat

CloudBeat is a platform for both test reporting and execution. To use CloudBeat, you must upload your test project files to execute tests and access report analytics. You can upload your project as a Zip file, or CloudBeat can automatically synchronize with your test project Git repository.

### Git synchronization

In order to sync your test project from git, select Git Integration and paste the url to your repository.

You can use your username and password, or with an access token.

### Uploading manually&#x20;

If you want to upload a local test project, you need to zip your project folder, then select upload.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FuZTqzx56QXyIUw7ghVYb%2Fimage.png?alt=media&#x26;token=3a87c216-e002-4912-afc1-f57b3645e16b" alt=""><figcaption></figcaption></figure>

## Running your tests

Under Testing, go to cases and you will see all your tests. Under each test you will find multiple options such as choosing who will receive notifications for this test, schedule when the test will run, choosing environments and parameters and the browser it will run on.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FN3TRiQrGj9oN8XWkAKCU%2Fimage.png?alt=media&#x26;token=4e6a2f5a-5913-4110-ab7f-9e12624000d4" alt=""><figcaption></figcaption></figure>

Click on Run Now to execute the test, then the results will appear under the Results tab.

To expend the results and see all the steps, data, logs and errors, click on case summary:

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FHsB9RqMTMntHk5IXAQQN%2Fimage.png?alt=media&#x26;token=4b0e3fef-efa6-4d74-a70d-cc4bbe3afe48" alt=""><figcaption></figcaption></figure>

### Running multiple tests

Under Testing, go to Suites, right-click on Dashboard to create a new suite, or start by creating a new folder then right-click on it and choose Create suites - web.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FWJxU7WfrSsO60CXixcaQ%2Fimage.png?alt=media&#x26;token=410c53aa-b3b5-4d44-8a8c-4f682d349a65" alt=""><figcaption></figcaption></figure>

Similarly to single tests, select your browser and other configurations:

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fe2y4Fw3A3XIMEB5CPWUy%2Fimage.png?alt=media&#x26;token=4fd192a0-a9a3-401f-9022-8994c5a98a6b" alt=""><figcaption></figcaption></figure>

Select your desired tests:

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2FRKv9fBGUrHPVcKRZDsZ7%2Fimage.png?alt=media&#x26;token=c44fb774-f0cd-4bc2-abc7-782e36a86d41" alt=""><figcaption></figcaption></figure>

Click on Save Changes and then Run Now. The results will wait for you under the results tab.

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fntq0H1QtFiczYW4AOW5g%2Fimage.png?alt=media&#x26;token=82e23a15-28bd-4e8b-884f-2129babd4138" alt=""><figcaption></figcaption></figure>
