【发布时间】:2017-10-30 18:45:07
【问题描述】:
我是 Selenium Cucumber 的新手,尝试使用 Eclipse 设置基本的 Selenium Cucumber JVM,但是当我将 Testrunner 作为 JUnit 运行时,注释丢失,我需要在步骤定义中手动添加测试步骤。下面是我的 Feature & JUnit 测试运行器
Feature: Gmail Login
@Scenario1
Scenario: User logs into GMail
Given Open Browser
When Enter gmail link
Then Enter login details
TestRunner.java
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\XXXX-PATH\\Feature"
,glue={"stepDefinition"},
tags={"@Scenario1"},
monochrome=true
)
public class TestRunner {
}
当我将TestRunner.java 作为 JUnit 执行时,sn-p is missing annotation,因此需要手动编写步骤定义
1 个场景(1 个未定义)
4 个步骤(4 个未定义)
您可以使用下面的 sn-ps 实现缺少的步骤:
Given("^Open Browser$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
When("^Enter gmail link$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
谁能帮帮我
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cucmber_test</groupId>
<artifactId>cucmber_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_111\bin\javac.exe</executable>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
</dependencies>
</project>
【问题讨论】:
-
那么您面临的实际/真正问题/错误/困难是什么?
JUnit的annotations被 Cucumber 中feature文件中的功能描述替换。谢谢 -
你需要在你的stepDefinition类文件中定义@given和“@when”方法;按照建议复制确切的语法
-
感谢您的回复,我没有得到 testrunner 中建议的确切语法,没有创建 @given,只创建了给定,因此我需要在 StepDefinition 中手动添加 @ 语法。我猜我错过了任何版本
-
在我的功能文件中,我添加了注释,@ 但是在执行测试运行程序时,我没有得到 testrunner 中建议的确切语法,@ 丢失,@given 没有创建,只创建了给定,因此我需要在 StepDefinition 中手动添加@语法。
标签: selenium cucumber-junit cucumber-java