Hot questions for Using Cucumber in eclipse

Question:

I am new to automation. Im facing this problem while running cucumber feature. It doesnt show run as Cucumber feature option at all

Screen shot of Run as options in eclipse


Answer:

As, when you open a feature file in Eclipse and right-click, then you do not find an option 'Run As->Cucumber Feature', it appears that your Eclipse do not have the required Cucumber Eclipse Plug-in. You can install this plug-in using following steps:

  1. Launch Eclipse and navigate to 'Help->Install New Software'.
  2. Click on 'Add' button
  3. Enter any name e.g. 'Cucumber' and type 'http://cucumber.github.com/cucumber-eclipse/update-site' as location.
  4. Click on OK.
  5. 'Cucumber Eclipse Plugin' option will appear in the available software list.
  6. Select the check box against it and click on 'Next' button.
  7. Read the terms of license agreement and click on 'I accept the terms of the license agreement" if you agree with the license terms.
  8. Click on 'Finish' button.
  9. Let it install, it will take few seconds to complete.

After successful installation of this plug-in, if you open any feature file (i.e. file with .feature extension) and right-click, you should see 'Run As->Cucumber Feature' option.

Update 1

In Eclipse, go to 'Windows->Preferences->Run/Debug/Launching/Launch Configuration' and uncheck 'Cucumber Feature' checkbox if it is checked. Refer to below screen shot for more details:

Question:

I'm setting up a test environment with Cucumber, Sikuli and Eclipse in my company. I've managed to get everything working just fine, but now I need to make the .feature files work in portuguese.

As far as I know, all I had to do was put the comment #language: pt at the beginning of the .feature file, but it's not working.

I also ran the commands cucumber --i18n help and cucumber --i18n pt to check if the language is really there, and it is.

Is there another configuration I'm not aware of?

I'm using these jars:

  • cucumber-core-3.0.2.jar
  • cucumber-java-3.0.2.jar
  • cucumber-junit-3.0.2.jar
  • cucumber-jvm-deps-1.0.6.jar
  • gherkin-5.1.0.jar
  • junit-4.12.jar
  • mockito-all-1.10.19.jar

Answer:

You can control the language of the Gherkin keyword by adding # language: xx as first line.

For Portuguese it would be

# language: pt
Funcionalidade: um exemplo

A list of all supported spoken languages can be found at https://docs.cucumber.io/gherkin/reference/#spoken-languages. The localized keywords you might lookup for example in gherkin-languages.json

A simple Maven project.

structure

pom.xml
src/test/java/features/example.feature
src/test/java/runner/TestRunner.java

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.suboptimal</groupId>
    <artifactId>cuke-test-13.so</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.cucumber>3.0.2</version.cucumber>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

src/test/java/features/example.feature

# language: pt
Funcionalidade: um exemplo

  Cenario: foo
  Dado something given

src/test/java/runner/TestRunner.java

package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features/example.feature"
        )
public class TestRunner {
}

running the test with mvn compile test will produce the following error.

Undefined scenarios:
src/test/java/features/example.feature:4 # foo

1 Scenarios (1 undefined)
1 Steps (1 undefined)
0m0.036s


You can implement missing steps with the snippets below:

@Dado("something given")
public void something_given() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

edit When the feature file is saved on Windows with Notepad as UTF-8 the BOM characters (EF BB BD) are inserted at the beginning.

$ hexdump -C example.feature 00000000 ef bb bf 23 20 6c 61 6e 67 75 61 67 65 3a 20 70 |...# >language: p|

If running mvn test the execution fails with exception.

