在动态步骤定义中使用表

时间:2018-06-11 18:09:36

标签: selenium automated-tests cucumber watir qa

我的功能文件包含这样的步骤

When user login with credentials
|username|password|
|blahblah|blahblah|

但是我想在动态步骤定义中使用这一步。可能吗?我试图做这样的事情

step 'user login with credentials
    |username|password|
    |blahblah|blahblah|'

或创建并传递哈希。到目前为止无法使其发挥作用。

1 个答案:

答案 0 :(得分:0)

https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions#calling-steps-with-multiline-step-arguments

使用多行步骤参数调用步骤

有时您想调用一个旨在采用多线步骤参数的步骤,例如:

# ruby
Given /^an expense report for (.*) with the following posts:$/ do |date, posts_table|
  # The posts_table variable is an instance of Cucumber::Ast::Table
end

这可以通过这样的纯文本步骤轻松调用:

# feature
Given an expense report for Jan 2009 with the following posts:
  | account | description | amount |
  | INT-100 | Taxi        |    114 |
  | CUC-101 | Peeler      |     22 |

但是如果你想从步骤定义中调用它呢?有几种方法可以做到这一点:

# ruby
Given /A simple expense report/ do
  step "an expense report for Jan 2009 with the following posts:", table(%{
    | account | description | amount |
    | INT-100 | Taxi        |    114 |
    | CUC-101 | Peeler      |     22 |
  })
end

或者,如果您更喜欢更具程序性的方法:

# ruby
Given /A simple expense report/ do
  step "an expense report for Jan 2009 with the following posts:", table([
    %w{ account description amount },
    %w{ INT-100 Taxi        114    },
    %w{ CUC-101 Peeler      22     }
  ])
end