I am supposed to migrate on Cucumber. I do have project framework with Selenium, TestNG with Data Driven Framework, Maven. I am exploring Cucumber feasibility with TestNG annotation.
My question is, How we can create connection between @Test method and Step definition of cucumber. Let's example our code is written in @BeforeClass, @Test, @AfterClass method. So how we can migrate with Step definition.
Feature File :
Feature: Is it Friday yet?
Everybody wants to know when it's Friday
Scenario: Sunday isn't Friday
Given today is Sunday
When I ask whether it's Friday yet
Step Definition:
@Given("^today is Sunday$")
public void today_is_Sunday() {
// Write code here that turns the phrase above into concrete actions
System.out.println("this is demo1");
}
@When("^I ask whether it's Friday yet$")
public void i_ask_whether_is_s_Friday_yet() {
// Write code here that turns the phrase above into concrete actions
System.out.println("this is demo2");
}
Class Exection:
@CucumberOptions(features = "cfeature/firstDemo.feature", glue = { "mytest/Stepd" })
public class demo01 extends AbstractTestNGCucumberTests {
private TestNGCucumberRunner tcr;
@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
tcr = new TestNGCucumberRunner(this.getClass());
}
@Test(groups="cucumber", description="Runs CucumberFeature")
public void testdemo() {
System.out.println("Hello");
}
@AfterClass(alwaysRun = true)
public void afterClass() {
tcr.finish();
}
}
Console:
Hello
[33mUndefined scenarios:[0m
[33mcfeature/firstDemo.feature:4 [0m# Sunday isn't Friday
1 Scenarios ([33m1 undefined[0m)
5 Steps ([33m5 undefined[0m)
0m0.073s
You can implement missing steps with the snippets below:
As of now, @Test annotation is calling. But, How to replace it with Step Definition. Please assist.