【问题标题】:Using table inside of dynamic step definitions在动态步骤定义中使用表
【发布时间】:2018-11-21 01:23:56
【问题描述】:

我有像这样的步骤的功能文件

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

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

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

或创建并传递一个哈希。到目前为止无法使其工作。

【问题讨论】:

    标签: selenium automated-tests cucumber watir qa


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-23
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多