• 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. FP-Growth in Spark MLLib

    并行FP-Growth算法思路 上图的单线程形成的FP-Tree. 分布式算法事实上是对FP-Tree进行分割,分而治之 首先,假设我们只关心...|c这个conditional transactio ...

  2. 一起学习MVC(2)Global.asax的学习

    在Global.asax.cs文件中        protected void Application_BeginRequest(Object sender, EventArgs e)  {     ...

  3. C#一些代码小结--文件对话框

    C# 一些代码小结--文件对话框 查看文件完整路径 try { Config cfg = new Config(); var file = ""; if (saveFileDial ...

  4. 在MUI框架中使用video.js插件,并在暂停的时候利用Asp.net将观看时长保存到sqlserver数据库

    本次保存数据的情况有三种: 在视频播放的时候点击暂停,将本视频的进度保存到数据库 利用mui内部的控件,返回上一页操作时,进行保存 安卓手机触发返回键的时候,进行保存 示例一: 在video标签上面添 ...

  5. 使用css保持一定宽高比例

    需求描述:移动端实现横跨页面半圆.(类似问题,实现4x4的正方形网格) 简化问题,我们可以理解为实现一个高度和宽度比为1:2的块. 需要解决问题: 1,高度和宽度按照一定比例. 2,外容器高度和宽度不 ...

  6. Day44 数据库的操作

    视图操作: 1.左连接查询 select * from person left join dept on person.dept_id = dept.did 2. 右连接 3. 内连接  inner ...

  7. 记录初学Spring boot中使用GraphQL编写API的几种方式

    Spring boot+graphql 一.使用graphql-java-tools方式 <dependency> <groupId>com.graphql-java-kick ...

  8. BZOJ3775: 点和直线(计算几何+拉格朗日乘数法)

    题面 传送门 题解 劲啊-- 没有和\(Claris\)一样推,用了类似于\(Shinbokuow\)推已知点求最短直线的方法,结果\(WA\)了好几个小时,拿\(Claris\)代码拍了几个小时都没 ...

  9. SQL执行计划分析2

    执行计划重点关注 type.key.key_len.rows.extra type:type如果为ALL,表示全盘扫描,也是效率最低的 key:表示使用了哪个索引,如果没有使用为null key_le ...

  10. react native 学习之 native modules

    翻译自https://facebook.github.io/react-native/docs/native-modules-ios.html Native Modules 很多情况下,app需要使用 ...