selenium 2 chrome driver - maven

So I have read all the docs on adding chromedriver to my path and followed all of them. I am on a Mac with selenium2, maven, eclipse, and all the latest drivers:
Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;
I put chromedriver in my Applications folder and my path looks like:
echo $PATH
/Users/tcerrato/selenium/BS_Sel_Project/auto_helper/test_scripts:/usr/local/apache-maven-2.2.1//bin:/Users/oracle/oracle/product/10.2.0/db_1/bin:/opt/local/bin:/opt/local/sbin:/Applications:
What am I missing? I cannot run with chrome driver at all. Any help would be great I'm trying random stuff now.
Here is my pom section on selenium:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0rc2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.6.0</version>
</dependency>

Add WebDriverManager to your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
This library downloads the latest version of the WebDriver binary you need and export the proper Java system variable (webdriver.chrome.driver, webdriver.gecko.driver, webdriver.opera.driver, webdriver.edge.driver, webdriver.ie.driver), simply using one of the following sentences respectively:
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();
More info on https://bonigarcia.dev/webdrivermanager/

I am not sure about Maven but this how I set the property webdriver.chrome.driver
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

Setting the webdriver.chrome.driver system property via maven can be done by the following (and tested working):
Add systemPropertyVariables configuration to the maven-surefire-plugin in your pom.xml. This is (typically) because surefire is the caller for tests and where system properties will be set.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
</systemPropertyVariables>
</configuration>
</plugin>
Now define ${webdriver.chrome} somewhere. A good start is a <properties> section in your pom.xml
<properties>
<webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>
</properties>
Potentially this could be done better via the use of <profiles> like in Simon Martinelli's example

