Failsafe Maven plugin separate selenium project - selenium

I have a selenium project separated from the web project.
I would like to use the Failsafe Maven plugin, but I am not sure if I can point in suiteXmlFiles label to the testng.xml file from another project. I would appreciate if anyone could help me.
<?xml version="1.0" encoding="UTF-8"?>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
</plugins>

Related

How to run test cases using robot framework jar file?

I tried running the testcases by using robotframework-2.8.6 jar like below
java -jar robotframework-2.8.6.jar testcases
But Its not recognizing the selenium2keywords. How do I use the selenium2library with robotframework jar ?
The easiest (and most robust/enhanceable) way to use the robot framework jar file is through the maven plugin.
(I'm assuming here that you have a maven runtime)
Just create a pom file that uses the plugin and run it using mvn install
Adding selenium 2 becomes just a matter of adding a dependency to the pom file.
Example (with selenium 2) which contains some useful tricks in it as well.
<?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.shtand</groupId>
<artifactId>robot-framework</artifactId>
<version>5.5.1</version>
<properties>
<logDir>${project.build.directory}/logs</logDir>
<webdriver.chrome.driver>bin\\chromedriver.exe</webdriver.chrome.driver>
</properties>
<dependencies>
<dependency>
<groupId>com.github.markusbernhardt</groupId>
<artifactId>robotframework-selenium2library-java</artifactId>
<version>1.4.0.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.3</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<variables>
<variable>RESOURCES:${project.basedir}/resources</variable>
<variable>LIBRARIES:../common</variable>
<variable>LOGDIR:${logDir}</variable>
</variables>
<extraPathDirectories>
<extraPathDirectory>resources</extraPathDirectory>
<extraPathDirectory>src/libraries/custom</extraPathDirectory>
<extraPathDirectory>src/test/robotframework/acceptance/common</extraPathDirectory>
</extraPathDirectories>
<excludes>
<exclude>NotImplemented</exclude>
</excludes>
<nonCriticalTags>
<nonCriticalTag>BUG_OPENED</nonCriticalTag>
</nonCriticalTags>
<debugFile>${logDir}/robot_debug.log</debugFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Using classpath command I was able to run the testcases.
java -cp robotframework-2.8.6.jar org.robotframework.RobotFramework testcase

How to run equivalent of Mule studio "Export" in a script?

I have the need to create a deployable ZIP archive from a script, much as the "Export" function does in Mule Studio. I'm expecting the ZIP to contain everything needed to deploy the app: JAR files, message flows, etc etc etc - again, just as Mule Studio Export does.
Is there a simple way to do this, or an example I can follow?
Maven is your best bet. Using the mule plugin for maven runnning mvn package will produce the deployable archive. More info on Mule and Maven here: http://www.mulesoft.org/documentation/display/current/Using+Maven+with+Mule
There is also an ant plugin but don't use it myself. Some info here: http://blogs.mulesoft.org/building-mule-apps-with-ant/
Alternatively, you can read about the application deployment structure here: http://www.mulesoft.org/documentation/display/current/Application+Format , so in theory you can build this structure yourself. But I wouldn't advise it and would stick to Maven.
Use Maven for building the app in jar/zip and deploy to the Mule standalone server automatically ... Make Sure your MULE_HOME is set to your standalone server in Environment variable ... and insert the following in your Maven Script to build it in Jar/Zip and deploy to app folder of Mule Standalone directly :-
<build>
<resources>
<resource>
<directory>>${project.basedir}/lib</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.mule.tools</groupId>
<artifactId>maven-mule-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
<configuration> <!-- This tag sets true/false to copy jar/zip file to Mule server app folder -->
<copyToAppsDirectory>true</copyToAppsDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>ISO-8859-1</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>YOUR_APPPLICATION_NAME</finalName>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${eclipsePluginVersion}</version>
<configuration>
<!-- by default download all sources when generating project files -->
<downloadSources>true</downloadSources>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER/${vmtype}/${jdkName}
</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<!--
make sure that MULE_HOME is set when building (required below when copying the
artifact to Mule's apps directory
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>env.MULE_HOME</property>
<message>You must set MULE_HOME before installing the example.</message>
</requireProperty>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>package-example</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- This tag automatically deploy jar/zip file to server -->
<copy file="${project.build.directory}/${project.build.finalName}.zip"
todir="${env.MULE_HOME}/apps" overwrite="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven 2 export jar to seperate directory

I need to export all the compiled class files as a jar to a directory of a local testserver. I would like to let maven do this automatically.
<!-- Build instructions -->
<build>
<finalName>${project.artifactId}</finalName>
<defaultGoal>compile package</defaultGoal>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<outputDirectory>/home/...</outputDirectory> <!--only class files go here, not the jar-->
<resources>
<resource>
<includes>
<include>plugin.yml</include>
</includes>
<directory>${basedir}</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
To build I first clean and then package via IntelliJ's Maven plugin. When I package I would like it to package the jarfile to my testserver so I don't have to move it over manually after every build.
Use Maven Ant plugin to custom code what you want to after a particular goal:
Using Ant with Maven
Ant Copt Task
You need to configure maven-jar-plugin and configure its outputDirectory as per your requirements, you can see the details on this link.
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html

Maven 3, maven-site-plugin, how to configure reportPlugins in a multi-module project

With Maven 3, the site plugin has changed regarding reporting.
In the maven 2, the reporting section had the an "inherited" element. For example:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.plugin.version}</version>
<configuration>
<useFile>false</useFile>
</configuration>
<inherited>true</inherited>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Does report plugin inheritance exist in Maven 3? So in maven 3 what is the inheritance behavior for reportPlugins and is there any way to change this behavior like the maven 2 inherited element?
Secondly, does the section have any affect on plugin configurations in the reportPlugins under the site plugin? Or do configurations have to be duplicated in pluginManagement & reportPlugins sections? Does any of this configuration also have to be duplicated in submodules?
At the end of the day I'd like to do something like the following in Maven 3:
<!-- in parent pom -->
<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.plugin.version}</version>
<configuration>
<useFile>false</useFile>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- no version num or config - specified in pluginManagement section -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- no version num, config, or report set - specified in pluginManagement section -->
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<!-- in sub module pom -->
<!-- specify nothing - already in parent pom-->
And I would like all of these configurations to be inherited to submodules. Even the reportPlugins section.
Is any/all of this possible with maven 3 currently?
It looks like this may not be completely possible.
Refer to this issue in the maven-site-plugin.
It is supposedly now working just like you wanted back then,
since Maven 3.5, released in 2017.

maven cobertura generated-classes

I'm using the maven cobertura plugin to generate coverage reports, but for some reason, the instrument goal gets stuck in an infinite loop.
In my classes directory (named bin), an infinite loop occurs and creates directories named generated-classes/cobertura/generated-classes/cobertura...and on and on as long as I let the instrument goal run. Inside each of the cobertura directories are my instrumented classes. Any idea why this might occur?
Can you post your pom file? Or at least the relevant sections? You should have something like the following:
<build>
<pluginManagement>
<plugins>
...snip...
<!-- cobertura code coverage plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
</plugin>
<!-- end cobertura code coverage plugin -->
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
Also, are you following the standard maven directory layout for your source? Where is your pom file with respect to your source files, and what does your directory layout look like?