I started a Selenium + JUnit 4 Test from the two getting started documents. I am on Maven3, Java17 and IntelliJ IDEA w/ Arch Linux.
My pom.xml is as follows:
<?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.leder</groupId>
<artifactId>HelloSelenium</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>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.20.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>test/main/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My Main.java is as follows:
package org.leder;
import dev.failsafe.internal.util.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static final String ALDI_ONLINESHOP_GUTES_FÜR_ALLE = "ALDI ONLINESHOP - Gutes für alle";
@Test
public void loginLogoutTest() {
WebDriver driver = new ChromeDriver();
driver.get("https://aldi-onlineshop.de");
String title = driver.getTitle();
System.out.println(title);
Assert.isTrue(title.equals(ALDI_ONLINESHOP_GUTES_FÜR_ALLE), "Title is valid");
WebElement submitButton = driver.findElement(By.cssSelector("[class='sc-jsJBEP.iXSECa']"));
submitButton.click();
WebElement loginMenu = driver.findElement(By.cssSelector("[data-attr-value='My Account']"));
loginMenu.click();
driver.quit();
}
}
I did the following already:
mvn clean test
from the command lineTo no avail!
I get no error message, simply a successful maven output "BUILD SUCCESS".
I was expecting to see the chromium browser openend and test to be executed.
Most probably, Maven does not recognize your test class and does not run the test at all. You can check this in the Maven console output.
Try renaming it using some pattern which surefire plugin uses. E.g. MainTest
See docs: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html