• behave 提供3中step匹配模式
  • 'parse'
  • 'cfparse' 基于parse的扩展,  支持cardinality field syntax?
  • 're' 支持在step中定义正则表达式

'parse'  是默认的step mathcer,  他被使用最多, 有以下特点

  • 上手容易, 易读性好, 好理解
  • 支持预定义的数据类型和用户自定义类型
  • 可以在自定义数据类型中使用re, 在step_impl中隐藏了re, 可读性好

'cfparse' 是parse的扩展, 设计初衷是替代parse, 它有以下特点

  • 继承parse, 支持 the cardinality field syntax
  • 自动创建缺少的类型转换函数for fields with cardinality field part
  • 基于parse_type

're'有以下特点

  • addresses some cases that cannot be solved otherwise (currently)
  • is backward compatible to cucumber (uses regular expressions)
  • is less ambiguous compared to the “parse” matcher (currently)

定义step matcher的两种方法

  • 在environment.py中定义默认的matcher

    # -- FILE: features/environment.py
    from behave import use_step_matcher # -- SELECT DEFAULT STEP MATCHER: Use "re" matcher as default.
    # use_step_matcher("parse")
    # use_step_matcher("cfparse")
    use_step_matcher("re")
  • 在step definition文件中切换step matcher, 同样使用use_step_matcher("re")
    从切换step matcher行后的所有step_impl都使用你切换的step matcher, 除非你再次切换

正则匹配

# 简单的group捕获, 并赋值给P<test>
# -- SIMPLE GROUP: foo
@when(u'I try to match "(?P<foo>foo)"')
def step_when_I_try_to_match_foo(context, foo):
context.foo = foo # -- SIMPLE GROUP: anything else
@when(u'I try to match "(?P<anything>.*)"')
def step_when_I_try_to_match_anything_else(context, anything):
context.anything = anything # 可选的的group: (?P<an_>an )?
@when(u'I try to match (?P<an_>an )?optional "(?P<foo>foo)"')
def step_when_I_try_to_match_an_optional_foo(context, an_, foo):
context.foo = foo
context.an_ = an_ # 套嵌的正则 @when(u'I try to match nested "(?P<foo>foo(?P<bar>bar)?)"')
def step_when_I_try_to_match_nested_foobar(context, foo, bar):
context.foo = foo
context.bar = bar
 

Behave step matcher的更多相关文章

  1. Java Pattern Matcher 正则应用

    转自:http://www.itzhai.com/java-notes-regex-matches-and-lookingat.html#read-more 1.基本语法 2.String内建的正则表 ...

  2. BDD框架:behave学习记录

    本人学习的时候基本上是按照behave的tutorial教程一步步学习的,这篇文章就当Behave教程的翻译版吧(*^__^*) 嘻嘻--. 1         安装behave 安装好python后 ...

  3. 自动化测试:behave

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  4. Behave用户自定义数据类型

    在step句子中, 所有的参数默认是string类型, 如果用户想使用复杂的或者其他数据类型, 就需要了解以下bahave中的数据类型. behave的数据类型转换器是在parse和cfparse中支 ...

  5. Behave 基础

    在你使用behave或其他BDD框架之前, 你应该选择一个断言库. python有很多这方面的第三方库.例如: hamcrest,nose.tools,  should-dsl, sure, comp ...

  6. behave 测试框架,了解一下

    # behave测试框架 [behave](https://pythonhosted.org/behave/)是python的1个bdd测试框架实现. ### 安装 ```pip install be ...

  7. Python+Selenium-BDD框架之behave

    (查看behave具体教程可以访问官网: http://pythonhosted.org/behave/) 1.安装behave 安装好python后,使用 pip install behave命令安 ...

  8. Behave + Selenium(Python) 三

    来自T先生 通过之前的2篇文章,大家都了解了如果利用behave和selenium打开网页和进行基本的操作,但是这些对于项目来说,却是往往不够的. 如果对junit或者TestNG熟悉的人都知道有@B ...

  9. Python behave in BDD

    BDD概念 全称 Behavior-driven development 中文 行为驱动开发 概念 是敏捷软件开发技术的一种,鼓励各方人员在一个软件项目里交流合作,包括开发人员.测试人员和非技术人员或 ...

随机推荐

  1. linux系统编程之信号(七):被信号中断的系统调用和库函数处理方式

        一些IO系统调用执行时, 如 read 等待输入期间, 如果收到一个信号,系统将中断read, 转而执行信号处理函数. 当信号处理返回后, 系统遇到了一个问题: 是重新开始这个系统调用, 还是 ...

  2. Transaction And Lock--使用资源锁来控制并发

    写过程序的朋友都知道,在多线程处理时,对于非线程安全的对象,需用使用锁定特定对象(LOCK)的方法来保证串行操作.曾经有位开发询问我,在SQL Server内部是否有类似的实现方法来控制某一操作不能并 ...

  3. 【加密算法】3DES

    一.简介 3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算 ...

  4. c# list修改某一个属性的值

    public class info() { public string name{get;set;} public string age{get;set;} } list<info> li ...

  5. ASP.NET Core 2 学习笔记(五)静态文件

    之前的ASP.NET网站,只要把*.html.*.css.*.jpg.*.png.*.js等静态文件放在项目根目录,默认都可以直接被浏览:但ASP.NET Core 小改了浏览静态文件的方式,默认根目 ...

  6. WPF MVVM Style中使用事件

    View的Style中设置事件 <Style TargetType="TextBox"> <EventSetter Event="GotFocus&qu ...

  7. PageAdmin CMS网站制作教程实例:如何制作一个报名表?

    PageAdmin CMS网站建设实例:如何制作一个报名表? 有时我们根据需求需要制作一些自定义表,该如何去制作呢? 我们以制作一个报名表为例: 登录后台地址,进入后台, 2.在顶部导航中找到系统,并 ...

  8. Day 9 作业题(完成)

    # 练习题# 1.整理函数相关知识点,画思维导图,写博客 # 2.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者.'''def func1(argv): f ...

  9. python 爬图 helloworld

    最近发现 吾志 上用户的头像都很个性,另外,对于没有把日记设为私密的用户,最后一天的日记是公开的,谁都可以查看. 所以,如果每天把所有可查看的日记爬一遍,那么-- 哈哈 以前对爬虫只是了解一点点,没有 ...

  10. Spring+Mybatis整合时 Failed to read candidate component class,Caused by:IllegalArgumentException

    Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误 org.springframework.beans.factory.B ...