I am running several selenium automated tests using Maven. When I'm debugging in Eclipse, I usually just right click on testing.xml and Run As > TestNG Suite. But running in Jenkins needs to be ran using mvn test
. But when I run that, I get several errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project ecom: Compilation failure: Compilation failure:
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[15,43] package com.company.automation.ecom.pages does not exist
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[16,43] package com.company.automation.ecom.pages does not exist
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[110,13] cannot find symbol
[ERROR] symbol: class Header
[ERROR] location: class com.company.automation.ecom.HelperMethods
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[110,62] cannot find symbol
[ERROR] symbol: class Header
[ERROR] location: class com.company.automation.ecom.HelperMethods
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[113,9] cannot find symbol
[ERROR] symbol: class SignIn
[ERROR] location: class com.company.automation.ecom.HelperMethods
[ERROR] /Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[113,58] cannot find symbol
[ERROR] symbol: class SignIn
[ERROR] location: class com.company.automation.ecom.HelperMethods
I know the files are present, when I run as TestNG suite everything works with no issues. Additionally, when I run which java -version
I get this:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
I know it's a configuration issue somewhere, but I don't know enough about maven/java configuration to figure it out. The files that Maven is telling me are gone are my files, and they are absolutely present. Here is 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.kirklands.automation.ecom.retry.MyTestListenerAdapter</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.kirklands.automation</groupId>
<artifactId>ecom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ecom</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
Project Structure:
src/main/java
{package com.company.automation.ecom}
CreditCard.java
HelperMethods.java
src/test/java
{package com.company.automation.ecom.pages}
Header.java
SignIn.Java
(etc...)
{package com.company.automation.ecom.tests}
HeaderTests.java
(etc...)
If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local . m2 repository to see if it was downloaded correctly.
groupId – a unique base name of the company or group that created the project. artifactId – a unique name of the project. version – a version of the project.
groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org. apache. maven.
Looks like your issue appears due to fact that you trying to access from your:
src/main/java
Test sources - which are located:
src/test/java
Here is the exact snippet of the log you posted:
/Users/kroe761/Documents/workspace/ecom/src/main/java/com/company/automation/ecom/HelperMethods.java:[15,43] package com.company.automation.ecom.pages does not exist
It will work from another side: if you will use your sources (src/main/java
) from test scope (src/test/java
).
Maven has his own lifecycle.
It has a strict consequence:
compile
- compile the source code of the projecttest
- test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployedAnd during compile
you can compile only your sources. However, it depends on your tests (pages package), which can't be compiled at this moment, because it will compile only at test
phase.
Thus compilation fails.
For solving try to change your project structure, a little bit:
src/main/java
{package com.company.automation.ecom}
CreditCard.java
HelperMethods.java
{package com.company.automation.ecom.pages}
Header.java
SignIn.Java
(etc...)
src/test/java
{package com.company.automation.ecom.tests}
HeaderTests.java
And your tests should use sources (core & pages) without any problem.
You need to run maven clean install
command first.
That command will compile your missing
package and it will even run the tests.
UPDATE: You should change your com.company.automation.ecom.pages
package to your src/main/java
folder. so that it can be compiled in maven compile
phase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With