maven2 - why failesafe plugin is ignoring my junit annotations? - maven-2

I have set up a java/maven project in order to perform tests this way:
unit tests are executed with the surefire plugin
integration tests are executed with the failsafe plugin
here is the POM (ugly compact formating):
<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>org.sample</groupId>
<artifactId>sample-service</artifactId>
<version>0.0.0</version>
<name>sdp-sample-service</name>
<build> <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration><debug>true</debug><source>1.6</source><target>1.6</target></configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-failsafe-plugin</artifactId><version>2.6</version>
<executions><execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<junitArtifactName>none:none</junitArtifactName>
<failIfNoTests>false</failIfNoTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version><scope>test</scope></dependency>
</dependencies>
</project>
I have a sample UNIT test class looking like that (again ugly compact format) :
package org.sample;import java.util.logging.Logger;import org.junit.*;
public class SampleUnitTest {
private static final Logger LOG = Logger.getLogger("SampleUnitTest");
#BeforeClass public static void beforeClass() {LOG.info("#BeforeClass");}
#Before public void before() {LOG.info("#Before");}
#AfterClass public static void afterClass() { LOG.info("#AfterClass");}
#After public void after() { LOG.info("#After"); }
#Test public void test1() { LOG.info("test1");}
#Test public void test2() { LOG.info("test2");}
}
I have the exact same Integration test:
package org.sample;import java.util.logging.Logger;import org.junit.*;
public class SampleIT {
private static final Logger LOG = Logger.getLogger("SampleIT");
#BeforeClass public static void beforeClass() {LOG.info("#BeforeClass");}
#Before public void before() {LOG.info("#Before");}
#AfterClass public static void afterClass() { LOG.info("#AfterClass");}
#After public void after() { LOG.info("#After"); }
#Test public void test1() { LOG.info("test1");}
#Test public void test2() { LOG.info("test2");}
}
And maven output is:
$ mvn clean install
...
[INFO] [surefire:test {execution: default-test}]
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.sample.SampleUnitTest
6 janv. 2011 14:38:38 org.sample.SampleUnitTest beforeClass
INFO: #BeforeClass
6 janv. 2011 14:38:38 org.sample.SampleUnitTest before
INFO: #Before
6 janv. 2011 14:38:38 org.sample.SampleUnitTest test1
INFO: test1
6 janv. 2011 14:38:38 org.sample.SampleUnitTest after
INFO: #After
6 janv. 2011 14:38:38 org.sample.SampleUnitTest before
INFO: #Before
6 janv. 2011 14:38:38 org.sample.SampleUnitTest test2
INFO: test2
6 janv. 2011 14:38:38 org.sample.SampleUnitTest after
INFO: #After
6 janv. 2011 14:38:38 org.sample.SampleUnitTest afterClass
INFO: #AfterClass
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
...
[INFO] [failsafe:integration-test {execution: integration-test}]
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.sample.SampleIT
6 janv. 2011 14:38:38 org.sample.SampleIT test1
INFO: test1
6 janv. 2011 14:38:38 org.sample.SampleIT test2
INFO: test2
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
...
Question: why failsafe integration tests totaly ignore my Junit annotation ?

Remove
<junitArtifactName>none:none</junitArtifactName>
from the configuration. It forces Surefire to run in Junit3 mode.

Related

Parallel Execution of Selenium Script on One Physical Machine

