Cucumber cannot find StepDefinitions while running the code but manually using the option “Find Step” can find step definition

天大地大妈咪最大 提交于 2019-12-12 05:14:33

问题


In the project Structure defined like below,

  • src/main/java -- Config (RunCukesTest.java) -- StepDefinitions
  • src/test/resources -- features/login

When I run from RunCukesTest.java using RunAs --> JUnit Test, Step Definitions cannot be found by runner

When I click find Step, opens the right file. Couldn't understand where the issue is because the code was running few days back. File is downloaded from here

https://drive.google.com/open?id=0B4SgyzyvwKhiVTRmRDZuNXNTSjA

Runner class code

package helpers;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
//features= "src/test/resources/features/navigation",

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:features"},
        plugin = {"pretty", "html:target/cucumber-html-report"},
        tags = {"@OnlyOneTime"},
//      dryRun = true,
        monochrome = true
        )
public class RunCukesTest{

}

回答1:


Running it as a Cucumber feature, it works well, but if I provide glue={"stepDefinitions"} and try running it from runner then NullPointerException is thrown,

This problem is arising from hooks not being found. But If I move @Before and @After to the SDLogin classs, then It works well.




回答2:


I figured out your issue, As per your runner class, the glue path is not set. please set glue path.glue={"stepDefinitions"}

package helpers; 
import org.junit.runner.RunWith; 
import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 
//features= "src/test/resources/features"@RunWith(Cucumber.class) @CucumberOptions( 
features = {"classpath:features"}, glue={"stepDefinitions"},plugin = {"pretty", "html:target/cucumber-html-report"}, tags = {"@OnlyOneTime"}, // dryRun = true, monochrome = true ) 
public class RunCukesTest{ }



回答3:


Glue code is supposed to have path to hooks and step definitions

So modified as glue={"helpers","stepDefinitions"} instead of glue={"helpers","classpath/stepDefinitions", "classpath/stepDefinitions.LogIn","classpath/stepDefinitions.Publish"}

Please refer to this link Similar issue on github



来源:https://stackoverflow.com/questions/44106280/cucumber-cannot-find-stepdefinitions-while-running-the-code-but-manually-using-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!