【问题标题】:Cucumber/Capybara link testing using array and loops使用数组和循环进行 Cucumber/Capybara 链接测试
【发布时间】:2013-02-14 18:13:27
【问题描述】:

我是 cucumber/capybara/ruby 的新手,在 php 构建的网站上尝试 BDD。

检查:

不同的链接将用户引导到正确的页面:“prod-integration-mycompany.com”

情况:

在这个页面上我有一些独特的链接(大约 20 到 50 个),链接看起来像,

<a href= " /edition/123456"> BookTitle 01 by <a class="author" title= "Dan Romio" href=" >/author/Dan+Romio/112212">Dan Romio</a>'

<a href= " /edition/654321"> BookTitle 02 by <a class="author" title= "Maggi Smith" href=" >/author/Maggi+Smith/11332">Maggi Smith</a>

<a href= " /edition/56232"> BookTitle 03 by <a class="author" title= "Dan Romio" href=" >/author/Dan+Romio/112212">Dan Romio</a>
etc…

我要检查的内容:

我想检查用户单击版本链接时,该页面的 与 BookTittle 匹配。我可以一步一步做完

   When ……
       within(:css, 'dd[@id = "(css ID here)"]') do
      click_on '' or click_link (name of the link)
        end 
   end

   Then ………|text|
        check_destination(text)
   end

在 env.rb 上,我有一些函数,例如“check_destination()”和不同的断言:

      def check_destination(paramText)
      new_window = page.driver.browser.window_handles.last
      page.within_window new_window do
            path = URI.parse(current_url)
           assert_include(paramText,path)
        end
      end 

那么?有什么问题?:

问题是当我想做一大堆它们时,我不知道我将如何使用数组的 key=> 值并在我的步骤中循环它们。是桌子吗?是课堂吗?我有点没概念/想法了……有什么想法吗?关联 ?顺便说一句,如果我浪费你的时间,我很抱歉。谢谢。

【问题讨论】:

  • 检查每个链接是否真的有价值(即如果其中一个链接有效,其他链接之一断开的可能性有多大)?
  • @JustinKo:这可能是版本 id 不存在/不存在的情况,或者即使它存在也可能是 redis(缓存)问题。我不会说检查这些链接有很大的价值,但我可以在不同的情况下使用相同的逻辑。谢谢。

标签: ruby arrays hyperlink cucumber capybara


【解决方案1】:

我太笨了.....我可以在节点查找器上使用 page.all,使用选项可以让我做任何我想做的事情。 http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders

    within("within block here") do 
        element = page.all("specify the condition to get all the elements")
        puts element.count  # should provide no of elements
    end

第一个元素可以通过 element[0] 访问。"some method here"

所有方法列表都可以在:http://www.ruby-doc.org/gems/docs/c/capybara-rails-2-2-0.4.1.1/Capybara/Node/Element.html

【讨论】:

    猜你喜欢
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2018-06-06
    • 2014-03-02
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多