cucumber.runtime.CucumberException: gherkin.ParserException$CompositeParserException: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '# language: pt'
(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Funcionalidade: um exemplo'
(4:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Cenario: foo'
(5:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Dado something given'

Question:

I am developing a test automation script using Cucumber, Selenium, and JUnit in Java. To quickly detect any issues with my custom code, I am placing System.out.println("success") and System.err.println("failure") in certain places. The problem is that neither print to the console in Eclipse. I've done this hundreds of times all though not necessarily with these tools. I suspect either Cucumber or JUnit is the culprit, but I couldn't find anything confirming this after some Google queries.

I did see this:

System.out.println doesn't print anything inside eclipse console

But that isn't the problem. None of my consoles are displaying my println()'s.

UPDATE What I've tried so far:

  1. PrintStream out = System.out; System.setOut(out); System.out.println("hello");
  2. Eclipse Console not showing output
  3. Explicitly throw an exception (resulted in no stack trace in console)

Answer:

So it turns out there is a bug with the version of Eclipse I was using (Eclipse Oxygen). Typically, when running code in Eclipse, the code is executed as javaw.exe instead of java.exe. The difference between those two are ONLY that javaw.exe does not use the CMD console where as java.exe does use the CMD console. Usually Eclipse will execute with javaw since it has its own console, however there is a known bug with some Eclipse versions, perhaps just Oxygen, where Eclipse does not handle this properly so you need to make it use java instead. To do this:

Go to Run > Run Configurations > make sure the desired class with the main method is selected on the left > select JRE on the right > click Alternate JRE under the Runtime JRE section > select Alternate under Java executable and type "java" in the field > Apply

Question:

Is there any way to run selective tests from Cucumber BDD Example section without commenting the lines?

For instance, from the example below, I would like to run 2nd row of test without commenting 1st & 3rd rows.

Scenario Outline: Test Scenario
        Given logged into the test application  using <username> and <password>
        When user is navigated to home screen
        Then user should be able to find home menus

    Examples:
    | username | password |
    | test1    | pwd1     |
    | test2    | pwd2     |
    | test3    | pwd3     |

I was working with C# - SpecFlow where I could achieve this using Test Explorer window. With SpecFlow & MS Visual Studio Test Explorer, user would be able to load all the tests and run single / selective tests easily. So would like to find similar option in Cucumber Java as well. Please help.


Answer:

In ruby cukes I think you can run test2 by telling cukes the line number of the example. So lets say the scenario is called foo, and the line your test2 example is on is line 25 then

cucumber features/foo.feature:25

would do what you ask.

Question:

I'm new to Maven. I have converted my Cucumber project to Maven and I'm getting execution error when I try to run Maven Clean or Maven Build.

[ERROR] Error executing Maven.
[ERROR] 1 problem was encountered while building the effective settings
[FATAL] Non-parseable settings C:\Users\qz\.m2\settings.xml: end tag name </settings> must match start tag name <activeProfiles> from line 10 (position: TEXT seen ...</pluginManagement>   \r\n</build>\r\n</settings>... @21:12)  @ C:\Users\qz\.m2\settings.xml, line 21, column 12

Snap of Maven Installation and Configuration My settings.xml file have some problem too as under Eclipse > Windows > Preferences > Maven > User Settings, I can see an error 'Could not read settings.xml'

I have tried deleting my repository folder and rebuilding it but that wasn't effective. It may be something to do with my Eclipse-Maven integration.

Edit-1: adding settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

 <localRepository>Users/qz/.m2/repository</localRepository>
 <interactiveMode>true</interactiveMode>
 <offline>false</offline>
  <profiles><profiles/>
  <activeProfiles><activeProfiles/>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.6</version>
        </plugin>           
      </plugins>
    </pluginManagement>   
</build>
</settings>

Edit-2: corrected .xml and updated the error message


Answer:

Close xml tag should be </tagName>

  <localRepository>Users/qz/.m2/repository 
 </localRepository>
 <interactiveMode>true</interactiveMode>

You can have empty tag in single tag as <tagName/> or you can remove it

   <activeProfiles/>

Question:

I have a Spring Boot project. In it I have a java class BookTests which contains:

@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {
                "pretty",
                "html:target/acceptance-test-report",
                "json:target/cucumber/cucumber.json"
        },
        glue = {
                "com.my.sdk.test",
                "com.my.book.test"
        }
        ,tags = {"@findConsideringGrants"}
        )
public class BookTests {
    // No implementation required.  The Cucumber annotations drive the test execution.

}

I'm using Junit 4. when I "Debug As JUnit Test" this class it only runs the feature file which is annotated with "@findConsideringGrants (as it should)

Is there a way i don't have to hard-code this tags annotation in the java class but instead specify the tags as Program argumnents or VM arguuments?

I tried configuring it with Program argumnents, but with all the following attempts it ignored the argument and ran the tests on all my features/tags:

--tags findConsideringGrants 
-tags findConsideringGrants
--tags @findConsideringGrants 
-tags @findConsideringGrants

So to summerize, i'm looking for a way to 1) debug in eclipse a certain feature 2) without hardcoding the name of the feature into the java source. Somehow by just configuring the debug configuration.

is this even possible?


Answer:

If you are using maven you can use -- mvn test -Dcucumber.options="--tags @findConsideringGrants".

Or you can use the cucumber cli command to run -- Main.main(new String[]{"-g", "classpath to step definition file","-t", "tags to use", "-p", "plugins to use", "Full path to feature file"}). The feature file path has to be the last option.

Running from eclipse -- Go to the "Environment" tab of the "Debug Configurations" or "Run Configurations" window. Click on "New" button. For the "Name" add "cucumber.options" and "Value" add "--tags @findConsideringGrants". Apply and Run. If you want to add a specific feature file path add only the path to the end of this.

Question:

I am trying to set up a very simple Cucumber test environment using Eclipse. I am following a tutorial and created the project with required reference libraries:

Referenced Libraries

I have created the CucumberRunner.java file with the following content:

package cucumber;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)

@CucumberOptions(
    plugin = { "pretty", "json:target/cucumber.json" },
    features = "src/cucumber"
    )

public class CucumberRunner {

}

and also create a feature file and step definitions. If I run the from, the feature files, the tests run correctly. But, if I run from the CucumberRunner.java, I get:

java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetPublicMethods(Class.java:2902)
    at java.lang.Class.getMethods(Class.java:1615)
    at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
    at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
    at cucumber.runtime.Runtime.<init>(Runtime.java:92)
    at cucumber.runtime.Runtime.<init>(Runtime.java:70)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:80)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

