Passing environment variables to config.properties file via maven - java

I have a java config.properties file which reads as follows:
mosURL=${mosURL}
mopURL=${mopURL}
I am wanting to pass in the values to ${mosURL} and ${mopURL} when I initiate my build with Maven. These properties are environment specific URL's.
My POM file is below and you can see I have set up property profiles for each environment. (EDIT. POM Example now contains suggestted changes mentioned in Anser below.) I have set env-uat as my default by having <activeByDefault>true</activeByDefault> present in the env-uat section.
But when I run mvn test everyting starts off as expected but when the test fails when attempting to use the URL and I get an error to inform me that no URL is present. So somewhere the link of passing from pom.xml into config.properties isnt working.
I can run "mvn help:active-profiles" from command and I can see the following:
The following profiles are active:
- env-uat (source: com.mycompany.app:my-app:1)
Is there a missing link that I dont know about?
EDIT: I can run mvn resources:resources and when I look at the generated .properties file in the target/classes folder I can see that all the properties are listed correctly as I would expect. But they are not being passed into my java propeties.config file when I run 'mvn test'.
I have started reading about Spring and wondering if I need to configure something with Spring to get these values form Maven into my Java file? The Maven population of the properties look fine.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<mosURL>https://mos-uat.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-uat.mywebsiteurlishere.com/</mopURL>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xpath</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.5.2.jre9-preview</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<exclude>**/*TPOS_Run_All.java</exclude>
</includes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>env-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<mosURL>https://mos-dev.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-dev.mywebsiteurlishere.com/</mopURL>
</properties>
</profile>
<profile>
<id>env-uat</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<mosURL>https://mos-uat.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-uat.mywebsiteurlishere.com/</mopURL>
</properties>
</profile>
</profiles>
</project>

The problem here should be connected to the "default" value of your variables.
Try adding the properties in the global properties declaration, on the top of your pom
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
//add them here aswell
<mosURL>https://mos-dev.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-dev.mywebsiteurlishere.com/</mopURL>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
I have the same configuration as yours, and the only difference seems to be this one.
Hope this helps

I'm posting this as an answer in case it's useful to anyone who may stumble across this in future.
After a discussion with the CI developer we decided that holding system specific values in my framework was the wrong approach. The property values are best held outside of Maven and let the CI environment pass them in on build. So I stripped out all environment specific properties from my POM.
I then created a separate class with static return methods to hold each of my config values such as below:
public class Config {
public static String getUrl1() {
return System.getProperty("url1");
}
public static String getUrl2() {
return System.getProperty("url2");
}
}
My code that would read these properties would be as simple as:
String strUrl1 = Config.getUrl1();
I would pass in the actual value from Maven comand such as:
mvn clean test -Durl1=https://url1goeshere.com/ -Durl2=https://url2goeshere
So it is then up to our CI developers to hold and pass in my specific variables. We are holding the environment values in Octopus which will then pass it to placeholders in TeamCity that will then construct and pass a command to Maven. So when we deploy to Dev through Octopus it will know to pass in the Dev parameters and so on for other environments.

Related

How to build standalone executable cucumber jar file?

