1

I use this Maven configuration in order to execute TestNG collection of tests:

<?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>org.example</groupId>
    <artifactId>Automation</artifactId>
    <version>1.1</version>

    <repositories>
        <repository>
            <id>Central Repository</id>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
        <repository>
            <id>google-api-services</id>
            <url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>repository.spring.release</id>
            <name>Spring GA Repository</name>
            <url>https://repo.spring.io/plugins-release/</url>
        </pluginRepository>
    </pluginRepositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version> <!-- There is a bug into the latest version 7.4.0. Wait for next stable version to be released before upgrade. -->
            <scope>test</scope>
        </dependency>
        <!-- Selenium dependencies -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>2.52.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.21.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.22</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

When I compile the project or run clean test tests are not executed. Do you know how I can configure the tests to be executed?

EDIT. Example for test:

package org.mobile.login;

import org.automation.utils.BrowserDriver;
import org.automation.utils.jaxb.Environment;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Timeout;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.utils.LoginProcess;

import java.util.concurrent.TimeUnit;

import static org.automation.utils.Constants.*;

public class ReloadPageTest extends LoginProcess {

    private Environment env;

    @BeforeSuite
    public void setup() throws Exception {
        env = setupEnvironment();
    }

    @Tag("description")
    @Order(1)
    @Test(testName = "52333 Mobile Web - Reload a page to refresh it", groups = { "multiple_runs" })
    @Timeout(value = 80, unit = TimeUnit.SECONDS)
    public void Mobile_Web_Reload_a_page_to_refresh_it_52333() throws InterruptedException
    {
        WebDriver driver = new BrowserDriver().initDriver();

        // Navigate to Test Environment
        driver.get(env.getConfiguration().getUrl());
        .....
}
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • Are your [test sources in `src/test/java` and the classes named `*Test.java`](https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html#Configuring_TestNG)? – Gerold Broser Nov 19 '21 at 22:36
  • Tests are always executed by default, unless you add `--skip-tests` to the command line. Make sure you are using the right annotations from the right packages as well as what Gerold said. – Guillaume F. Nov 19 '21 at 22:39
  • Which framework do you use? TestNG? Or JUnit Jupiter? – khmarbaise Nov 19 '21 at 22:52
  • I use TestNG as you can see from the dependencies. – Peter Penzov Nov 20 '21 at 00:37
  • I see dependencies for testng as well as for JUnit Jupiter (junit-jupiter-engine) which is the problem here... you have to decide which one you use... – khmarbaise Nov 21 '21 at 16:07
  • I want to use TestNG with some JUnit functionalities. How I can fix this proejct? – Peter Penzov Nov 21 '21 at 16:26
  • No, please decide! ;) ..and please also provide (at least) a test. – xerx593 Nov 22 '21 at 17:26
  • First why using TestNG? What specific feature do you use of TestNG which JUnit Jupiter doesn't have? – khmarbaise Nov 22 '21 at 21:19
  • I use TestNG because I can group tests. – Peter Penzov Nov 22 '21 at 23:22
  • I added basic example for test. – Peter Penzov Nov 22 '21 at 23:24
  • This can be done via Junit Jupiter via Tag annotation furthermore you can use nested classes to categorize tests as well. Apart from that your test example show the usage of TestNG annotation and Junit Jupiter annotation within a single test which will not really work...and I suppose that's exactly the reason why your tests are not correctly running. – khmarbaise Nov 23 '21 at 07:00

1 Answers1

1

Use maven-surefire-plugin version 2.22.2 instead of 3.0.0-M5:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>

When changed, the test get executed.

D-FENS
  • 1,438
  • 8
  • 21