I have installed the Cucumber Eclipse Plugin as per another answered question so I am at a total loss as to why this is happening. If I try to add JARs to include the missing libraries, I just seem to move the problem to a difference missing library.

I think it must be to do with the versions of libraries I am using but I am a complete novice at this and have no experience of how to problem solve this.

Any help at all would be much appreciated.


Answer:

In my case, I had to add glue="cucumber.steps", to the CucumberOptions list.

Question:

I get a java.lang.NoClassDefFoundError: gherkin/formatter/Formatter when I execute my cucumber JUnit test in Eclipse.

My environment:

Eclipse Neon 4.6.3
JUnit 4.12
Cucumber-core 1.2.5
Cucumber-java 1.2.5
Cucumber-junit 1.2.5
Hamcrest-core 1.3

Reference to cucumber in eclipse: eclipse\help\Installed software  tab=cucumber Eclipse feature ver 0.0.17.201704062133.

Eclipse Environment Setup

enter image description here

POM.XML

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javacodegeeks</groupId>
  <artifactId>junitcucumber</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>JUnit Cucumber Example</name>
  <description>JUnit Cucumber Example</description>
 <dependencies>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

UserSteps.java

package junitcucumber;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import junitcucumber.User;

public class UserSteps {

    private User user = new User();

    @Given("^that the user (.*) is given a task to clear (.*) certification exam$")
    public void certificationName(String name, String certication) throws Throwable {
        user.setName(name);
        user.setCertification(certication);
    }

    @When("^(.*) got (\\d+) marks in exam$")
    public void gotMarks(String name, int marks) throws Throwable {
        user.setName(name);
        user.setMarks(marks);
    }

    @Then("^(.*) is known as (.*) certified$")
    public void certifiedYes(String name, String certification) throws Throwable {
        assertThat(name, is(user.getName()));
        assertThat(user.getCertification(), equalTo("Java"));
        assertThat(user.getResult(), is(true));
    }
}

user.feature

Feature: User Certification

  Scenario: User is Passed
    Given that the user Vinod is given a task to clear Java certification exam
    When Vinod got 60 marks in exam
    Then Vinod is known as Java certified

UserTest.java

package junitcucumber;

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
public class UserTest {

}

User.java

package junitcucumber;

public class User {
    private String name;
    private String certification;
    private int marks;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCertification() {
        return certification;
    }

    public void setCertification(String certification) {
        this.certification = certification;
    }

    public int getMarks() {
        return marks;
    }

    public void setMarks(int marks) {
        this.marks = marks;
    }

    public boolean getResult() {
        if (this.marks < 60) {
            return false;
        } else {
            return true;
        }
    }
}

Eclipse project class path: enter image description here

Stack Trace:

java.lang.NoClassDefFoundError: gherkin/formatter/Formatter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.formatter.PluginFactory$1.<init>(PluginFactory.java:53)
    at cucumber.runtime.formatter.PluginFactory.<clinit>(PluginFactory.java:52)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:70)
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:25)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:56)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Formatter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 34 more

Answer:

The Gherkin JAR is missing in your Java build path (see Referenced Libraries in your screenshot):

  1. Add Gherkin as dependeny to your pom.xml.
  2. Make sure Maven Dependencies > gherki-2.12.2.jar > gherkin.formatter > Formatter.class is available (if not, in the Maven repository delete the JAR which may be broken and rebuild the project).

Question:

everyone. I'm faced with a problem using serenity+cucumber: I run maven "clean verify" tasks to my project (using eclipse IDE) and when first test case fail, execution is aborted.

Here is pom.xml:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>br.jus.tjpb.testes.fta</groupId>
<artifactId>estudos</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>estudos</name>
<url>http://maven.apache.org</url>

<properties>
    <junit.version>4.12</junit.version>
    <selenium.version>3.4.0</selenium.version>
    <serenity.version>1.5.3</serenity.version>
    <slf4j.version>1.8.0-alpha2</slf4j.version>
    <cucumber.version>1.2.5</cucumber.version>
    <serenity.cucumber.version>1.5.4</serenity.cucumber.version>
    <!-- BUILD -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <surefire.version>2.19.1</surefire.version>
    <failsafe.version>2.19.1</failsafe.version>
    <compiler.version>3.5.1</compiler.version>
    <!-- TAGS -->
    <tags>SistemaCompleto</tags>
    <webdriver.driver>firefox</webdriver.driver>
