来自Cucumber Java TestNG的片段看起来很奇怪
问题描述:
我正在为我的Selenium Java + TestNG项目尝试Cucumber。 一旦我用空的stepdefinition运行.feature文件,我应该得到一个片段,我可以将粘贴复制到我的步骤定义类。但是我得到了一种奇怪的格式,不能用于开箱即用。来自Cucumber Java TestNG的片段看起来很奇怪
Given
应该是@Given
,对吧? 没有public void()
。
可能是什么原因?谢谢。
2 Scenarios (2 undefined)
5 Steps (5 undefined)
0m0.000s
You can implement missing steps with the snippets below:
Given("^User is on Home Page$",() -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
When("^User enters UserName and Password$",() -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^He can visit the practice page$",() -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
When("^User LogOut from the Application$",() -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^he cannot visit practice page$",() -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
这是我glue file
package glue;
import java.io.IOException;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import cucumber.api.testng.TestNGCucumberRunner;
@Test(groups = "cucumber")
@CucumberOptions(features = "C:\\Users\\workspace\\cucumber\\src\\test\\java\\feature\\logintest.feature",
glue = "C:\\Users\\workspace\\cucumber\\src\\test\\java\\glue\\Glue.java",
plugin = {"html:C:\\Users\\workspace\\cucumber\\logs"})
public class Glue extends AbstractTestNGCucumberTests {
@Test(groups = "cucumber", description = "Runs Cucumber Features")
public void runCukes() throws IOException {
}
}
这是我.feature
文件
Feature: Login
Scenario: Successful Login with Valid Credentials
Given User is on Home Page
When User enters UserName and Password
Then He can visit the practice page
Scenario: Successful LogOut
When User LogOut from the Application
Then he cannot visit practice page
这是我的依赖
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
答
您正在使用黄瓜java8依赖,下面是用于stepDefintion文件格式(请确保您的Java编译器版本应该是1.8)。
@Given注释将在黄瓜的Java
定的注释将在黄瓜java8
import cucumber.api.java8.En;
public class stepDefinitions implements En{
public stepDefinitions(){
Given("^User is on Home Page$",() -> {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test1");
});
When("^User enters UserName and Password$",() -> {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test2");
});
Then("^He can visit the practice page$",() -> {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test3");
});
When("^User LogOut from the Application$",() -> {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test4");
});
Then("^he cannot visit practice page$",() -> {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test5");
});
}
}
我在我的机器其工作执行它,尝试,让我知道,如果它的工作原理为你。