I want to create a executable jar file so anyone can run it from their computer with least install require components.
I found several tutorial but none of them a work.
When I execute jar file I've built they are return error like:
Error: Could not find or load main class fully.qualified.MainClass
Caused by: java.lang.ClassNotFoundException: fully.qualified.MainClass
OR like this:
Error: Could not find or load main class io.cucumber.core.cli.Main
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.cli.Main
My project run from Intellij with no problem.
Here my project structure
https://i.stack.imgur.com/NcQzf.png
And my pom.xml
<?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>com.example</groupId>
<artifactId>CucumberSelenium</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>7.6.0</cucumber.version>
<selenium.version>4.8.0</selenium.version>
<webdrivermanager.version>5.2.1</webdrivermanager.version>
<junit.jupiter.version>5.9.0</junit.jupiter.version>
<apache.common.version>2.4</apache.common.version>
<projectlombok.version>1.18.24</projectlombok.version>
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M7</maven.surefire.plugin.version>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>${cucumber.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Platform -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- Web Driver Manager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
</dependency>
<!-- Apache Common -->
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>${apache.common.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${projectlombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<properties>
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
<debugForkedProcess>true</debugForkedProcess>
<forkCount>0</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.cucumber.core.cli.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I've run mvn clean compile assembly:single, it's output a CucumberSelenium-1.0-SNAPSHOT-jar-with-dependencies.jar file, but it wont runs.
I just came across a similar issue and, despite trying the ubiquitous
java -cp . org.example.Main
(while on current directory being where the Main.class is), I kept getting this dreaded
"Error: Could not find or load main class"
I eventually resorted to comparing the actual command with parameters invoked by IntelliJ (on IntelliJ IDEA's debug log) with mine, and discovered that the following solves the issue:
java -cp C:\Users\WebViwer\IdeaProjects\MyProj\target\classes org.example.Main
I am guessing that once the fully qualified class name is specified, the current directory (where the class resides) is no longer valid as a classpath: Only the top level classes directory should be specified (in this org.example, 2 levels up).
You have a a few problems going on.
The maven-assembly-plugin should not be a in the dependencies section. It is not a dependency used by the runtime code of your project.
Your step definitions, feature files and glue code located in src/test are not included in the jar file build by the assembly plugin.
Your test scoped dependencies will also not be included by the assembly plugin either.
You must configure the containerDescriptorHandler of the assembly plugin with metaInf-services or the plugin will not merge files in META-INF/services correctly.
You can verify most of these by opening the generated jar file (it's a .zip file in disguise).
My project run from Intellij with no problem.
When running tests in Intelij you are using the test scope, the jar file only includes runtime scoped code.
For a more comparable test you must create a new run configuration that invokes the main method.
I found several tutorial but none of them a work.
It appears that you are relatively new to Java and Maven. It would be prudent to follow a proper course first rather than tutorials. You are missing fundamental knowledge that is generally not taught in tutorials.
I want to create a executable jar file so anyone can run it from their computer with least install require components.
It's also prudent to consider why you are doing this.
Tests will typically change as quickly as the source code they are testing does. Manually distribution of jar files won't keep up with this.
This means it's generally better to integrate the tests and the test source code into the automated build pipeline of the project they test.
This also means that you don't need to distribute your tests as a jar. Rather you should expect (and possibly train) people to use Maven, GIT and Java.

Vaadin 14 training "RouterAPI" is probably outdatedt, so mvn jetty:run raises an error. How do I need to change the POM file?

as stated I have trouble running mvn jetty:run with the existing vaadin exercise for routing in vs code. As the tutorial was already created under vaadin 10 the pom file is probably outdated, as the other trainigs worked perfectly fine with the mvn jetty:run command.
The exact error is:
No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\Dukatz\.m2\repository), central (https://repo.maven.apache.org/maven2)]
Sadly I'm pretty new do web application development, so I don't have the slightest idea, how to make it work. Hopefully you can help me.
The Tutorial: Vaadin Router Api Tutorial
the POM file:
<?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>com.vaadin.trainings.routing</groupId>
<artifactId>exercises-routing</artifactId>
<name>Routing Exercises</name>
<version>1.0.0</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Dependencies -->
<vaadin.version>13.0.5</vaadin.version>
<servlet.api.version>3.1.0</servlet.api.version>
<!-- Plugins -->
<jetty.version>9.4.15.v20190215</jetty.version>
<maven.war.plugin.version>3.1.0</maven.war.plugin.version>
</properties>
<repositories>
<repository>
<id>vaadin-prereleases</id>
<name>Vaadin Pre-releases</name>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<type>pom</type>
<scope>import</scope>
<version>${vaadin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Added to provide logging output as Flow uses -->
<!-- the unbound SLF4J no-operation (NOP) logger implementation -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</build>
</project>
There is no Problem with the pom file. Because it's an older lesson, there was no pom file created for the whole project, but only in the specific paths (like \exercises or \solutions). So running mvn jetty:run couldn't work. There was no pom in the directory. I started it in VS-Code with the Maven-Explorer jetty plugin but
mvn jetty:run -f "c:\Users\Dukatz\Desktop\VadinTutorials\Vaadin14-RouterAPI\Exercises\pom.xml"
would do the job from the command line.
Thanks me! I won't delete the question because, one day there's maybe someone as dumb as me.

Filter JUnit 5 test cases with the annotation #Tag("name_test") using Maven

I want to filter my Junit 5 test cases, I am using the annotation #Tag("type_test"). I run my test with maven with the command mvn -Dtests=a test but it runs all the cases. For example, I have two methods and I want run only the method with #Tag("a"), but the result in console is "Hello word 1" and "Hello word 2". See the example code.
static Properties properties = null;
#BeforeAll
public static void setUp() throws Throwable {
properties = CommonMethods.loadConfigPropertiesFile();
RestAssured.baseURI = properties.getProperty("BASE_HOST");
}
#Test
#Tag("a")
public void test1() {
System.out.println("hello word 1");
}
#Test
#Tag("b")
public void test2() {
System.out.println("hello word 2");
}
}
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<properties>
<includeTags>${tests}</includeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M2</version>
</dependency>
</dependencies>
The versions and libraries you're using are outdated. Please retry with:
Maven Surefire 2.22.1 (better: 3.0.0-M3)
JUnit Jupiter 5.3.2 (better: 5.4.0-M1)
See this sample pom.xml file that also covers how to filter tags:
<build>
<plugins>
<!-- JUnit 5 requires Surefire version 2.22.1 or higher -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<groups>a</groups>
<!-- excludedGroups>slow</excludedGroups -->
</configuration>
</plugin>
</plugins>
</build>
Source: https://github.com/junit-team/junit5-samples/blob/master/junit5-migration-maven/pom.xml
For more details on how to configure the JUnit Platform with Maven see the JUnit 5 User Guide https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven or the Maven Surefire documentation: https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html
No need to touch your POM file.
mvn surefire:test -D groups=a,b should also do the trick.
If you need to compile before running the tests, use:
mvn test -D groups=a,b
Note that the space put between -D and groups=a,b is optional and purely for cosmetic reasons.
I found a solution. It important verify and try with the latest version of each dependency. In this example:
maven-surefire-plugin (3.0.0-M3)
junit-platform-surefire-provider (1.3.0-M1)
junit-jupiter-engine (5.4.0-M1)
junit-jupiter-api (5.4.0-M1)
Solutions
Without profiles:
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<properties>
<includeTags>${tests}</includeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.0-M1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0-M1</version>
</dependency>
</dependencies>
And you can use the command mvn test -Dtests=a to execute only the methods with the annotation #Tag("a")
With profiles:
Add this example code in the pom.xml
<profiles>
<profile>
<id>serverdevelop</id>
<properties>
<tests>develop</tests>
</properties>
</profile>
<profile>
<id>servertesting</id>
<properties>
<tests>testing</tests>
</properties>
</profile>
<profile>
<id>serverproduction</id>
<properties>
<tests>production</tests>
</properties>
</profile>
</profiles>
And for example you can use the command mvn test -Pserverdevelop to execute only the methods with the annotation #Tag("develop"). This is very useful for separating test cases by environments.

Configure Jenkins to use Chrome - Selenium 3.0.1 Maven TestNG

I've been trying to get Jenkins to use Chrome for my automated tests. When I run the tests locally I am able to get it to use Chrome by -Dbrowser=chrome in JDK VM options for TestNG.
For some reason it seems to be stuck on using Firefox no matter what I try.
Here is my before method
#BeforeMethod(
alwaysRun = true
)
public static void configureBrowserBeforeTest(Method testMethod) {
try {
((Driver)driver.get()).resetBrowser();
wait.set(newDefaultWait());
userAgent = determineUserAgent();
initialiseNewScreenshotCapture(testMethod);
} catch (Exception var2) {
logger.error("Failed to configure browser.", var2);
throw new RuntimeException("Failed to configure browser.", var2);
}
}
And POM 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>
<groupId>com.frameworkium</groupId>
<artifactId>Frameworkium</artifactId>
<packaging>jar</packaging>
<version>2.0.5</version>
<name>Frameworkium</name>
<description>
A template designed to get up and running quickly with Selenium and Appium.
</description>
<url/>
<inceptionYear/>
<organization/>
<licenses/>
<developers/>
<contributors/>
<prerequisites>
<maven>3.1.1</maven>
</prerequisites>
<modules/>
<scm/>
<issueManagement/>
<ciManagement/>
<distributionManagement/>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<env.config>local</env.config>
<threads>1</threads>
<groups/>
<aspectj.version>1.8.9</aspectj.version>
</properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>com.github.Frameworkium</groupId>
<artifactId>frameworkium-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>
src/main/resources
</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
<systemProperties>
<screenshotDirectory>
${project.build.directory}/screenshots
</screenshotDirectory>
<allure.issues.tracker.pattern>
/browse/%s
</allure.issues.tracker.pattern>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>**/Test*.java</include>
<include>**/*Tests*.java</include>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
<groups>${groups}</groups>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I'm sure the solution is something simple, I have Jenkins running as a service and using a local admin account. I have installed the chromedriver plugin for jenkins as well as the Selenium plugin. The tests are being found OK but they are using Firefox and FF version 50 doesnt seem to work with the gecko driver on Selenium 3.0.1, so I would rather use Chrome which I know works just fine but for the life of me I cant figure out how to tell Jenkins to use Chrome instead of FF. Thanks in advance for your help! And apologies if I've missed anything out.
OS - Windows Server 2012
Maven
TestNG
Selenium 3.0.1
I am guessing that the default browser defined to be used is firefox and your test code is not able to find the browser flavour to use (via command line (or) JVM args (or) via parameters) so its defaulting to what it knows of viz., firefox.
I noticed that in your IntelliJ run configurations screenshot, you have specified the browser flavour using the JVM argument -Dbrowser=chrome but for some reason I don't see the same in your Jenkins configuration page screenshot.
You seem to be having something like this clean install package -DBrowserName="$BROWSERNAME" -e
Can you please change it to clean install package -Dbrowser=$BROWSERNAME -e (I dont think you need to enclose $BROWSERNAME with quotes and am assuming that BROWSERNAME refers to a valid parameter in your Jenkins configuration page )
That should basically take care of your issue.

Jenkins + Maven + TestNG = MojoFailureException

When I run in Eclipse, Maven and TestNG work fine and pass, but when I run in Jenkins, the following failure message appears:
MojoFailureException
Unlike many other errors, this exception is not generated by the Maven core itself but by a plugin. As a rule of thumb, plugins use this error to signal a failure of the build because there is something wrong with the dependencies or sources of a project, e.g. a compilation or a test failure.
The concrete meaning of the exception depends on the plugin so please have a look at its documentation. The documentation for many common Maven plugins can be reached via our plugin index.
This is my pom.xml:
<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>com.techbeamers</groupId>
<artifactId>loadtesting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Load Testing</name>
<description>Selenium Load Testing Example using TestNG and Maven</description>
<properties>
<selenium.version>2.53.1</selenium.version>
<testng.version>6.9.10</testng.version>
</properties>
<build>
<plugins>
<!-- Below plug-in is used to execute tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<!-- TestNG suite XML files -->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<!-- Include the following dependencies -->
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</project>
Please help -- I don't know what's wrong with my plugin or dependencies.
The first possible problem I see: you define the property: testng.version, set the value to: 6.9.10, but then ignore the testng.version property later in your pom.xml, and set the <version> of TestNG to: 6.8.
Try changing the definition of your TestNG <dependency> from what you curently have:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
So that the definition is defined as follows:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>

Categories