I hope everyone is going well, i have following 2 classes under src/test/java/com.selenium.test:
AppTest.java:
package com.selenium.test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class AppTest {
WebDriver driver;
//Before function
@Before
public void Begin()
{
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@After
public void End()
{
driver.quit();
}
}
and the second class Projectest.java:
package com.selenium.test;
import org.junit.Test;
public class Apptest2 extends AppTest{
@Test
public void testWebsite(){
System.out.println("Starting test " new Object({}.getClass().getEnclosingMethod().getName());
driver.get("http://www.google.com");
}
in cmd i access to the project folder and i write this command "mvn test", this is the output that i have:
C:\Users\user\eclipse-workspace\SeleniumTest>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.selenium:SeleniumTest >----------------------
[INFO] Building SeleniumTest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SeleniumTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is
platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ SeleniumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SeleniumTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is
platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ SeleniumTest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ SeleniumTest ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.106 s
[INFO] Finished at: 2022-04-06T21:43:07 02:00
[INFO] ------------------------------------------------------------------------
this is also my "pom.xml" file:
<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 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.selenium</groupId>
<artifactId>SeleniumTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.4.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</reporting>
The problem is that when i put the @test code in the first class like this:
package com.selenium.test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class AppTest {
WebDriver driver;
//Before function
@Before
public void Begin()
{
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test
public void testWebsite(){
System.out.println("Starting test " new Object(){}.getClass().getEnclosingMethod().getName());
driver.get("http://www.google.com");
}
@After
public void End()
{
driver.quit();
}
}
when i write the command mvn test, i have this output:
-------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
but when i wrote the @test in the second class as shown above, i have this resultat:
-------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
I didn't understand where the problem is, can anyone please help me. Thank you in advance
CodePudding user response:
perhaps you need to run "mvn clean compile" first (usally I run "mvn clean install' all the time). I guess problem is that your new class with new @Test annotation was not recompiled. I see that
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ SeleniumTest
[INFO] Nothing to compile - all classes are up to date
CodePudding user response:
First src/test/java/com.selenium.test
this is not a correct package src/test/java/com/selenium/test
second the name Apptest2
does not follow naming convention. It must end with *Test.java
and pay attention to case so change it into AppTwoTest
... instead ... And you should rename your AppTest
because it's not a test itself it's only a base class for other tests so for example AppTestBase