Cucumber

问题:featrue 文件里面的Description关键字用法?

Feature: 功能

Scenario:场景

Given  前提

When 动作

Then 结果

 

环境的搭建?

自动化框架的学习网站:国外的
https://www.toolsqa.com/
https://www.toolsqa.com/cucumber-tutorial/
搭建cucumber环境的网站:


https://www.toolsqa.com/cucumber/download-cucumber-jvm-eclipse/

官网上各个版本都试了一下,最终用maven下载以下版本,环境搭建成功

cobertura-2.1.1
cucumber-core-1.2.5
cucumber-java-1.2.5
cucumber-junit-1.2.5
cucumber-jvm-deps-1.0.5
cucumber-reporting-3.10.0
gherkin-2.12.2
junit-4.12
mockito-all-2.0.2-beta

 

目录结构

 

 

 

 MAVEN 依赖

<?xml version="1.0" encoding="UTF-8"?>
<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>cucumberMaven</groupId>
    <artifactId>cucumberMaven</artifactId>
    <version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.0.3</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.cobertura</groupId>
        <artifactId>cobertura</artifactId>
        <version>2.1.1</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.10.0</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>2.0.2-beta</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>


    </dependency>
</dependencies>

</project>

 

feature 定义

Feature: pay for the product
  Scenario: pay money to the factory
    Given  I have a lot of money
    When  I take much money to you
    Then  I can be very poor
Feature: pay for the product
  Scenario: pay money to the factory
    Given  I have a lot of money
    When  I take much money to you
    Then  I can be very poor

 

step定义

package  Tests;
import cucumber.api.java.en.*;

public class stepDefinition {

    @Given("^I am on the website$")
    public void preAddition() throws Throwable {
        // Write code here that turns the phrase above into concrete actions

        System.out.println("I am on the website");
    }

    @When("^input the right username and the right password$")
    public void actionInput() throws Throwable {

        System.out.println("input the right username and the right password");

    }

    @Then("^I can go to homePage$")
    public void i_can_go_to_homePage() throws Throwable {

        System.out.println("I can go to homePage");

    }

}

 

runner.java

package runner;

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

@RunWith(Cucumber.class)
@CucumberOptions(
//feature所在的文件夹
features = {"src\\test\\resources\\features"},
//java step代码定义的package路径,这里是相对路径
glue = {"Tests"},
//美化报告格式
format = {"pretty","html:target/cucmber"}
)

public class TestRunner {
}

运行机制

 

 

 

step table

scneraial outline 区别

 

posted @ 2020-04-25 12:21  ChenduLaoWang  阅读(728)  评论(0)    收藏  举报