博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cucumber Hooks
阅读量:2386 次
发布时间:2019-05-10

本文共 4923 字,大约阅读时间需要 16 分钟。

http://www.itpub.net/thread-1626060-1-1.html

https://github.com/cucumber/cucumber/wiki/tags

https://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/

https://github.com/cucumber/cucumber/wiki/Hooks

Hooks

在很多情况下,我们需要在每个scenario之前(before)和之后(after)执行某些相同的操作。比如说在测试完成后要关闭浏览器。在Cucumber中,我们可以使用hooks. 在Cucumber中,有三种不同的hooks:


  Before:     在每个scenario前执行

  After:       在每个scenario后执行

  AfterStep: 在每个scenario后执行


我们可以把这些hooks放在features文件夹下面的任何ruby文件里面,但一般推荐的做法是把它们放在features/support/hooks.rb 文件里,这样让我们更容易记住我们的代码放在哪。


另外,Hooks可以被定义任意次。如果在每个scenario之前有十件不同的事需要我们去处理,我们可以定义十个Before 钩子(hooks),他们会按定义的顺序去执行。


当我们有很多个hooks时,我们有时候可能不需要让它们全部运行,这时候我们就可以使用标签钩子(tagged hooks).

Tags

Eddie Curtis edited this page on 31 May 2017 · 

 Pages 77

Clone this wiki locally

Tags are a great way to organise your features and scenarios. Consider this example:

@billingFeature: Verify billing  @important  Scenario: Missing product description  Scenario: Several products

A Scenario or feature can have as many tags as you like. Just separate them with spaces:

@billing @bicker @annoyFeature: Verify billing

Tag Inheritance

Any tag that exists on a Feature will be inherited by ScenarioScenario Outline or Examples.

Running a subset of scenarios

You can use the --tags option to tell Cucumber that you only want to run features or scenarios that have (or don’t have) certain tags. Examples:

cucumber --tags @billing            # Runs both scenarioscucumber --tags @important          # Runs the first scenariocucumber --tags ~@important         # Runs the second scenario (Scenarios without @important)cucumber --tags @billing --tags @important    # Runs the first scenario (Scenarios with @important AND @billing)cucumber --tags @billing,@important           # Runs both scenarios (Scenarios with @important OR @billing)

(Another way to “filter” what you want to run is to use the file.feature:line pattern or the --scenario option as described in ).

Tags are also a great way to “link” your Cucumber features to other documents. For example, if you have to deal with old school requirements in a different system (Word, Excel, a wiki) you can refer to numbers:

@BJ-x98.77 @BJ-z12.33Feature: Convert transaction

Another creative way to use tags is to keep track of where in the development process a certain feature is:

@qa_readyFeature: Index projects

Tags are also used in Tagged , which let you use tags to define what Before and Afterblocks get run for what scenarios.

Logically ANDing and ORing Tags

As you may have seen in the previous examples Cucumber allows you to use logical ANDs and ORs to help gain greater control of what features to run.

Tags which are comma separated are ORed:

Example: Running scenarios which match @important OR @billing

cucumber --tags @billing,@important

Tags which are passed in separate --tags are ANDed

Example: Running scenarios which match @important AND @billing

cucumber --tags @billing --tags @important

You can combine these two methods to create powerful selection criteria:

Example: Running scenarios which match: (@billing OR @WIP) AND @important

cucumber --tags @billing,@wip --tags @important

Example: Skipping both @todo and @wip tags

cucumber --tags ~@todo --tags ~@wip

You can use this tag logic in your  as well.

This feature was originally added in version 0.4.3. The logical behaviour of tags was later reversed in version 0.6.0.

Overriding the tag filters from a profile

It is currently not possible to override the tag filters from a profile.

The default profile, for example, includes a --tags ~@wip filter. But what if you want to use everything from the default profile except the --tags ~@wip portion?

You might think you could just append something like this to the command line to “undo” the --tags from the profile: --tags @wip,~@wip (anything either tagged with @wip or not tagged with @wip)

But because that is effectively doing an “and” between --tags ~@wip and --tags @wip,~@wip, it doesn’t match any scenarios.

How can we override the tag filter then?

Tag limits and WIP

If you’re following Kanban principles, you want to limit the work in progress (WIP). The idea is that the fewer features or scenarios that being worked on simultaneously, the quicker you’ll be able to implement new features.

Cucumber can enforce this using tag limits. Here is an example:

cucumber --tags @dev:2,@qa:3

This will make cucumber fail if you have more than 2 @dev tags or more than 3 @qa tags, even if each of your scenarios pass individually.

Used in conjunction with the --wip switch you can set up your project to enforce the WIP limits of your team.

Special Tags

@allow-rescue: Turns off Cucumber’s exception capturing for the tagged scenario(s). Used when the code being tested is expected to raise and handle exceptions.

@javascript: Uses a javascript-aware system to process web requests (e.g., Selenium) instead of the default (non-javascript-aware) webrat browser.

@no-txn: Turns off transactions. See .

转载地址:http://iqjab.baihongyu.com/

你可能感兴趣的文章
Nagios飞信linux系统免费短信报警配置
查看>>
mysql proxy 笔记
查看>>
mysql负载均衡笔记
查看>>
文件共享
查看>>
lighttpd 笔记
查看>>
lighttpd,nginx,apache的性能负载比较
查看>>
纯真ip数据库查询的php实现(补充分组查询)
查看>>
sql server数据库的复制
查看>>
MySQL主从备份
查看>>
使用全新的Linux ReiserFS文件系统
查看>>
centos5.2挂载reiserfs文件系统
查看>>
nginx 加速网站
查看>>
cdn应用研究
查看>>
新浪互联星空网站的体系结构(4000万动态pv-6台服务器)
查看>>
著名网站系统架构设计
查看>>
修改常见服务器的banner
查看>>
面向站长和网站管理员的Web缓存加速指南[翻译]
查看>>
mogilefs学习笔记
查看>>
小布老师 LoadRunner系列培训视频
查看>>
Linux系统内核网络参数的意义及应用
查看>>