Reputation: 1806
The heart of the matter is that within my IDE (IntelliJ), I can right click on an individual .feature file and it runs fine, but does not read any of the parameters from the Runner class. From the command line, it works fine.
mvn clean compile test -Dcucumber.options="--tags @calculator"
I'm using a single framework to handle multiple web apps. So each app is in a separate sub-folder.
+---test
+---java
+---com
+---company
+---app
¦ +---app1
¦ ¦ +---common
¦ ¦ +---page
¦ ¦ +---step
¦ +---app2
¦ +---common
¦ +---page
¦ +---step
+---core
The framework will use PageObject Model so page
will contain each page's details, common
will be for features common across the whole app, and step
is for the Given, When, Then steps.
In the resources folder I have a similar layout
+---resources
+---com
+---company
+---app
+---app1
¦ +---feature files go here
+---app2
+---feature files go here
The runner class is in the main app
folder.
package com.company.app;
import com.company.core.Browser;
import com.company.core._Start;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty",
"html:target/cucumber",
"json:report/report.json",
"com.cucumber.listener.ExtentCucumberFormatter:"
},
tags = {"~@ignore"},
snippets = SnippetType.CAMELCASE
)
public class _RunnerTest extends _Start {
private static String reportFile = "report.html";
private static String configFile = "extent-config.xml";
@BeforeClass
public static void setup() {
// Stuff
}
@AfterClass
public static void teardown() {
// Stuff
}
}
So running via Maven command line, everything works as expected. If I right-click on a .feature file (or a scenario with it) the test(s) will run, but does not use the runner class so there is no report, and the @BeforeClass and @AfterClass are ignored.
Is there something I'm missing?
Upvotes: 2
Views: 2392
Reputation: 13
For running .feature file directly from IDE you should have your stepdefinitions available in same path. If they are not in same path and are separated by packages then you must use Runner file where you can provide path to your glue code and feature files.
Upvotes: 0
Reputation: 3026
When you run the feature file directly, it is not run using the runner. If you want your test to use the @BeforeClass and @AfterClass defined in the runner, you'll have to run the runner.
Also note that although Cucumber supports JUnits @ClassRule
, @BeforeClass
and @AfterClass
annotations, using these is not recommended, as it limits the portability between different runners;
they may not execute correctly when using the commandline or IDE
Instead it is recommended to use Cucumbers Before
and After
hooks.
Upvotes: 3