feature文件
1. Feature
用来描述我们需要测试的模块,如登录模块
2. Scenario
用来概述功能测试点,如登录功能接口.登录验证功能接口
3. Given
前置条件,比如用户已有账号,用户在哪个页面进行操作?
4. When
描述用户操作的执行动作,比如请求某个api
5. Then
断言 表示执行的结果
6. And
一个步骤中如果存在多个Then操作,第二个开始后面的Then可以用And替代(注意是可以,也可以用Then),使用but比起when仅仅是让语义阅读起来更好理解
7. But
测试中效果与And一样
8. Scenario outline
与Examples配合使用,测试Examples每一行数据
9. Examples
定义测试数据表,第一行是字段名,与Given,When,Then里参数一一对应
10. background
如果有多个案例中存在重复的given and ,可以使用backfround进行替换,就是提前公共部分,例如
11. 井号#
注释
#语句中参数写法
Feature: faceBook login
Scenario Outline: Login functionality for a social net working site.
Given user navigates to Facebook
When I enter Username as "<username>"
And Password as "<password>"
Then login should be unsuccessful
Then check status "<status>"
Then check msg "<msg>"
@test1
Examples:
|Scenario | username | password | msg | status |
|test1 | a | 123456 | success | 0000 |
|test2 | b | 123456 | success | 0000 |
|test3 | b | 123456 | | 0000 |
|test4 | b | 123456 | null | 0000 |
@test2
Examples:
|Scenario | username | password | msg | status |
|test1 | ac | 123456 | success | 0000 |
|test2 | bc | 123456 | success | 0000 |
|test3 | bx | 123456 | | 0000 |
|test4 | bc | 123456 | null | 0000 |
@test3
@test1
Examples:
|Scenario | username | password | msg | status |
|test1 | acv | 123456 | success | 0000 |
|test2 | bcb | 123456 | success | 0000 |
|test3 | bvc | 123456 | | 0000 |
|test4 | bvn | 123456 | null | 0000 |
步骤定义类
1. @Given,@When,@Then
与feature里的步骤一一对应
2. @And@But
与上一个@注解相同的意思
3. 传参,参见官网
运行文件
1. @RunWith(Cucumber.class)
指明这是Cucumber测试运行文件