Cucumber test ignored - TestNG - java

I hope my second question on SO is well scripted. I am trying to automate test cases using Gherkin, TestNG and Selenium in Java. Using a Maven project with Intellij.
I am able to launch my Test Case when I launch them in the .feature file but when I use the testng.xml file or the Test Runner class, it somehow ignores the Test Case.
I have already checked the project settings which seems to be properly configured. Also checked that I have proper dependencies in my pom.xml (I hope I do)
My test.feature
Feature: Xray Jira
#TEST_01 #STC
Scenario: Xray Jira Testing
Given The user login to the application
When the credentials are entered
Then the homepage is viewed
My test Runner
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
#CucumberOptions(
features = "src/test/resources/",
glue = {"src/test/Steps/"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
My step definition - the following code in the step definitions are
working when I launch the test case from the feature file
package Steps;
import Pages.BasePage;
import Pages.HomePage;
import Pages.LoginPage;
import Helper.ConfigFileReader;
import io.cucumber.java.en.*;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
public class MyStepdefs extends BasePage {
private WebDriver driver = null;
private Hooks lHooks;
public MyStepdefs(Hooks lHooks) {
this.driver = lHooks.driver;
}
#Given("The user login to the application")
public void the_user_login_to_the_application() {
LoginPage loginObject = new LoginPage(driver);
resultValue = loginObject.VerifyUrl();
Assert.assertTrue(resultValue);
}
#When("the credentials are entered")
public void the_credentials_are_entered() {
ConfigFileReader config = new ConfigFileReader();
String userID = config.getUserID();
String userPassword = config.getUserPassword();
LoginPage loginObject = new LoginPage(driver);
loginObject.enterName(userID);
loginObject.enterPassword(userPassword);
loginObject.clickLoginButton();
HomePage lHome = new HomePage(driver);
resultValue=lHome.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
#Then("the homepage is viewed")
public void the_homepage_is_viewed() {
HomePage homeObject = new HomePage(driver);
resultValue=homeObject.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
My POM.xml
//Below is my POM.xml I usually followed different tutorials online to get the dependencies. I had issues with compatibility of different version of the dependencies. I was able to correct them. Not sure if it is still the problem
<?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>execute_auto</groupId>
<artifactId>execute_auto</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.7.1</version>
</dependency>
<!-- Web driver manager dependency -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>testng.xml</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.15.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>POC-language-testing</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My expected result should be that the test is passed. But it is always ignored when launched via testng.xml or the runner class. I would be more than glad if anyone could he be of help
PS: My final objective is to automate and launch test cases on Intellij with Cucumber and Java using Page Object Model. This should update the test cases on Xray in Jira. If anyone has any useful link with respect to such functionalities, it would be much appreciated.

The glue element should be a package name, not a directory. So if your steps are in the package Steps then the glue should be Steps.
Additionally TestNG swallows the message in the SkipException exceptions thrown by Cucumber so you should add the summary plugin to see why Cucumber skipped the test (most likely due to an undefined step because you didn't have the glue configured properly).
#CucumberOptions(
features = "src/test/resources/",
glue = {"Steps"},
plugin = {
"summary"
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
As an aside: You should not include transitive dependencies in your pom. You can and should remove the cucumber-core, gherkin and cucumber-jvm-deps dependencies.

Related

What container provider supports org.apache.cxf.jaxrs.JAXRSServerFactoryBean?

Using the information provided below can you answer the following questions:
What container provider supports org.apache.cxf.jaxrs.JAXRSServerFactoryBean so that I may add my application using org.glassfish.jersey.server.ContainerFactory when creating an end point?
What is wrong with the below application that causes (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class); to throw an illegal argument exception?
I am attempting to deploy a JAX-RS application that uses annotations (no web.xml) to system that uses a Java Application Manager (it is a proprietary system that has ported over some application manager libraries but I am not sure what those are due to little supporting documentation around it).
At a high level I have a Java application that uses JAX-RS annotations, such as ApplicationPath, Path, Produces/Consumes, and JsonProperty, to attempt to create an endpoint on a "application server". I say "application server" because I have no documentation around this system so I am just going to call it that. When attempting to start the application I get the following exception:
java.lang.IllegalArgumentException: No container provider supports the type class org.apache.cxf.jaxrs.JAXRSServerFactoryBean
at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:64)
at org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint(RuntimeDelegateImpl.java:47)
at com.app.Server.startServer(Server.java:182)
I have researched the java.lang.IllegalArgumentException thrown by the org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint function. I am not sure why it would do this because on the cover it appears like the application class is annotated correctly and extends Application.
I was able to look at the Server's class code and here is what is being done:
Server Code
Here a snippet portion of com.app.Server.startServer(Server.java:182) code, I cannot alter this code:
inside of startServer...
Application app = (Application) Class.forName("com.app.MyApplication").newInstance();
JAXRSServerFactoryBean jaxrsServerFactory = (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class);
Now my code:
Application Code
MyApplication
package com.app;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import com.app.services.ServiceOne;
#ApplicationPath("base/path")
public class MyApplication extends Application {
public MyApplication() {
System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " constructor called...");
}
/* (non-Javadoc)
* #see javax.ws.rs.core.Application#getClasses()
*/
#Override
public Set<Class<?>> getClasses() {
System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " getClasses() method called...");
Set<Class<?>> classes = new HashSet<>();
classes.add(ServiceOne.class);
return classes;
}
}
My Application's Services
package com.app.services.ServiceOne;
import java.util.ArrayList;
import javax.ws.rs.Consumes;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// pretend the model imports are here...
#Path("serviceOne")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class ServiceOne {
#PUT
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public ResponseObject performService(InputObject body) throws NotFoundException {
// do whatever to get result and send...
}
}
Pom.xml Plugins and Dependencies
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.28-RC4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.28-RC4</version>
</dependency>
</dependencies>
Thanks again for your help!
I figured out the answer to my question.
The system I was attempting to deploy my application to already had jar files installed on the system in various directories.
I updated my application to include those jar files. This was done by updating a descriptor that I use to deploy the application to the system.
Then I and set the scope of certain dependencies in my pom.xml to <scope>provided</scope> so that when the application was packaged by maven, those dependencies would not be included in the final jar.
Below is an example:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jdk-http</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.28-RC4</version>
<scope>provided</scope>
</dependency>
</dependencies>
This was fixed in my side by excluding jersey-server which has its own META-INF/services/javax.ws.rs.ext.RuntimeDelegate (see RuntimeDelegate.JAXRS_RUNTIME_DELEGATE_PROPERTY), hence preventing the proper loading of org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl. In my case, jersey-server was brought transitively by hadoop-mapreduce-client-core:
<dependency>
<groupId>XXX</groupId>
<artifactId>YYY</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
</exclusion>
</exclusions>
</dependency>

The import javax.servlet cannot be resolved (only in runtime) [duplicate]

I was trying to implement a login filter in my web app with jsf 2, following this guide:
https://stackoverflow.com/tags/servlet-filters/info
after I compiled my filter and added the .class in "web-inf/classes" (as the guide says) the filter worked, but i put the wrong url to redirect to the login page so i deleted the filter.class from the folder (web-inf/classes) and tried to compile the project again , but it failed, and since then im getting "package javax.servlet does not exist"
it is weird because before it was working and i have javax.servlet in my pom.xml.. i tried cleaning the project, but nothing.
this is my filter class:
package Bean;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Created with IntelliJ IDEA.
* User: rodrigo
* Date: 28-04-13
* Time: 06:54 AM
* To change this template use File | Settings | File Templates.
*/
#WebFilter("/Contenido/*")
public class filtro implements Filter {
#Override
public void init(FilterConfig config) throws ServletException {
// If you have any <init-param> in web.xml, then you could get them
// here by config.getInitParameter("name") and assign it as field.
}
#Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) request;
LoginBean user = (LoginBean) req.getSession().getAttribute("user");
if (user != null && user.isLoggedIn()) {
// User is logged in, so just continue request.
chain.doFilter(request, response);
} else {
// User is not logged in, so redirect to index.
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(req.getContextPath() + "/Contenido/Login.xhtml");
}
}
#Override
public void destroy() {
// If you have assigned any expensive resources as field of
// this Filter class, then you could clean/close them here.
}
}
this is the error:
\Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[5,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[6,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[7,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[8,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[9,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[10,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[11,31] error: package javax.servlet.annotation does not exist
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Frutemu</groupId>
<artifactId>Frutemu</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Frutemu Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2-b10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2.1-b04</version>
<scope>provided</scope>
</dependency>
<!-- OpenJPA framework -->
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>Frutemu</finalName>
<plugins>
<!-- Open Jpa -->
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<includes>**/model/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Plugin para levantar una instancia de Tomcat 7 liviana, única para este proyecto -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://127.0.0.1:8080/manager/text</url>
<server>TomcatServer</server>
<path>/Frutemu</path>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<dependencies>
<!--note this must be repeated here to pick up correct xml validation -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
The javax.servlet dependency is missing in your pom.xml. Add the following to the dependencies-Node:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
I only put this code in my pom.xml and I executed the command maven install.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
The answer provided by #Matthias Herlitzius is mostly correct. Just for further clarity.
The servlet-api jar is best left up to the server to manage see here for detail
With that said, the dependency to add may vary according to your server/container. For example in Wildfly the dependency would be
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
So becareful to check how your container has provided the servlet implementation.
I needed to import javaee-api as well.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
Unless I got following error:
package javax.servlet.http does not exist
javax.servlet.annotation does not exist
javax.servlet.http does not exist
...
In my case, migrating a Spring 3.1 app up to 3.2.7, my solution was similar to Matthias's but a bit different -- thus why I'm documenting it here:
In my POM I found this dependency and changed it from 6.0 to 7.0:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
Then later in the POM I upgraded this plugin from 6.0 to 7.0:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
...
<configuration>
...
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
I got here with a similar problem with my Gradle build and fixed it in a similar way:
Unable to load class hudson.model.User due to missing dependency javax/servlet/ServletException
fixed with:
dependencies {
implementation('javax.servlet:javax.servlet-api:3.0.1')
}
I ran into the same error when using IntelliJ IDEA despite having javax.servlet-api listed as a dependency in my pom.xml file.
Turns out my Java project did not have Maven framework support. Here is how I added it:
Right click on the project in Project View -> select 'Add Framework Support...'
Select 'Maven'
In the Maven View that shows up, click 'Download Sources and/or Documentation'
Hope this helps anyone new to IntelliJ IDEA.
maybe doesnt exists javaee-api-7.0.jar.
download this jar and on your project right clik
on your project right click
build path
Configure build path
Add external Jars
javaee-api-7.0.jar choose
Apply and finish

Cucumber parsing strings

I'm learning how to use cucumber in java and selenium webdriver. I have the architecture in place and I'm down to one very specific problem.
#When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \" ([^\"]*)\"")
public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{
if (arg1.equals("PRO")) {
arg1 = "PRO";
}
if (arg2.equals("testleader")) {
arg2 = "testleader";
}
if (arg3.equals("Chrome")) {
arg3 = "Chrome";
}
assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3));
}
I don't understand why this code works, and when I leave out the if statements I get a null pointer exception, like this:
#When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \"([^\"]*)\"")
public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{
assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3));
}
gets me:
java.lang.NullPointerException
at codebase.LoginPortal.inloggen(LoginPortal.java:14)
at codebase.Beoordeling_Login.correctinloggen(Beoordeling_Login.java:12)
at steps.InloggenSteps.I_login_with_the_parameters(InloggenSteps.java:32)
at ✽.When I login with the parameters "PRO" and "testleader" and "Chrome" (featurefiles/inloggen.feature:9)
When I put back the if statements it runs like I would expect, so I know that arg1, arg2 and arg3 strings are actually strings and can be used.
Why won't it let me use them in my login method and I have to re-set the strings in an ugly fashion?
edit 1:
public class LoginPortal { public WebDriver inloggen(String Omgeving, String Rol, String Browser) {
String InlogUrl = null; WebDriver driver = anroepDriver.roepdriver(Browser);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
complete code on github: https://github.com/Yourtestprofessionals/YourCucumber
edit2: cheers for the replies so far. my problem is still not solved though.
EDIT
Here is my modified pom.xml. I went back to selenium-java version 2.53.1. I also added surefire and specified Java 1.8 (Oracle). Try this pom and let me know.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.czeczotka.bdd</groupId>
<artifactId>cucumber-jvm-maven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>cucumber-jvm-maven</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</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>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.53.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<additionalClasspathElements>
<!-- ${basedir} needed in classpath so that log4j can find the log4j.properties file -->
<additionalClasspathElement>${basedir}</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19.1</version>
</dependency>
</dependencies>
</plugin>
<!-- Specifying the maven-compiler-plugin allows us to set default JDK -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I last point. I am using ChromeDriver 2.25.426923.
EDIT 2
I modified your runner. I replaced format with plugin.
package runner;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cucumber"},
glue = "steps",
features = "classpath:featurefiles/nieuwe_bevinding.feature"
)
public class RunInloggerTest {
}
I would be surprised if this would actually solve your problem but trying won't hurt; have you tried using the regex 'wildcard': '.*'?
Like this:
#When("^I login with the parameters \"(.*)\" and \"(.*)\" and \"(.*)\"")

Maven Surefire plugin did not rerun failed Cucumber tests

I am using the Java implementation of Selenium WebDriver (version 2.53.0) to run some automated tests against a web application. The tests are written in Behaviour Driven Testing format using the Java implementation of Cucumber (version 1.2.3). I use Maven (version 3.3.9) to import all my dependencies and also to build and run the tests. The tests are organised into different categories using Cucumber tags. For example, I can run one category of tests tagged with #JohnnyBravo from the command line using the following commands:
cd path_to_Maven_POM_file
mvn clean test -Dcucumber.options="--tags #JohnnyBravo"
After doing some research, I found out that you can use the Maven SureFire plugin to rerun failed tests by adding "-Dsurefire.rerunFailingTestsCount=2" to the Maven command above according to this link. I then tried to rerun that category of tests using the command below while ensuring that some of them will definitely fail so as to see if they will be rerun or not:
mvn clean test -Dcucumber.options="--tags #JohnnyBravo" -Dsurefire.rerunFailingTestsCount=2
Unfortunately, the failed tests did not rerun. What am I doing wrong here ?
My POM file is shown below:
<?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.company</groupId>
<artifactId>regression-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<cucumber.version>1.2.3</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.pojosontheweb</groupId>
<artifactId>monte-repack</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>src/test/resources/chromedriver/chromedriver.exe</webdriver.chrome.driver>
</systemPropertyVariables>
<!--<testFailureIgnore>true</testFailureIgnore>-->
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The Cucumber JUnit test runner class is shown below:
import com.cucumber.listener.ExtentCucumberFormatter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.HashMap;
#RunWith(Cucumber.class)
#CucumberOptions(
monochrome = false,
plugin = {
"pretty",
"html:C:/Test_Output_Data/Results/HTML/",
"json:C:/Test_Output_Data/Results/results.json",
"com.cucumber.listener.ExtentCucumberFormatter"
},
features = {"src/test/resources/"},
tags = {
"#JohnnyBravo",
//"#AgentUI", "#Smoke",
//"#GenUI", "#Smoke",
//"#GenUI", "#Regression",
}
)
public class GeneralRunnerTest {
#BeforeClass
public static void setup() {
ExtentCucumberFormatter.initiateExtentCucumberFormatter();
ExtentCucumberFormatter.loadConfig(new File("src/test/resources/extent-config.xml"));
ExtentCucumberFormatter.addSystemInfo("Browser Name", "Firefox");
ExtentCucumberFormatter.addSystemInfo("Browser version", "46.0.1");
ExtentCucumberFormatter.addSystemInfo("Selenium version", "2.53.0");
HashMap<String, String> systemInfo = new HashMap<>();
systemInfo.put("Cucumber Version", "1.2.3");
systemInfo.put("Extent Cucumber Reporter Version", "1.1.0");
ExtentCucumberFormatter.addSystemInfo(systemInfo);
}
}
Check if you are using the right version for your cucumber dependencies.
On the page for this feature on the surefire website, it says
Since of 2.21.0 the provider surefire-junit47 can rerun scenarios created by cucumber-jvm 2.0.0 and higher.
Also check if you're using the same junit provider that they've mentioned. I'm not sure which is the default provider.

The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved

I'm a newbie at Spring and this is also my very first question on StackOverflow so I'm going to try to make this as understandable as possible.
I'm trying to make a web service client using Spring and Maven on this tutorial: and I get this error: The import org.springframework.test.context.junit4 cannot be resolved
Here is my code:
package demo;
import hello.WsClientApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; //this won't import
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = WsClientApplication.class)
public class WsClientApplicationTests {
#Test
public void contextLoads() {
}
}
Here is my pom.xml in case you need it.
<?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>org.springframework</groupId>
<artifactId>gs-consuming-web-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::wsdl[] -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
<!-- end::wsdl[] -->
</plugins>
</build>
</project>
I have tried some other solutions in StackOverflow but I can't get it to work.
Thanks.
You need to add a dependency on spring-boot-starter-test:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Now, if you are using latest spring-boot, 1.5.2 RELEASE, #SpringApplicationConfiguration is no longer available, instead you must use #SpringBootTest. Reference here(#spring boot starter test in Spring Boot)
Gradle
In gradle this would be done by adding
testCompile("org.springframework.boot:spring-boot-starter-test")
to the dependencies block as in:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
After that it should be possible to write an import statement at the top of your class
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Allowing you to use the annotation:
#RunWith(SpringJUnit4ClassRunner.class)
public class MyAppTest {
}
I know this is answered kind of late, but I had the same problem and I found I was able to fix it 2 ways.
I was able to remove the < scope > test < / scope> tags and that removed the restriction
I had an issue with intellij not properly handling it when doing tests, so I made sure it was marked as test-root, I changed it from green -> gray -> back to the green test-root and that resolved my issue.
Just to improve in the situation.
I managed to fix it like this:
before, spring boot initializr created a dependency to spring-boot-starter-test but with the exclusion, like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
Eclipse accused the annotation #Runwith to be Junit 4, therefore, the logic thing to do was to remove the exclusion.
Final POM dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
sometimes maven start downloading dependencies and doesn't finish.
Go to your .m2 folder and type:
find . -name *progre*
this command will show you every file with the tag "in-progess", which are the files missing or not finished.
delete the folder and try to update the dependencies again.
In case, you are not using the spring boot, but only spring framework you should add dependency for spring-test.
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
You can check the latest version for spring-test using mvn, and update accordingly.
If you are using spring-boot project than add spring boot dependency, if you are not using spring-boot the below will work, but not recommended.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.4.1</version>
</dependency>
NOTE: If you are using spring-boot project, adding <version> will not be necessary.

Categories