</properties>

<profiles>
    <profile>
        <id>win</id>
        <properties>
            <geckodriver.path>C:\\geckodriver\\geckodriver.exe</geckodriver.path>
        </properties>
    </profile>
    <profile>
        <id>linux</id>
        <properties>
            <geckodriver.path>/ambiente/conf/geckodriver</geckodriver.path>
        </properties>
    </profile>
</profiles>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.8.0-alpha2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</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>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>${serenity.cucumber.version}</version>
    </dependency>
</dependencies>

<build>
    <resources>
        <resource>
            <directory>src/test/java</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire.version}</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${failsafe.version}</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                <reuseForks>true</reuseForks>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                <systemPropertyVariables>
                    <tags>${tags}</tags>
                    <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    <webdriver.gecko.driver>${geckodriver.path}</webdriver.gecko.driver>
                    <webdriver.timeouts.implicitlywait>30</webdriver.timeouts.implicitlywait>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${compiler.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>${serenity.version}</version>
            <dependencies>
                <dependency>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-core</artifactId>
                    <version>${serenity.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

Here it is error look like:

Failed tests: expected:<[]-Menor que 18 anos: ...> but was:<[duvida]-Menor que 18 anos: ...>

Here it is report generation status:

[INFO] --- serenity-maven-plugin:1.5.3:aggregate (serenity-reports) @ estudos ---
[INFO] current_project.base.dir: /home/diegoquirino/workspace/estudosfta
[INFO] Generating test results for 0 tests
[INFO] 0 requirements loaded after 736 ms
[INFO] 0 related requirements found after 736 ms
[INFO] Generating test outcome reports: false
[INFO] Starting generating reports: 750 ms
[INFO] Configured report threads: 20
[INFO] Test results for 0 tests generated in 1798 ms

I saw some error about serinity+cucumber reports but proposed solution in them didn't address my problem.

Thanks for help.


Answer:

The dependency is into the plugin in POM.xml:

<plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>${serenity.version}</version>
            <dependencies>
                <dependency>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-core</artifactId>
                    <version>${serenity.version}</version>
                </dependency>
            </dependencies>

The dependencies should be between the rest of dependencies . . . .

Try to remove that dependency and past it into the dependencies, not in the plugin section.

Question:

I have seen it, and i have tried to follow its steps to generate the steps of feature file. Here is my dependencies in pom.xml:

<dependencies>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </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-java8</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

And i have defined the runner class as below:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber"})
public class RunCukesTest {
}

and the feature file is located in src/features in the project:

The problem is, when i right click on the feature file-> Run as-> Cucumber

Nothing happens.

I expect that, the cucumber runner runs, and gives me the steps

So, what is wrong?

Feature is:

Feature: Title of your feature I want to submit data into registeration form

Scenario: Register into the forum
Given I want to register into the main forum
When I enter name
    And I enter passwrod
    And I repeat the password
    And I enter username
    And I enter email
Then I click the submit

Answer:

I didn't need that RunCukesTest at all.The point was to install the Cucumber-jvm plugin on STS, and it generates the steps very easily. This question was also very useful.

Additionally, to run a feature file in Eclipse, you should

  1. open the file
  2. Right click on it
  3. Rus as
  4. 1 Cucumber Feature

Question:

I'm running some service testing using restassured and cucumber and they work fine locally just using Maven test.

The issue is if I run Maven clean, then I must run Maven update or it will not work (Says it can't find my Cucumber feature files). For reference it says:

No features found at [classpath:classpath/classpath]

This wouldn't be a huge issue except I need to have this running through Bamboo where I can't call Maven update.

So I either need to figure out what is wrong with my POM to begin with to cause this issue, or how I can run Maven update through the goals/environment variables.

The POM is fairly simple, only having the needed dependencies/reporting stuff. The build part of the POM is as follows:

<build>
    <finalName>Test</finalName>
    <directory>target</directory>
    <outputDirectory>target/classes</outputDirectory>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/test/resources</directory>
        </resource>
    </resources>
</build>

This is all in Java 8 using Eclipse as the IDE.


Answer:

I would avoid specifying anything in the build section in my pom and instead use the default values.

That is, I would keep my feature files in the same package as the runner or a sub package.

The runner could for example live in the package se/thinkcode/tage As in the directory:

./test/java/se/thinkcode/tage

This means that the feature files should live in the directory:

./test/resources/se/thinkcode/tage

This would allow me to minimize the configuration in the runner. I typically use runners that looks like this:

package se.thinkcode.tage;

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class RunCukesTest {
}

This is the smallest configuration possible if you want to run Cucumber using JUnit from Maven.

It is even smaller that the example supplied by the Cucumber team: https://github.com/cucumber/cucumber-java-skeleton