Cucumber是行为驱动测,允许
测试被写成纯文本并且能够转换成自动化.文本被写成业务可读领域语言。行为驱动测试允许如何定义需求和项目开发
通过文字描述测试行为,一方面通过文字描述告诉客户测试是如何进行的,另一方面,通过关键字驱动和正则表达式匹配告诉scripts去做哪些事情。
cucumber结构
/config folder
/features folder
/step_definitions folder
browser_all_inclusive.rb file-step
/support folder
browser_all_inclusive.feature file-Gherkin
cucumber之Gherkin语法
关键字:
Feature
Background
Scenario Scenario outline
Scenarios(or examples)
Given When Then And(or but)
| (which is used to define tables)
""" (which is usde to define multiline strings)
# (which is used for comments)
Feature
文件开头的关键字,不加的话,无法识别cucumber文件
Title(who the feature is for,what the feature is about)
Scenario
Scenario outlines
这个必须和scenarios和Example结合使用,Scenario是从Given开始,Then结束,Sceanrio outline是从Scenarios或Example开始,根据参数的个数决定循环执行多少次Given...Then
Steps
这几个关键字不会影响文件执行的顺序,主要是方便阅读
Given:indicates something that we accept to be true in a scenario
When:indicates the event in a scenario
Then: indicates an expected outcome
场景关键字,每个case单元
When: indicates the event in a scenario
Then: indicates an expected outcome
And
But
tags
示例:
@expedia,@hotel,@starfilter_01
world
Hooks
在每个scenario前后执行的公共操作
Before:Excuted before every scenario
After:Executed after every scenario
AfterStep:Executed after every step
BackGround
这个关键字下面的step会在每个scenario前执行。Hooks在Background前执行,当我们想steps可见,有时用来替代Before hooks。
Tables in steps
tables里面的数据作为哈希的数组存储,可通过hash()方法显示,需要指定执行,,但是Example和Scenarios的数据全部会被遍历到。
|Rank|suit|
| 1 | A |
| 2 | B |
| 3 | C |
相当于 hash={"Rank"=>[1,2,3],"suit"=>["A","B","C"]}
查看report
cucumber -f pretty -f html -o report.html test.feature