You could have a go at using the driver binary downloader maven plugin to download the driver binaries for you (https://github.com/Ardesco/selenium-standalone-server-plugin):
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
This will download the binaries and set a maven property that you can use in your surefire/failsafe configuration like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<systemProperties>
<!--Set properties passed in by the driver binary downloader-->
<phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
</systemProperties>
<includes>
<include>**/*WebDriver.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
When you instantiate a new driver object the system property pointing to the driver binary location will now be set and it will just work.

So in the pom you have to set it like this
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.34.0</version>
</dependency>
This is a java code to run the chrome using selenium
System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
WebDriver myD = new ChromeDriver();
In order for you to run Chrome you need to download the chrome driver from here. https://code.google.com/p/chromedriver/downloads/list
Once you have done that then you have to set it in environment variable. Read this https://code.google.com/p/selenium/wiki/ChromeDriver
Thanks,
Mediha

System.setproperty("webdriver.chrome.driver","your file path here with chromedriver.exe");
webDriver driver=new chromeDriver();
driver.get("http://google.com");

Try this:
System.setProperty("webdriver.chrome.driver","/location to/chromedriver folder");
WebDriver driver = new ChromeDriver();
driver.get("your.app");

It works for me without setting webdriver.chrome.driver property. Just by adding chromedriver to PATH
> echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
>
> which chromedriver
/usr/local/bin/chromedriver
If you use Homebrew, installing chromedriver along with adding to PATH can be done as simple as this:
brew install chromedriver
Useful links:
https://sites.google.com/a/chromium.org/chromedriver/
http://brewformulas.org/Chromedriver

Just add WebDriverManager in your maven pom and it works without manual setup if you have your browser setup in default config.

Pom.xml code and Selenium code below:
<groupId>com.HelloWorld</groupId>
<artifactId>t</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>t</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>${webdriver.chrome}
</webdriver.chrome.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
</project>
Selenuim Code
public class App
{
static String currentDir = System.getProperty("user.dir");
static WebDriver driver;
#BeforeClass
public static void setupClass() {
ChromeDriverManager.getInstance().setup();
driver= new ChromeDriver();
driver.get("https://www.google.com/");
}
#Test
public void test() {
System.out.println( "Hello World!" );
}
}

Related

Test class cannot resolve main class when trying to Unit Test groovy using maven on Jenkins

I am having trouble getting my Unit Tests to work in Maven for a Jenkins shared library written in Groovy.
I am new to Maven and relatively new to Jenkins. The situation is the following:
We have a TFVC server hosting our shared library. The shared library is stored this way:
TFVC
- sharedLibrary
- src
- br
- common
- v1
- SomeClass1.groovy
- SomeClass2.groovy
- SomeClass3.groovy
- test
- groovy
- SomeClass1Tests.groovy
- SomeClass2Tests.groovy
- Jenkinsfile
- pom.xml
The structure src-br-common-v1 cannot be changed. I added the test-groovy structure according to information I found online.
The Jenkinsfile contains the Job to test the library in Maven. It's calling
mvn clean gplus:testCompile
My POM looks like this:
<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>my.company</groupId>
<artifactId>sharedLib</artifactId>
<version>1.0</version>
<name>Jenkins Shared Pipeline Library</name>
<repositories>
<repository>
<id>jenkins</id>
<url>http://repo.jenkins-ci.org/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-core</artifactId>
<version>2.85</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.12</version>
</dependency>
<dependency>
<groupId>com.cloudbees</groupId>
<artifactId>groovy-cps</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-utility-steps</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/br/common/v1</sourceDirectory>
<testSourceDirectory>src/test/groovy</testSourceDirectory>
<resources>
<resource>
<directory>E:\Jenkins\plugins\pipeline-utility-steps\WEB-INF\lib</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>
<directory>${project.basedir}/src/br/common/v1</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
<testSources>
<testSource>
<directory>${project.basedir}/src/br/common/v1</directory>
<directory>${project.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<argLine>${surefireArgLine}</argLine>
<includes>
<include>**/*Test*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is a simplified version of a Test class, lets just assume SomeClass1 contains a method returnTrue that does exactly what you think:
package test.groovy;
import br.common.v1.SomeClass1;
public class SomeClass1Tests extends GroovyTestCase
{
public void testReturnTrue() {
def someClass1Object = new SomeClass1();
def expected = true;
def result = someClass1Object.returnTrue();
assertEquals(expected, result);
}
}
I now have the problem that my Test class cannot resolve the class I want to test.
Unable to resolve class br.common.v1.SomeClass1 # line 2, column 1
Originaly I had my test files in another location in TFVC, but that did not work and I read that gmaven-plus is very picky about where to store your test classes.
I hope I provided all information needed in a practical way, please let me know if I missed anything.
Thank you for your help in advance!
The source directories configured for maven are to specific (they point to where the files are). If you want to import br.common.v1 make sure, that the directory hierarchy br/common/v1 is inside the source roots.

Cucumber not running in parallel with Maven

I'm trying to run my Cucumber tests with Selenium in parallel using Maven. I tried maven surefire plugin and failsafe plugin and even old cucumber jvm parallel plugin. I've got the same result. My tests run in sequence without parallelization.
I've tried to configure maven-surefire-plugin and then maven-failsafe-plugin. Nothing helps.
Here is my pom.xml file
<plugins>
<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>
<encoding>UTF-8</encoding>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/RunnerTest.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.3.0.jre8-preview</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies>
And here my configuration of failsafe plugin. But it disabled
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<rerunFailingTestsCount>1</rerunFailingTestsCount>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/RunnerTest.class</include>
<include>**/*IT.class</include>
</includes>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<perCoreThreadCount>false</perCoreThreadCount>
<reportsDirectory>target</reportsDirectory>
</configuration>
</execution>
</executions>
</plugin>
And my Runner class
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue = "step_definitions",
plugin = {"pretty", "html:target/cucumberHtmlReport", "json:target/cucumber-report.json"},
monochrome = true,
strict = true
)
public class RunnerTest {
}
To run my tests in Maven I use this command:
mvn clean verify "-Dcucumber.options=--tags #Test-1,#Test-2" -Dbrowser=chrome
In addition I can say that I'm using static webDriver and Singleton class for handling properties. I have no idea how it can impact but it's FYI. I can provide code if required.
For now I'm looking to run my tests in forks because threads handling is another big deal.
Please follow below steps.
Key Point :
We shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome.
We do not need to use cucumber-jvm-parallel or cucable plugin when cucumber version is greater than or equal to 4.0.0.
Cucumber Parallel Execution via JUnit
First - Update POM.xml with correct set of io.cucumber dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
Point To Note Down - There could be an issue like everything is ok but still tests do not execute in parallel and could be if your pom.xml is having direct/transitive dependency of testng. As testNG causes Surefire to ignore JUnit wrapper class. If you had testng dependency so remove the TestNG dependency or you can take a call to 2 define 2 execution - For TestNG & JUnit and disable one as per your need.
Second - Customize Runner class as per your framework need
package com.jacksparrow.automation.suite.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:features/functional/",
glue = {"com.jacksparrow.automation.steps_definitions.functional" },
plugin = { "pretty","json:target/cucumber-json/cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
tags = { "#BAMS_Submitted_State_Guest_User" },
junit ={ "--step-notifications"},
strict = false,
dryRun = false,
monochrome = true)
public class RunCukeTest {
}
Third - Implementing maven surefire plugin which would actually run tests in parallel
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>2</threadCount>
<reuserForks>false</reuserForks>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*RunCukeTest.java</include>
</includes>
</configuration>
</plugin>
Fourth - Implement Hooks.java
import cucumber.api.Scenario;
import cucumber.api.java.Before;
import cucumber.api.java.After;
public class Hooks {
#Before
public void setUpScenario(String browser){
//BaseSteps.getInstance().getBrowserInstantiation(browser); your browser setup method
}
#After
public void afterScenario(Scenario scenario){
// more code goes here
}
}

How to execute JAVA FX 11 JAR without providing VM args via CMD

Java : JDK 12
Build Tool : Maven
IDE : Eclipse
OS : Windows
I have a simple piece of java FX 11 code which displays a simple blank screen.
I have made deployed an executable jar using eclipse.
It works fine when i give the following command using CMD:
As it is visible that i need to provide the modules at time of execution of JAR file.
If we skip this step we get JAR direct execution error:
As I have already tried using maven as :
---Maven 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.proj1</groupId>
<artifactId>Proj1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13-ea+7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>--add modules</arg><arg> javafx.controls,javafx.fxml,javafx.graphics</arg>
</compilerArgs>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
But even when this is done the exported executable JAR still demands the arguments.
Is it possible to somehow avoid this through CMD and make the JAR executable by simply double clicking it using Maven.
I am not asking on how to solve the javaFx runtime exception but on how to solve it by adding dependencies so that when the JAR is distributed the client does not have to pass the runtime arguments and get the job done by simple clicks.
With the JavaFX maven plugin you can execute two goals: run and jlink. The former will just run the project with the required arguments (--module-path, --add-modules), so you can run on command line:
mvn clean javafx:run
Of course, this is not intended for distribution.
javafx:jlink
However, if your project is modular (i.e you have a module-info.java file), you can set your plugin like:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.2</version>
<configuration>
<mainClass>hellofx/org.openjfx.App</mainClass>
<launcher>app</launcher>
<jlinkImageName>appDir</jlinkImageName>
<jlinkZipName>appZip</jlinkZipName>
</configuration>
</plugin>
and run:
mvn clean javafx:jlink
It will generate a custom runtime image with your project that you can distribute, and you can add a launcher or even zip it. Once extracted you will only need this to run it:
target/appdir/app
See the plugin options here.
Shade plugin
You can also use the maven-shade-plugin.
As explained here you will need a main class that doesn't extend from Application:
Launcher.java
package org.openjfx;
public class Launcher {
public static void main(String[] args) {
App.main(args);
}
}
And now you can add the shade plugin to your pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjfx.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Run mvn clean package, and it will generate your fat jar that you can distribute and run as:
java -jar target/hellofx-1.0-SNAPSHOT.jar
Cross platform
Note that in both cases (jlink or shade plugin), you will have a jar that you can distribute only to run on the same platform as yours.
However you can make it multiplaform if you include the dependencies for other platforms as well:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>12.0.1</version>
<classifier>mac</classifier>
</dependency>

Manually creating a deployable JAR for Liferay

I created a liferay workspace in gradle format and it basically only contains a theme and a TemplateContextContributor-module.
Now I want to build a maven "wrapper" around both artifacts to make them compatible with some other maven-processes/-plugins while keeping the original gradle structure. I dont want to use the liferay-maven-plugin or maven-tools to build those artifacts, because it seems to behave differently from the gradle/gulp toolset when it comes to compiling scss for example.
So I created some POMs from scratch for
Theme
TemplateContextContributor-Module
First off I will take about the mechanism for the theme, which is already working:
That wrapper uses the maven-war-plugin to bundle the contents of the build/-folder, where the previously built gradle artifact resides, into a WAR-file that can be deployed by Liferay without problems.
theme pom.xml:
<properties>
<src.dir>src</src.dir>
<com.liferay.portal.tools.theme.builder.outputDir>build</com.liferay.portal.tools.theme.builder.outputDir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
[...]
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${com.liferay.portal.tools.theme.builder.outputDir}</directory>
<excludes>
<exclude>**/*.sass-cache/</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
However, I am having difficulties creating a OSGI-Compatible JAR-File for the module contents. It seems that only the META-INF/MANIFEST.MF does not contain the right information and I seemingly cannot generate it in a way that Liferay (or OSGI) understands.
this is the module pom.xml dependencies and plugins that I tried:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<version>1.2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.gradle.plugins</artifactId>
<version>3.9.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
[...]
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.ant.bnd</artifactId>
<version>2.0.48</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.25.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
I was able to create a JAR using the above but its' META-INF/MANIFEST.MF is not identical to the one produced by the gradle build:
I guess that's why Liferay does not deploy it. The log says "processing module xxx ....", but that never ends and the module does not work in Liferay.
These are the plugins I have tried in different combinations so far:
maven-build-plugin
maven-scr-plugin
maven-jar-plugin
maven-war-plugin
maven-compiler-plugin
Any help in creating a liferay-deployable module JAR would be great.
I'm not sure why you're manually building a maven wrapper for the Template Context Contributor. The Liferay (blade) samples are available for Liferay-workspace, pure Gradle as well as for Maven. I'd just go with the standard and not worry about re-inventing the wheel.
To make this answer self-contained: The current pom.xml listed in the Template Context Contributor plugin is:
<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>
<artifactId>template-context-contributor</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>blade</groupId>
<artifactId>parent.bnd.bundle.plugin</artifactId>
<version>1.0.0</version>
<relativePath>../../parent.bnd.bundle.plugin</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>com.liferay.blade.template.context.contributor-${project.version}</finalName>
</build>
</project>

Cucumber report duplication while using Scenario Outline

When using Scenario Outline, the report generates two times of scenario, one without color and another with color (as show in the image).
This happens only when using Scenario Outline, not when using Scenario.
Here is my pom.xml
'
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
GroupMaven
ArtifactMaven
0.0.1-SNAPSHOT
pom
ProjectMaven
http://maven.apache.org
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
'
Here is My Cucumber Runner class
'
#RunWith(Cucumber.class)
#CucumberOptions(format = {"html:cucumber-html-reports/first",
"json:cucumber-html-reports/cucumber.json" }, features = { "test/features/FirstFeature.feature" })
public class CucumberCukesTest {
}
'
And i used monochrome,strict,dryrum, etc options, nothing will work. And also i used plugin instead of format.
Cucumber report for scenario using Scenario Outline keyword
The first one is the generalized details of your scenario outline ie what you have written in the feature file. Check out the and in the 6th and 7th step.
The second one and others depending on the number of examples is the scenario with the details substituted with the actual values for userid and password. Notice the absence of <> in the same steps.

Resources