I have a hybrid framework based on Selenium WebDriver. It is taking around 2-3 hours to run the test suite I have right now. What is the best way to start running the tests parallel On the same machine (Even if I use Selenium Grid, how many nodes can I have at max on one machine, provided I also I have to use the same machine as the Hub ?). I have the constraint of using only one physical machine, and I am not using Test NG.
Run it with maven using the failsafe plugin by configuring to run in parallel with multiple threads.
Below is a sample code for running junit tests in 5 threads with test classes (placed in default location src/test/java and using the default class inclusion rules) running in parallel. The webdriver are instantiated in the BeforeClass and destroyed in the AfterClass methods. The webdriver instances are stored in a static ThreadLocal variable for keeping them separate.
pom.xml -
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
BaseClass -
public class BaseTestIT {
#BeforeClass
public static void setup() {
System.setProperty("webdriver.chrome.driver", "");
WebDriver driver = new ChromeDriver();
ThreadWebDriver.set(driver);
}
#AfterClass
public static void teardown() {
ThreadWebDriver.get().quit();
ThreadWebDriver.remove();
}
}
ThreadLocal -
public class ThreadWebDriver {
private static final ThreadLocal<WebDriver> threadWebDriver = new InheritableThreadLocal<WebDriver>();
private ThreadWebDriver() { }
public static WebDriver get() {
return threadWebDriver.get();
}
public static void set(WebDriver driver) {
threadWebDriver.set(driver);
}
public static void remove() {
threadWebDriver.remove();
}
}
TestOneClass - Both the methods will run in same thread.
public class FirstTestIT extends BaseTestIT {
#Test
public void testOne() {
System.out.println(Thread.currentThread().getId());
WebDriver driver = ThreadWebDriver.get();
driver.get("https://junit.org/junit4/");
driver.manage().window().maximize();
}
#Test
public void testTwo() {
System.out.println(Thread.currentThread().getId());
WebDriver driver = ThreadWebDriver.get();
driver.get("https://junit.org/junit5/");
driver.manage().window().maximize();
}
}
TestTwoClass - Single method will run in separate thread.
public class ThirdTestIT extends BaseTestIT{
#Test
public void test() {
System.out.println("third one");
WebDriver driver = ThreadWebDriver.get();
driver.get("https://stackoverflow.com/questions/tagged/selenium");
driver.manage().window().maximize();
}
}
You can even look at using a sharedwebdriver concept in which the driver will only be shut when the JVM closes. This link uses cucumber but pretty easy to modify just for selenium use. Remove the before and after hooks and handle this part in junit hooks.

but has not been marked #Optional in testng.xml

I am trying to run the below code using TestNG,
package Framework;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
public class XMLtestng {
WebDriver d;
#Test
#Parameters({"fname"})
public void reg(String fname) throws InterruptedException {
d.findElement(By.linkText("REGISTER")).click();
d.findElement(By.name("firstName")).sendKeys(fname);
d.findElement(By.name("register")).click();
Thread.sleep(3000);
}
#BeforeClass
public void beforeClass() {
d = new FirefoxDriver();
d.manage().window().maximize();
d.get("http://newtours.demoaut.com/");
}
#AfterClass
public void afterClass() {
d.close();
}
}
And this is the corresponding xml file,
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="reg">
<Parameter name="fname" value="Rachel"/>
<classes>
<class name="Framework.XMLtestng"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
when I run my xml file as TestNg suite,only the website's url is being opened and close. Actions to be performed (typing the firstname for registration), is not being executed. This is the message being printed in the console,
Suite
Total tests run: 1, Failures: 0, Skips: 1
===============================================
Can anybody please help me in resolving this.
Thanks in advance.
Your test is skipped because you didn't provide it the expected parameter and it is not declared as #Optionnal.
The problem is you used <Parameter... instead of <parameter....
Use the DTD to validate your file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

Jackson Afterburner module is failing inside Apache Karaf 3.0.5

