How to implement and run cucumber test files using

2019-07-11 03:17发布

Trying to implement selenium + Cucumber + Testng instead of Junit.

My queries are

  1. What is the alternate for @Runwith(Cucumber.class) in testng
  2. How to run the class file which contains the path to feature file

package runner;

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


@CucumberOptions(features="src/main/java/testCases/Cucumber/Login_Cucumber.Feature",glue="")
public class TestRunner extends AbstractTestNGCucumberTests {

}

run with testng/cucumber are not appearing

3条回答
该账号已被封号
2楼-- · 2019-07-11 03:45

Install TestNG Eclipse Plugin. Afterwards you should be able to run TestNG Test.

查看更多
再贱就再见
3楼-- · 2019-07-11 03:46

First of all, Cucumber have .feature files and not test files.

Answer to your first question: 1. What is the alternate for @Runwith(Cucumber.class) in testng? "You don't need @RunWith while running with TestNG"

I didn't understand your second question but you need to understand that Cucumber runs end execute the Runner class by default and you have already defined feature files in @CucumberOptions section.

To make it more clear you can easily implement and Run Cucumber project using TestNG. The whole game is in your pom.xml file and Runner class.

Following detail also explains that you can run each scenario in cucumber as a test using TestNG.

How? It's explained below:

First of all, update your Cucumber Maven dependencies from info.cukes to io.cucumber dependencies

Following Java code in Cucumber Runner Class worked perfectly for me to run each scenario as TestNG test in feature files:

@CucumberOptions(features = "src/test/resources", plugin = "json:target/cucumber-report-feature-composite.json")
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;

@BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}

@Test(groups = "cucumber scenarios", description = "Runs Cucumber 
Scenarios", dataProvider = "scenarios")
public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper 
cucumberFeature) throws Throwable{
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
}
@DataProvider
public Object[][] scenarios() {
    return testNGCucumberRunner.provideScenarios();
}

@AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
    testNGCucumberRunner.finish();
}
 }

Run with mvn clean test command and see the magic :)

I would be happy to see your problem resolved. Please let me know if this issue is still not resolved.

Reference: https://github.com/cucumber/cucumber-jvm/blob/master/testng/README.md

I followed this approach: https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java

查看更多
戒情不戒烟
4楼-- · 2019-07-11 04:03

TestNg uses @CucumberOptions tag to declare parameters

@CucumberOptions(plugin = "json:target/cucumber-report.json")
public class RunCukesTest extends AbstractTestNGCucumberTests {
}

or

@CucumberOptions(features = "src/test/resources/features/Download.feature",
        glue = "uk.co.automatictester.jwebfwk.glue",
        format = {"pretty"})

Check this out: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng

Also a possible dup of :How to integrate the cucumber in testNG?

查看更多
登录 后发表回答