Check whether link present nor not using cucumber

Hi, I am using cucumber with webrat for testing my application. I have admin role in my application. When admin logs into the system he able to see the "Users" link which gives an interface to manage users for admin. I have written the feature like as follows:-

Feature: List All Users So that Admin can manage users Scenario: Login as Admin When I login with user "username" with password "123456" Then "Users" link should be shown

My Step definition code is like as follows:-

When /^I login with user "([^"]*)" with password "([^"]*)"$/ do |login, password>   visit "/"   fill_in "login", :with=>login   fill_in "password", :with=>password   click_button "Log in"

# File.open("response.html", 'w') {|f| f.write( response.body) } # response.should contain("Logged in successfully") end Then /^"([^"]*)" link should be shown$/ do |arg1|   clicks_link user_list_path   #pending # express the regexp above with the code you wish you had end

My problem is 2nd step:- Could not find link with text or title or id "/user-list" (Webrat::NotFoundError) features/admin.feature:5:in `Then "Users" link should be shown'

Failing Scenarios: cucumber features/admin.feature:3 # Scenario: Login as Admin

Is there anything wrong with my code?

How can I check whether the link is present or not? Also, My login is successful as admin but when I print response I get the home page structure and not the app home page. Can anyone help me out?

Thanks, Mike

Ahmy Yulrizka

Hi,

I am using cucumber with webrat for testing my application.

I have admin role in my application.

When admin logs into the system he able to see the “Users” link which

gives an interface to manage users for admin. I have written the feature

like as follows:-

Feature: List All Users

So that Admin can manage users

Scenario: Login as Admin

When I login with user “username” with password “123456”

Then “Users” link should be shown

My Step definition code is like as follows:-

When /^I login with user “([^”])" with password “([^”])"$/ do |login,

password>

visit “/”

fill_in “login”, :with=>login

fill_in “password”, :with=>password

click_button “Log in”

File.open(“response.html”, ‘w’) {|f| f.write( response.body) }

response.should contain(“Logged in successfully”)

end

Then /^“([^”]*)" link should be shown$/ do |arg1|

clicks_link user_list_path

#pending # express the regexp above with the code you wish you had

end

My problem is 2nd step:-

Could not find link with text or title or id “/user-list”

(Webrat::NotFoundError)

features/admin.feature:5:in `Then “Users” link should be shown’

If im not mistaken, the clicks_link accept the “link text” rather then the url http://webrat.rubyforge.org/classes/ActionController/Integration/Session.html#M000004

if you have User List" the step should be clicks_link “User List”

also you might want to see the features/step_definition/web_step.rb you could use the predefined helper “follow”

so in the description you could use … And I follow “User List” …

Failing Scenarios:

cucumber features/admin.feature:3 # Scenario: Login as Admin

I don’t really know about this, but there is also predefined step that will help you look at what webrat “see” the step is

show_me_the_page

when it’s called, it save current response html to /tmp