0

I am trying to run some test for cucumber (to learn) I have the below:

myapplication.feature with

Feature: test                                                                      
   Scenario: login
   Given open firefox and start app 
   When enter details    
   Then login happens

the class runner:

package runnerPackage;

import org.junit.runner.RunWith;
import org.testng.annotations.Test;

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

@RunWith(Cucumber.class)
@CucumberOptions(features="C:/Users/lucian.patrascu/workspace/tst/features/myapplication.feature",
glue={"stepdefinition"},dryRun = false)
public class Runner {
}

step definition:

public class test1 {

    WebDriver driver=new ChromeDriver();

    @Given("^open firefox and start app$")
    public void open_firefox_and_start_app(){
        System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
        System.out.println("worked");
    }

    @When("^enter details$")
    public void enter_details(){
        driver.navigate().to("hi5.com");
    }
    @Then("^login happens$")
    public void login(){
        driver.findElement(By.xpath("//input[@id='signInBtn'][@tabindex='3']"));
    }
}

I had TestNG and Junit libraries first, then i removed TestNg and same result. I tried with various path for @CucumberOptions(features=... ) and still it says:

0 Scenarios
0 Steps
0m0.000s

Could you advise, as I cannot find a way to fix it

3
  • 2
    Have you tried the relative path "tst/features" or "features"? Nov 20, 2017 at 8:37
  • Could you please post your myapplication.feature file.
    – SubOptimal
    Nov 20, 2017 at 10:28
  • Feature: test Scenario: login Given open firefox and start app When enter details Then login happens it;s in the first lines written, i cannot format right sorry (it;s in the initial comment) Nov 20, 2017 at 11:02

2 Answers 2

0

Maybe you could start with this simple project and then check where are the differences in yours. It could be a typo in the path, or something else we cannot know based on your provided input.

assume following structure

/tmp/cuke/tst/features/myapplication.feature
/tmp/cuke/src/test/java/runnerPackage/Runner.java
/tmp/cuke/pom.xml

myapplication.feature

Feature: test
    Scenario: login
        Given open firefox
        And start app
        When enter details
        Then login happens

Runner.java

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

@RunWith(Cucumber.class)
@CucumberOptions(
    features="/tmp/cuke/tst/features/myapplication.feature",
    glue={"stepdefinition"},
    dryRun = false
)
public class Runner {
}

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</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>2.1.0</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

run the Cucumber runner Runner

cd /tmp/cuke
mvn test -Dtest=Runner

results in

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running runnerPackage.Runner

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.021s
...

edit Based on the provided Eclipse project. The tests are supposed to be executed by TestNG. Therefor Cucumber runner must extend cucumber.api.testng.AbstractTestNGCucumberTests

assume following structure

/tmp/cuke/src/test/java/runnerPackage/RunnerTest.java
/tmp/cuke/features/myapplication.feature
/tmp/cuke/pom.xml

myapplication.feature

Feature: test
    Scenario: login
        Given open firefox
        And start app
        When enter details
        Then login happens

RunnerTest.java

package runnerPackage;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(features = "features")
public class RunnerTest extends AbstractTestNGCucumberTests {
}

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</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>2.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>2.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <surefire.version>2.18.1</surefire.version>
    </properties>
</project>

run the test

cd /tmp/cuke
mvn test

results in

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running runnerPackage.RunnerTest
Configuring TestNG with:
org.apache.maven.surefire.testng.conf.TestNG652Configurator@6bf2d08e

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.018s
...
14
  • thanls for the answer, the thing is i'm not using mavem, to follow your example..i'll give it againa good look, i fallowed an online tutorial (youtube.com/watch?v=Vv7hHrVX_Zg) ...and did almost everything the same Nov 20, 2017 at 14:13
  • in my feature files for "GIVE" i have no error for "When"&"Then" >>> step 'enter details' does not have a matching glue Nov 20, 2017 at 14:21
  • in the failure trace it says: java.lang.IllegalArgumentException: Not a file or directory: C:\workspace\tst\features\myapplication.feature at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:54) Even if i change the feature to the right path it still gives same error message, for the same erroneous path Nov 21, 2017 at 13:21
  • regardless of what i specify within the feature property it always gives error: java.lang.IllegalArgumentException: Not a file or directory:C:\workspace\tst\features\myapplication.feature Nov 21, 2017 at 13:40
  • i've downloaded latest jars, now it says: java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.formatter(Ljava/lang/ClassLoader;)Lcucumber/api/formatter/Formatter; Nov 21, 2017 at 14:22
0

Please Remove the option dryRun = false

Thanks

1
  • 1
    It can be really helpful if you can elaborate on why you think that this would work.
    – apines
    Apr 25, 2020 at 13:48

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.