Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell cucumber go to some page?

I'm learning to test with cucumber + capybara.

In one video tutorial I found that something like this should work:

...
When I go to the homepage
Then /do stuff/

I'm trying to do that but cucumber treats the word "homepage" as a part of regex.

So it gives me the suggestion to create a statement like so

When /^I go to homepage$/ do
   #tasks
end

Tried "index page", "items page" (name of existing controller), "root path" - same thing. Cucumber doesn't actually go there - just asks to create a handler.

Where do I go from here?

like image 299
user1885058 Avatar asked Dec 24 '12 07:12

user1885058


1 Answers

Using a gem such as Capybara you could do something like so

In you test:

When I go to the homepage

In your step:

When /^I go to the homepage$/ do
 visit root_path
end

Or to generalize:

When /^I go to the "(.*)"/ do |place|
 visit "/#{place}"
end

where your step would pass in the location (url) where you would want to go.

For more info on visit method checkout here

like image 73
Jay Truluck Avatar answered Sep 22 '22 07:09

Jay Truluck