I have a simple Hello World type Karaf Bundle running inside Apache ServiceMix 6.1.0 using Jackson's Afterburner Module. The activator code looks like below:-
public class HelloWorldActivator implements BundleActivator {
#Override
public void start(BundleContext bundleContext) throws Exception {
System.out.println("STARTING DEMO: hello, world\n");
System.out.println(getJsonDataAsString());
}
#Override
public void stop(BundleContext bundleContext) throws Exception {
System.out.println("STOPPING DEMO");
}
private String getJsonDataAsString() {
JsonDataBlob jsonDataBlob = new JsonDataBlob();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new AfterburnerModule());
try {
return objectMapper.writeValueAsString(jsonDataBlob);
} catch(Exception e) {
e.printStackTrace();
}
return "";
}
}
The pom.xml looks like below:-
<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.hello</groupId>
<artifactId>world</artifactId>
<version>0.0.1</version>
<packaging>bundle</packaging>
<name>Hello World</name>
<dependencies>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>**/com/hello/main/*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>com.hello.world.HelloWorldActivator</Bundle-Activator>
<Import-Package>*;resolution:=optional</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
The java object which I am trying to convert to json is a simple object as shown below:-
package com.hello.world;
public class JsonDataBlob {
private String add1 = "JP Naagar";
private String add2 = "";
private int shippartagent = 1;
public String getAdd1() {
return add1;
}
public void setAdd1(String add1) {
this.add1 = add1;
}
public String getAdd2() {
return add2;
}
public void setAdd2(String add2) {
this.add2 = add2;
}
public int getShippartagent() {
return shippartagent;
}
public void setShippartagent(int shippartagent) {
this.shippartagent = shippartagent;
}
}
But whenever I am trying to install the bundle I am getting the below exception and the bundle gets stuck in the Resolved state:-
2016-05-07 15:36:48,986 | WARN | x-6.1-2.0/deploy | fileinstall | 7 - org.apache.felix.fileinstall - 3.5.0 | Error while starting bundle: file:/Users/debraj/Downloads/apache-servicemix-6.1-2.0/deploy/world-0.0.1.jar
org.osgi.framework.BundleException: Activator start error in bundle world [239].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/afterburner/AfterburnerModule
at java.lang.Class.getDeclaredConstructors0(Native Method)[:1.8.0_77]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)[:1.8.0_77]
at java.lang.Class.getConstructor0(Class.java:3075)[:1.8.0_77]
at java.lang.Class.newInstance(Class.java:412)[:1.8.0_77]
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4336)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
... 7 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.module.afterburner.AfterburnerModule not found by world [239]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_77]
... 13 more
All the required Jackson bundles are installed in Karaf:-
karaf#root>bundle:list | grep Jackson
123 | Active | 50 | 2.6.2 | Jackson-core
125 | Active | 50 | 2.6.2 | Jackson-annotations
238 | Installed | 80 | 2.7.1 | Jackson-module-Afterburner
karaf#root>bundle:list | grep jackson
124 | Active | 50 | 2.6.2 | jackson-databind
Everything works fine if I comment out the below line:-
objectMapper.registerModule(new AfterburnerModule());
Can some one let me know what I am doing wrong?
All the code I have placed in the github.
You already asked this at the karaf mailing list.
It's still the same thing, as long as the package isn't imported in your own application it won't work.
Since you do an import for *;optional=true you won't get a wiring exception as your imports are all optional. Therefore the ClassNotFound Exeception.
First of all check the headers for the right imports with
bundle:header [bundle-id]
second, since you are doing an * import it might happen as you don't explicitly ask for a certain class in a certain package that some packages aren't imported.
And a sub-package import doesn't help on the package, so if you have an import for
com.fasterxml.jackson.module.afterburner.subPackage
this won't help on resolving classes in
com.fasterxml.jackson.module.afterburner
So it's actually best to declare all imports and use the * only on sub-packages.
In your case add the following to your pom:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>com.hello.world.HelloWorldActivator</Bundle-Activator>
<Import-Package>
com.fasterxml.jackson.module.afterburner.*,
*;resolution:=optional
</Import-Package>
</instructions>
</configuration>
</plugin>
Along with upgrading to Jackson 2.7.4. Modifying my Import-Package in pom.xml as shown below solved the issue:-
<Import-Package>com.fasterxml.jackson.module.afterburner.ser;resolution:=optional,*</Import-Package>

Cucucmber-Jvm (Using Maven Project) + Selenium WebDriver PageObjects + Allure Report

I am working on "Cucucmber-Jvm (Using Maven Project) + Selenium WebDriver PageObjects + Allure Report", I am unable generate "Allure" report.
Below are the codes, feature file, pom.xml, etc...
Pom.xml : Reference POM url - https://github.com/allure-framework/allure-cucumber-jvm-adaptor
<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>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<name>Allure Cucumber-JVM Adaptor</name>
<artifactId>allure-cucumber-jvm-adaptor</artifactId>
<groupId>ru.yandex.qatools.allure</groupId>
<version>1.4-SNAPSHOT</version>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://github.com/allure-framework/allure-cucumber-jvm-adaptor</url>
<connection>scm:git#github.com:allure-framework/allure-cucumber-jvm-adaptor.git</connection>
<developerConnection>scm:git:git#github.com:allure-framework/allure-cucumber-jvm-adaptor.git</developerConnection>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/allure-framework/allure-cucumber-jvm-adaptor/issues</url>
</issueManagement>
<ciManagement>
<system>TeamCity</system>
<url>http://teamcity.qatools.ru/</url>
</ciManagement>
<developers>
<developer>
<id>clicman</id>
<name>Viktor Sidochenko</name>
<email>viktor.sidochenko#gmail.com</email>
</developer>
</developers>
<mailingLists>
<mailingList>
<name>Allure Mailing List</name>
<post>allure#yandex-team.ru</post>
</mailingList>
</mailingLists>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<compiler.version>1.7</compiler.version>
<allure.version>1.4.5</allure.version>
<aspectj.version>1.8.4</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-core</artifactId>
<version>${allure.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-java-aspects</artifactId>
<version>${allure.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-commons</artifactId>
<version>${allure.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.0</version>
<type>jar</type>
</dependency>
<!-- <dependency>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</dependency> -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.5</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<!-- parallel execution configuration -->
<parallel>classes</parallel>
<threadCount>8</threadCount>
<includes>
<include>**/*Test.java</include>
</includes>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>ru.yandex.qatools.allure.cucumberjvm.AllureRunListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Feature file location: src/test/resources and Name of the feature file: OpenAndclose.feature
Feature: OpenAndClose
Scenario: OpenAndClose Browser
Given user opened firefox browser
Then user entered url
Then user closed firefox browser
And codes at: src/test/java
TestRunner class:
package openANDclose;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(dryRun=false, monochrome = true, features= "src/test/resources/OpenAndclose.feature")
public class OpenAndClose_TestRunner {
}
Step Definitions:
package openANDclose;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
public class OpenAndClose_StepDefinitions {
public static WebDriver driver;
#Given("^user opened firefox browser$")
public void user_opened_firefox_browser() throws Throwable {
driver=new FirefoxDriver();
}
#Then("^user entered url$")
public void user_entered_url() throws Throwable {
OpenAndClose_PageObjects.user_opened_firefox_browser(driver);
}
#Then("^user closed firefox browser$")
public void user_closed_firefox_browser() throws Throwable {
OpenAndClose_PageObjects.user_closed_firefox_browser(driver);
}
}
Page Object Class:
package openANDclose;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class OpenAndClose_PageObjects {
public static WebDriver driver ;
public static WebElement element=null;
public static WebElement user_opened_firefox_browser(WebDriver driver) {
driver.get("http://google.co.in");
return element;
}
public static WebElement user_closed_firefox_browser(WebDriver driver) {
driver.quit();
return element;
}
}
After running "Allure" report from command prompt, getting below error message and error report.
Below report from: "mvn clean test" below error message is displaying.
D:\Cucumber_JVM_WorkSpace\Cucumber_Allure>mvn clean test
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO] ... total of 1 executions of maven-deploy-plugin replaced with nexus-st
aging-maven-plugin
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Allure Cucumber-JVM Adaptor 1.4-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # allure-cucumber-jvm-ad
aptor ---
[INFO] Deleting D:\Cucumber_JVM_WorkSpace\Cucumber_Allure\target
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # allure-cucumber-j
vm-adaptor ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # allure-cuc
umber-jvm-adaptor ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Cucumber_JVM_WorkSpace\Cucumber_Al
lure\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) # allure-cucumber
-jvm-adaptor ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # al
lure-cucumber-jvm-adaptor ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) # allure-
cucumber-jvm-adaptor ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to D:\Cucumber_JVM_WorkSpace\Cucumber_Allure\tar
get\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_StepDefinitions.java:[3,27] package org.openqa.selenium does not exis
t
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_StepDefinitions.java:[4,35] package org.openqa.selenium.firefox does
not exist
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_StepDefinitions.java:[11,23] cannot find symbol
symbol: class WebDriver
location: class openANDclose.OpenAndClose_StepDefinitions
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[3,27] package org.openqa.selenium does not exist
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[4,27] package org.openqa.selenium does not exist
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[7,23] cannot find symbol
symbol: class WebDriver
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[9,23] cannot find symbol
symbol: class WebElement
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[11,62] cannot find symbol
symbol: class WebDriver
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[11,23] cannot find symbol
symbol: class WebElement
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[16,62] cannot find symbol
symbol: class WebDriver
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_PageObjects.java:[16,23] cannot find symbol
symbol: class WebElement
location: class openANDclose.OpenAndClose_PageObjects
[ERROR] /D:/Cucumber_JVM_WorkSpace/Cucumber_Allure/src/test/java/openANDclose/Op
enAndClose_StepDefinitions.java:[15,36] cannot find symbol
symbol: class FirefoxDriver
location: class openANDclose.OpenAndClose_StepDefinitions
[INFO] 12 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.287 s
[INFO] Finished at: 2015-05-02T15:01:37+05:30
[INFO] Final Memory: 13M/33M
[INFO] ------------------------------------------------------------------------
Below report from: mvn site
About Allure Cucumber-JVM Adaptor
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project not comliled successfully and not started. You should add webdriver dependencies to your project`s pom.xml.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.45.0</version>
</dependency>
Also you should not compile the adaptor itself. Use it as dependency to your project. See an example project: allure-cucumber-jvm-example.
Use example project as base and add selenium dependency to it and your code.

Maven findbugs:check - Output Summary Of Bugs

Does anybody know how to configure the maven findbugs plugin to output a summary of the bugs to the console (similar to the pmd plugin)?
At present findbugs:check just prints out how many bugs there are in total and I need to check the individual modules target/findbugs directory and each findbugs.xml file to fix the issues.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0.1</version>
<configuration>
<xmlOutput>true</xmlOutput>
<xmlOutputDirectory>findbugsreports</xmlOutputDirectory>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlOutputDirectory>target/site/findbugsreports</findbugsXmlOutputDirectory>
<debug>true</debug>
</configuration>
</plugin>
Ideally it would be good to get a summary report back on the command line. Any ideas?
I use this hack, based on maven-groovy-plugin:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-5-SNAPSHOT</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def file = new File("${project.build.directory}/findbugsXml.xml")
if (!file.exists()) {
fail("Findbugs XML report is absent: " + file.getPath())
}
def xml = new XmlParser().parse(file)
def bugs = xml.BugInstance
def total = bugs.size()
if (total > 0) {
log.info("Total bugs: " + total)
for (i in 0..total-1) {
def bug = bugs[i]
log.info(
bug.LongMessage.text()
+ " " + bug.Class.'#classname'
+ " " + bug.Class.SourceLine.Message.text()
)
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
There isn't currently a means to do this using the standard plugin. You can create a plugin to read the findbugsChecks.xml and output the information you need though.
The code below will output the total bugs found and the bugs per package for any project with a findbugsChecks.xml in the output directory. You can configure the name of the file it reads by setting the findBugsChecks property on the configuration:
package name.seller.rich;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* #goal stats
*/
public class FindbugsStatsMojo extends AbstractMojo {
/**
* Where to read the findbugs stats from
*
* #parameter expression="${findbugsChecks}"
* default-value="${project.build.directory}/findbugsCheck.xml"
*/
private File findbugsChecks;
/**
* Output the Findbus stats for the project to the console.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (findbugsChecks != null && findbugsChecks.exists()) {
try {
Xpp3Dom dom = Xpp3DomBuilder.build(new FileReader(
findbugsChecks));
// get the summary and output it
Xpp3Dom summaryDom = dom.getChild("FindBugsSummary");
// output any information needed
getLog().info(
"Total bug count:"
+ summaryDom.getAttribute("total_bugs"));
Xpp3Dom[] packageDoms = summaryDom.getChildren("PackageStats");
getLog().info(packageDoms.length + " package(s)");
for (int i = 0; i < packageDoms.length; i++) {
String info = new StringBuilder().append("package ")
.append(packageDoms[i].getAttribute("package"))
.append(": types:").append(
packageDoms[i].getAttribute("total_types"))
.append(", bugs:").append(
packageDoms[i].getAttribute("total_bugs"))
.toString();
getLog().info(info);
}
} catch (FileNotFoundException e) {
throw new MojoExecutionException(
"Findbugs checks file missing", e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException(
"Unable to parse Findbugs checks file", e);
} catch (IOException e) {
throw new MojoExecutionException(
"Unable to read Findbugs checks file", e);
}
}
}
}
To package this code, add it to the src/main/java folder of a Mavenproject with a POM 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>name.seller.rich</groupId>
<artifactId>maven-findbugs-stats-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>
Then run mvn install to install the plugin.
To actually use it, you can run it as an additional goal on the command line, or bind it to your project to run as part of the standard lifecycle.
Here's the command to run from the commandline (assuming the project has previously been compiled:
mvn findbugs:check name.seller.rich:maven-findbugs-stats-plugin:0.0.1:stats
To bind the configurations to your project so it will be run on each build, use the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>check</id>
<phase>package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<xmlOutput>true</xmlOutput>
<xmlOutputDirectory>findbugsreports</xmlOutputDirectory>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlOutputDirectory>${findbugsOutputDirectory}</findbugsXmlOutputDirectory>
<debug>true</debug>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>name.seller.rich</groupId>
<artifactId>maven-findbugs-stats-plugin</artifactId>
<executions>
<execution>
<id>stats</id>
<phase>package</phase>
<goals>
<goal>stats</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Following along from the concepts above I have raised this issue on the maven findbugs issue tracker. http://jira.codehaus.org/browse/MFINDBUGS-118. I have also coded and submitted a patch that shows total bugs for each project. It could easily be modified to get other details.
The code ignores projects specified as producing POM outputs and also ignores projects whose POMs specify true in their findbugs configuration. We are running a large multi-module maven build with the patch applied.
With the patch applied you run mvn findbugs:check and you get something like the following output (output obfuscated to protect the guilty :):
[INFO] Summary
[INFO] -------
[INFO] C:\PATH\Abstraction\PalDefinitions\target/findbugsXml.xml 4
[INFO] C:\PATH\System\target/findbugsXml.xml 19
[INFO] C:\PATH\ApplicationLayer\target/findbugsXml.xml 13
[INFO] C:\PATH\Support\ServiceStub\target/findbugsXml.xml 11
[INFO] C:\PATH\Support\MultiPlatform\target/findbugsXml.xml 10
[INFO] C:\PATH\Support\Serializer\target/findbugsXml.xml 19
[INFO] C:\PATH\Support\Brander\target/findbugsXml.xml 19
[INFO] C:\PATH\PlatformAbstraction\Pal1\target/findbugsXml.xml 8
[INFO] C:\PATH\PlatformAbstraction\Pal2\target/findbugsXml.xml 0
[INFO] C:\PATH\PlatformAbstraction\Pal3\target/findbugsXml.xml 0
[INFO] C:\PATH\PlatformAbstraction\Pal4\target/findbugsXml.xml 0
[INFO] C:\PATH\Framework\Common\target/findbugsXml.xml 12
[INFO] C:\PATH\Framework\legacyFramework\target/findbugsXml.xml 7
[INFO] C:\PATH\Framework\UIFramework\target/findbugsXml.xml 7
[INFO] C:\PATH\ExecutionLayer\Stub\target/findbugsXml.xml 0
[INFO] C:\PATH\ExecutionLayer\BB\BB\target/findbugsXml.xml 1
[INFO] TOTAL = 130
[INFO] -------
[INFO] Number of bugs 130 falls BELOW summaryThreshold 260. Check OK
You can do this with Violations Maven Plugin. It is configured with patterns to identify report files on the filesystem. It needs to run after findbugs, or any other static code analysis tool.
It will
Print the violations in the build log.
Optionally fail the build if number of violations found is higher then a configured number.