1
votes

I'm very new to cucumber/capybara/ruby, trying BDD on a php-built website.

Checking on:

Different links directs a user to the correct page on : "prod-integration-mycompany.com"

Situation:

on this page I've got some unique links(around 20 to 50) and the links look something like,

<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…

What I want to check:

I want to check when a user clicks on an edition link, the of that page matches BookTittle. I can do it one by one on my steps

   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

on env.rb, I've got some functions like "check_destination()" and different asserts:

      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 

So ? What's the problem ?:

Problem is when I wanna do a whole bunch of them, I don't know how I'm gonna use array's key=> value and loop through them on my steps. Is it Table, is it class, I kind of running out of concept/ideas here…any idea ? link ? And btw sorry if I waste your time. Thanks.

1
Is there actually value in checking each of those links (ie if one of those links works, what is the likelihood that one of the other links breaks)?Justin Ko
@JustinKo: it might be a case of edition id does/does not exist or even if it's exist might be a redis(cache) issue. I wouldn't say a great value in checking those links, but I can use the same logic in different situation. Thanks.RVM

1 Answers

0
votes

I am so so dumb..... I could've just use page.all on node finders, using option will let me do whatever I wanna do. 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

First element can be access by element[0]."some method here"

All the list of method can be found in: http://www.ruby-doc.org/gems/docs/c/capybara-rails-2-2-0.4.1.1/Capybara/Node/Element.html