您可以使用下面的代码片段执行缺少的步骤

时间:2018-07-05 12:03:32

标签: maven junit cucumber

>## This my Pom.xml file structure ##
<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>com.cucumberExcecise</groupId>
    <artifactId>Cucumber_Practice</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

## Feature File:##
Feature: Login Feature
Scenario: Login as a authenticated user
   Given User is on Home Page
**Step Definition code:**
@Given("User is on Home Page$")
    public void user_is_on_homepage() {
        // Write code here that turns the phrase above into concrete actions
        System.setProperty("webdriver.chrome.driver", "E:\\Downloads\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://sample.com");
    }
**Runner Class:**
@RunWith(Cucumber.class)
@CucumberOptions(strict = true,features = "src/test/resources/featureFiles/sample.feature", glue = {
        "src/test/java/com/stepDefinitions/Step.java" })

public class TestRunner {

}

**Whenever running Runner class its showing below error:**

1 Scenarios ([33m1 undefined[0m)
1 Steps ([33m1 undefined[0m)
0m0.000s

您可以使用以下代码片段执行缺少的步骤:

    @Given("^User is on Home Page$")
    public void user_is_on_Home_Page() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

1 个答案:

答案 0 :(得分:0)

在您的Testrunner类中,您必须放置一些东西,或者它具有某些注释(该类本身为空)

您必须知道Feature文件在哪里以及step文件在哪里(.java文件,在“胶水”中)

您还可以指定标签(然后使用@something注释功能或场景以运行它们) 还有其他一些选项可以处理报告等问题。

一个例子是:

package steps;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/"
        , monochrome = false
        , format = { "pretty", "html:target/results" }
        , glue = { "steps" }
        , strict = true
        , tags = {"@RT-interact"}
)
public class TestRunner {
}

http://www.automationtestinghub.com/cucumber-test-runner-class-junit/等许多教程可在其中找到更多信息。