While I run cucumber tests from IntelliJ IDE, it works perfectly.
However when I try to run it from command prompt, after creating a runner class, the step definitions are not recognized.
Below is how the code looks like:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
glue={"classpath:src\\test\\java"},
features = "src\\test\\resources",
plugin={"pretty","html:target/site/cucumber-pretty","json:target/cucumber.json"})
public class RunCucumberTests {
}
Below is how the project structure looks like. The 'LoginSeps' class contains the step definitions.
The error which is thrown is as below
[ERROR] Tests run: 5, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 0.79 s <<< FAILURE! - in RunCucumberTests [ERROR] Login functionality.Login Successful Time elapsed: 0.276 s <<< ERROR! io.cucumber.junit.UndefinedStepException: The step 'I am in the login page of application' and 2 other step(s) are undefined.....
Any help is much appreciated.
CodePudding user response:
Stepdefiniton
classes should always reside in a package and under src\test\java
folder.
Please create a package cucumberStep
or something and move the class LoginSteps
under that.
Code:
@CucumberOptions(features = "src\\test\\resources\\features", glue = { "cucumberStep", }, dryRun = false, plugin = { "pretty",
"html:report/TestReport.html", }, monochrome = true, stepNotifications = true, tags = "@Regression")
CodePudding user response:
The issue got resolved with a bit of refactoring.
Moving the step definitions class to a new package and referring the package name in the glue resolved the issue.
Below is how the solution looks now.