Cucumber语法及测试用例<一>
工作原因,最近一直在研究cucumber的 语法以及它和java之间的关系。鉴于是初学者且代码基础薄弱,我开始摸索前行,感谢分享博客且也在一路前行的人儿们。
一、cucumber简介
1、介绍:
cucumber是一种可以使用文本描述语言来执行自动测试用例的工具,使用的语言叫做Gherkin.
Gherkin用于描述软件的行为而不需要了解具体的实现,使用Gherkin主要有两个目的文档和自动测试用例(我们希望能够和手工测试用例也统一)。Gherkin支持超过40种语言,包括英文、中文。Gherkin可以在任何地方新增注释,注释以#开头,每一个文件都是已.feature结尾,在feature文件中输入功能描述、场景、步骤,当执行这个功能时每一个步骤都需要编写ruby代码块来实现具体的功能,当前cucumber支持多种语言,除了ruby还可以使用java、javascript来编写具体定义层的实现。
2、关于Feature
每一个feature文件就是一个模块功能(如登录,注册:login.feature,此处为一个公共方法),Feature之后的描述作为标记整个ticket或者story也或者说是一个项目小模块的功能概述(如:这是一个增加、编辑功能),Scenario(场景),一个feature中可以有多个Scenario,每个Scenario包含一个到若干个step,步骤使用Given、When、Then、But、And这些关键词进行步骤连接。在执行测试用例时我们一般是从上到下进行执行(如:feature/Given 出错则一定会给出对应处的提示)
3、Step denfinitions 定义
在项目Feature中,每一个step(given when then)都有一个 step denfinition 来进行方法定义。一般来说我们可以通过自动的方式生成step definition,具体操作你点击Run查看 log栏下拉可看到报错信息中含有,然后拷贝好方法到指定的step definition中进行code 编写即可。
二、cucumber具体实现
1、基本语法为:此处举例两种区别一看即知->
1)简单一点
Scenario
Given
When
Then
2)复杂一点
Scenario
Given
When
And
And
Then
And
3)释义
Feature:用来描述我们需要测试的模块,模块1,2,3...
Scenario: 用来概述功能测试点 如:add/delete
Given:前置条件,比如用户在哪个页面进行操作?
When: 描述用户操作的执行动作,比如click/save
Then: 断言 表示执行的结果
But-一个步骤中如果存在多个Then操作,第二个开始后面的Then可以用But替代(注意是可以,也可以用Then)
2、写测试用例范本
1)、Scenario:start new workflow step 1/3 ---一个功能,如登录,注册,类似于功能总结为步骤的第一步
Given choose a valid workflow --此处给出一个前提条件,和我们testcase一样的原理,可以有多个前提条件
When click"Start New" button --此处为动作,动作可以有多个如上第二个语法例子
Then widow prompt:Are you sure you want to start workflow for current responsible?---测试的预期结果,比如现象是什么样。此处在代码中可以使用断言 2)、Scenario:start new workflow step 2/3--一个功能的总结步骤的第二步
Given start new work flow --同上
When choose "Yes" --同上
Then the workflow was started --同上 3)、Scenario:cancle new workflow step 3/3 --一个功能总结步骤的第三步骤
Given start new work flow --同上
When choose "No" --同上
Then cancle the current window--同上
3、Scenario Outline 使用:
If there are many examples, this becomes tedious. We can simplify it with a Scenario Outline:
Scenario Outline: feeding a suckler cow
Given the cow weighs <weight> kg
When we calculate the feeding requirements
Then the energy should be <energy> MJ
And the protein should be <protein> kg Examples:
| weight | energy | protein |
| 450 | 26500 | 215 |
| 500 | 29500 | 245 |
| 575 | 31500 | 255 |
| 600 | 37000 | 305 |
4、background
Occasionally you'll find yourself repeating the same Given steps in all of the scenarios in a feature file. Since it is repeated in every scenario it is an indication that those steps are not essential to describe the scenarios, they are incidental details.
You can literally move such Given steps to the background by grouping them under a Background section before the first scenario:
Background:
大意为:如果有多个案例中存在重复的given and ,可以使用backfround进行替换
Given a $100 microwave was sold on 2015-11-03
And today is 2015-11-18
5、Data Tables
Data Tables are handy for passing a list of values to a step definition:
Given the following users exist:
| name | email | twitter |
| Aslak | aslak@cucumber.io | @aslak_hellesoy |
| Julien | julien@cucumber.io | @jbpros |
| Matt | matt@cucumber.io | @mattwynne |
Just like Doc Strings, Data Tables will be passed to the Step Definition as the last argument.
The type of this argument will be DataTable. See the API docs for more details about how to access the rows and cells.
签名:知识靠的是累积,我只是担心年纪大了,会忘事儿Cucumber语法及测试用例<一>的更多相关文章
- Cucumber语法格式
@login Feature: Login @T1 Scenario: Login with correct credentail Given I open login page When I ent ...
- Robot Framework(七)创建用户关键字
2.6创建用户关键字 关键字表用于通过将现有关键字组合在一起来创建新的更高级别关键字.这些关键字称为用户关键字,以区别于 测试库中实现的最低级库关键字.创建用户关键字的语法与创建测试用例的语法非常接近 ...
- 1.AngularJS初探
1.需要什么前端开发环境 1)代码编辑工具 webstorm 2)断点调试工具 chrome插件Batarang 3)版本管理 tortoiseGit 4)代码合并和混淆工具 grunt-contri ...
- Robot Framework测试框架学习笔记
一.Robot Framework框架简介 Robot Framework是一种基于Python的可扩展关键字驱动自动化测试框架,通常用于端到端的可接收测试和可接收测试驱动的开发.可以 ...
- robotframework笔记16
发布处理具有相同名称的关键字 使用机器人框架要么是关键词 图书馆 关键字 或 用户的关键字 . 前来自 标准 库 或 外部库 ,后者 中创建相同的文件在使用或进口 资源文件 . 许多关键字使用时,是很 ...
- robotframework笔记14
创建用户关键字 关键字表是用于创建新的更高层次的关键词 结合现有的关键词. 这些关键字被称为 用户 关键字 区分他们的最低水平 库关键字 实现在测试库. 的语法创建用户 关键词非常接近的语法创建测试用 ...
- Jenkins 自动化测试
学习 Jenkins 自动化测试的系列文章 Robot Framework 概念 Robot Framework 安装 Pycharm + Robot Framework 环境搭建 Robot Fra ...
- UniEAP UTF 用户手册 (引擎)
目录 第1章 概述 5 1.1 术语解释 5 第2章 测试文件组织 6 2.1 测试执行文件详解 7 2.1.1 参数配置 7 2.1.2 测试报告配置 9 2.1.3 浏览器类型配置 9 2.1.4 ...
- Cucumber(2)——目录结构以及基本语法
目录 回顾 HelloWorld 扩展 回顾 在上一节中,我大致的介绍了一下cucumber的特点,以及基于ruby和JavaScript下关于cucumber环境的配置,如果你还没有进行相关的了解或 ...
随机推荐
- 用shebang编写一个ssh自动登陆脚本
单例模式是软件开发中非常普遍的一种模式.它的主要作用是确保系统中,始终只存在一个类的实例对象. 这样做的好处有两点: 1.对于需要频繁使用的对象,在每次使用时,如果都需要重新创建,并且这些对象的内容都 ...
- jd-gui报错INTERNAL ERROR 解决办法
问题:我用dex2jar工具反编译了apk文件,但当我用jd-gui反编译前面操作获得的jar文件的时,能很完美地看到大部分类反编译后的代码,但有一部分类不能显示出来--constants类,仅仅显示 ...
- PHP比较操作符详解(转自hack58)
php的比较操作符有==(等于)松散比较,===(完全等于)严格比较,这里面就会引入很多有意思的问题. 在松散比较的时候,php会将他们的类型统一,比如说字符到数字,非bool类型转换成bool类型, ...
- 在chrome 总调试cordova出现Detached from the target. Remote debugging has been terminated with reason: Connection lost. Please re-attach to the new target
在chrome 总调试cordova出现如下错误: "Detached from the target. Remote debugging has been terminated with ...
- HTML的文本格式化
文本格式化:<html> <body> <b>This text is bold</b> <br /> <strong>This ...
- JavaScript中的arguments,callee,caller
在提到上述的概念之前,首先想说说javascript中函数的隐含参数: arguments: arguments 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...
- kylin(一): 原理架构
由eBay开源的一个大数据OLAP框架,2014年11月加入了Apache,项目名字也改成了"Apache Kylin",Apache Kylin是唯一来自中国的Apache顶级开 ...
- file_get_contents()函数
$data = file_get_contents('http://www.zgjmwl.com/jinshui/pro_one/ceshi_a.php'); var_dump(substr($dat ...
- 要用于尝试,广东移动间接实现“流量不清零”[bubuko.com]
拥有1亿用户的广东移动在推出流量共享后,推出4G套餐外流量的“自动升档”服务,每月根据客户消费情况动态自动匹配当月最恰当的一档流量资费.未来,还将推出“流量转赠”服务,用不完的流量可转赠给其他用户. ...
- Mapcontrol 遍历所有图层方法
mapcontrol 遍历所有图层方法 2011-04-29 19:51 通过IMap中的get_layers()可以遍历MapControl中当前的图层.此方法可以通过指定UID对图层进行过滤或者分 ...