Selenium - Cucument JUnit Test Runner - 没有得到注释

时间:2017-05-30 10:29:21

标签: selenium cucumber-junit cucumber-java

我是Selenium Cucumber的新手,尝试使用Eclipse设置基本的Selenium Cucumber JVM,但是当我将Testrunner作为JUnit运行时,缺少注释,我需要在步骤定义中手动添加测试步骤。以下是我的功能& 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执行时,代码段缺少注释,因此需要手动编写步骤定义 1场景(1未定义) 4个步骤(4个未定义) 您可以使用以下代码段实现缺少的步骤:

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>

1 个答案:

答案 0 :(得分:0)

可能是因为您正在使用Java 8 lambda样式步骤定义。在Java 8样式步骤定义中,不需要@符号。这也不是问题。您可以运行该脚本,但不会影响执行。有关详细信息,请查看链接https://cucumber.io/docs/reference/jvm