Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions java-reporter-testng-selenide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Java reporter integration with TestNG

## Overview

This simple demo shows how Testomat.io Java reporter works in your project.

## Installation

1. Clone the repository

```sh
git clone https://github.com/testomatio/examples.git
```
2. Change the directory

```sh
cd java-reporter-testng
```
3. Install dependencies with test skip

```sh
mvn clean install -DskipTests
```


## Configurations

**By default, the library runs with properties default values except `testomatio.api.key` and `testomatio.listening`**

![properties img](img/properties.png)

Add your project API key to the `testomatio.properties` file ad `testomatio.api.key`

## Configure TestNG Before Running

Before running tests, make sure your TestNG suites are configured in the testng.xml file.
Runs test methods in parallel using 7 threads simultaneously.
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="UI Tests" parallel="methods" thread-count="7">

<test name="Smoke Tests">
<classes>
<class name="tests.InventoryTest"/>
<class name="tests.LoginTest"/>
<class name="tests.ProductDetailsTest"/>
</classes>
</test>

</suite>
```

## Run

Run tests with

```bash
mvn test -Dtestomatio.api.key=tstmt_key #if you did not provide it in the `testomatio.properties` file
```

where `tstmt_key` is your Testomat.io key from a particular project.
60 changes: 60 additions & 0 deletions java-reporter-testng-selenide/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.testomat</groupId>
<artifactId>java-reporter-testng-selenide</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenide.version>7.16.1</selenide.version>
<testng.version>7.11.0</testng.version>
<allure.version>2.29.1</allure.version>
</properties>

<dependencies>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>${selenide.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-testng</artifactId>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.testomat.config;

public final class Urls {

public static final String BASE_URL = "https://www.saucedemo.com/";
public static final String INVENTORY_URL = BASE_URL + "inventory.html";
private static final String INVENTORY_ITEM_PATTERN = BASE_URL + INVENTORY_URL + "?id=%s";

private Urls() {
}

public static String inventoryItemUrl(int id) {
return String.format(INVENTORY_ITEM_PATTERN, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.testomat.data;

public final class Users {

public static final String PASSWORD =
"secret_sauce";

public static final String STANDARD_USER =
"standard_user";

public static final String LOCKED_USER =
"locked_out_user";

public static final String PROBLEM_USER =
"problem_user";

public static final String PERFORMANCE_USER =
"performance_glitch_user";

public static final String ERROR_USER =
"error_user";

public static final String VISUAL_USER =
"visual_user";

private Users() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.testomat.pages;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;

public class CartPage {

private final ElementsCollection cartItems =
$$(".cart_item");

private final SelenideElement cartLink =
$(".shopping_cart_link");

public CartPage verifyItemsExist() {
cartItems.shouldHave(sizeGreaterThan(0));

return this;
}

public int getItemsCount() {
return cartItems.size();
}

public void cartLinkShouldVisible() {
cartLink.shouldBe(visible);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package io.testomat.pages;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;

import java.util.List;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.*;

public class InventoryPage {

private final SelenideElement title =
$(".title");

private final ElementsCollection inventoryItems =
$$(".inventory_item");

private final ElementsCollection itemNames =
$$(".inventory_item_name");

private final ElementsCollection itemPrices =
$$(".inventory_item_price");

private final SelenideElement cartButton =
$(".shopping_cart_link");

private final SelenideElement sortDropdown =
$(".product_sort_container");

private final ElementsCollection addToCartButtons =
$$("button[id^='add-to-cart']");

private final ElementsCollection removeButtons =
$$("button[id^='remove']");

private final SelenideElement burgerMenu =
$("#react-burger-menu-btn");

private final SelenideElement logoutLink =
$("#logout_sidebar_link");

private final ElementsCollection inventoryItemsImgs =
$$(".inventory_item_img img");

private final SelenideElement inventoryDetailsImgs =
$(".inventory_details_img img");

private final SelenideElement inventoryDetailsName =
$(".inventory_details_name");

private final SelenideElement inventoryList =
$(".inventory_list");

public InventoryPage verifyPageLoaded() {
title.shouldHave(text("Products"));
inventoryItems.shouldHave(sizeGreaterThan(0));

return this;
}

public int getItemsCount() {

return inventoryItems.size();
}

public List<String> getItemNames() {

return itemNames.texts();
}

public List<String> getItemPrices() {
return itemPrices.texts();
}

public InventoryPage sortBy(String value) {

sortDropdown.selectOptionByValue(value);

return this;
}

public InventoryPage addFirstItemToCart() {
addToCartButtons.first().click();

return this;
}

public InventoryPage removeFirstItemFromCart() {

removeButtons.first().click();

return this;
}

public CartPage openCart() {

cartButton.click();

return new CartPage();
}

public LoginPage logout() {

burgerMenu.click();

logoutLink.shouldBe(visible).click();

return new LoginPage();
}

public ElementsCollection getInventoryItemsImgs() {
return inventoryItemsImgs;
}

public SelenideElement getInventoryDetailsImgs() {
return inventoryDetailsImgs;
}

public SelenideElement getInventoryDetailsName() {
return inventoryDetailsName;
}

public void inventoryListShouldVisible() {
inventoryList.shouldBe(visible);
}

public ElementsCollection getCartButtons() {
return addToCartButtons;
}

public ElementsCollection getItemPriceElements() {
return itemPrices;
}
}
Loading
Loading