【问题标题】:Can't implement two step definitions individually in cucumber无法在黄瓜中单独实现两个步骤定义
【发布时间】:2017-06-05 04:20:45
【问题描述】:

我正在使用黄瓜和红宝石实现自动化。我的场景如下。

Given I'm on home page
When i click on links
Then it should redirect to corresponding pages.

为了实现,我已经完成了迭代,以单击第二步中的所有链接。

为此,我每次都必须返回主页然后进行验证。我是否必须每次都重复第二步实现,还是可以跳过第三步并在第二步中实现所有内容?

【问题讨论】:

    标签: ruby selenium cucumber watir


    【解决方案1】:

    您可以在表格中执行以下操作:

      Background: Member should open homepage
          Given member goes to home page
    
      @javascript
      Scenario: Member should go to correct url by clicking links in head menu
         Then member should ensure that links in the table go to correct url
            | Spor Giyim          | /spor-giyim            |
            | Kadın               | /kadin                 |
            | Erkek               | /erkek                 |
            | Ayakkabı & Çanta    | /ayakkabi-canta        |
    

    Ruby 部分应该是这样的:

    When(/^member should ensure that links in the table go to correct url$/) do |table|
        # table is a Cucumber::Core::Ast::DataTable
        links = table.raw
    
        links.each do |line|
            link       = line[0]
            target_url = line[1]
    
            click_link(link)
    
            url = page.current_url
            expect(url).to include target_url 
        end
    end
    

    【讨论】:

    • 谢谢。现在就试试这个。
    【解决方案2】:

    我喜欢稍微不那么强制性的方法:

    Given I am on home page
    When I collect a list of links and the text from the header menu
    Then visiting each link should return a page where the title matches the link text
    

    或者它可能匹配 alt 文本,或者你匹配 URL 或类似的东西。我认为上面显示的命令式方法使得添加到页面的新项目不会被检查,任何脱落的东西都会被检查。

    如果您想让它更具必要性并有一个列表,我会验证只有那些链接显示,并且如果新链接意外显示,它会引发错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多