问题
Basically I want the scenario outline to loop through all of the various combinations so that I don't have to write a bunch of scenarios. I want to have it visit the starting page and then check to see if the links are there however I've hit a barrier.
Cucumber feature
Scenario Outline: As a user I need links in order to navigate the site
Given I am a '<user>'
When I am at the <page> page
Then I should see a link to '<link>'
Scenarios: As a user that is not logged in
| user | page | link |
| not_signed_in_user | / | contact |
Cucumber Feature Steps
Given /^I am a 'not_signed_in_user'$/ do
@user = nil
end
When /^I am at the (.+) page$/ do |starting_page|
visit starting_page
end
Then /^I should see a link to (.+)$/ do |link|
pending
end
I need to use something like:
response.should have_selector('a,':href => link_path,
:content => link )
but that won't work dynamically as it will just check for link_path...
回答1:
It sounds like you want to use send("#{link}_path")
here. That would generate the link using the routing helper which I think it is what you want.
来源:https://stackoverflow.com/questions/6810287/creating-dynamic-cucumber-steps-to-check-for-links-on-a-page