Visit url with query string under Capybara > Celerity or Selenium?

3,071 views
Skip to first unread message

David Kahn

unread,
Sep 17, 2010, 7:59:58 PM9/17/10
to cu...@googlegroups.com
Hi all,
My first post on this group. Am about 3 days into Cucumber. And of course I am not sticking to the straight forward stuff. I have a feature I need to test some ajax. So I am using culerity/celerity (also tried selenium with similar bad result).

I need to do this step: visit('/login', { :account_name => user.account.name })
I get this error: wrong number of arguments (2 for 1) (ArgumentError)
And I understand that this is because the Rack method allows atts where the others do not.

visit (Capybara::Driver::Celerity) >>>   visit(path)
visit (Capybara::Driver::Selenium) >>>   visit(path)
visit (Capybara::Driver::RackTest) >>>   visit(path, attributes = {})  

So, question: How do I deal with visiting a url with a query string? I know I can just use Selenium directly and do this but would rather now if don't have to.

Thanks,

David

Jonas Nicklas

unread,
Sep 18, 2010, 5:33:11 AM9/18/10
to cu...@googlegroups.com
just append the query string:

visit('/login?account_name=#{user.account.login}')

the fact that what you tried before even works at all is an accident,
and afaik was never documented anywhere.

/Jonas

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to
> cukes+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.
>

David Kahn

unread,
Sep 18, 2010, 11:05:48 AM9/18/10
to cu...@googlegroups.com
On Sat, Sep 18, 2010 at 4:33 AM, Jonas Nicklas <jonas....@gmail.com> wrote:
> just append the query string:
> visit('/login?account_name=#{user.account.login}')

Thanks Jonas, but this is the error message I get when I try this (same error whether I state my scenario under @culerity or without it:

bad URI(is not URI?): /login?account_name=First Lender (URI::InvalidURIError)
/Users/DK/.rvm/rubies/ruby-1.8.7-p174/lib/ruby/1.8/uri/common.rb:436:in `split'
/Users/DK/.rvm/rubies/ruby-1.8.7-p174/lib/ruby/1.8/uri/common.rb:485:in `parse'
./features/step_definitions/login_steps.rb:18:in `/^I am logged in as a lender user$/'
features/comparison.feature:10:in `Given I am logged in as a lender user'

The methods I copied below come from the rdoc for Capybara. Are you using Capybara or Webrat?  (I am assuming you are also on Rails)


> visit (Capybara::Driver::Celerity) >>>   visit(path)
> visit (Capybara::Driver::Selenium) >>>   visit(path)
> visit (Capybara::Driver::RackTest) >>>   visit(path, attributes = {})

Thanks,

David

Aslak Hellesøy

unread,
Sep 18, 2010, 11:21:07 AM9/18/10
to cu...@googlegroups.com, cu...@googlegroups.com
Replace single quotes with double quotes?


Jonas Nicklas

unread,
Sep 18, 2010, 11:49:03 AM9/18/10
to cu...@googlegroups.com
If you want to put spaces into whatever you're putting into the URL,
you'll need to escape your input first. I really encourage you to
rethink your design though, these URLs don't look particularly
friendly to me.

Oh and as aslak pointed out, it should be double quotes obviously. My bad.

/Jonas

David Kahn

unread,
Sep 18, 2010, 12:02:00 PM9/18/10
to cu...@googlegroups.com
Thanks guys.... Jonas, that was it, I needed to URI.escape the query string content. In retrospect that makes a lot of sense.

Yeah I know about the url.... thing was having a choice of creating 3 separate views for login, each with slightly different auth info and cobranding (admin, broker user, lender user), or one view, so I chose one.

Jonas Nicklas

unread,
Sep 18, 2010, 12:06:49 PM9/18/10
to cu...@googlegroups.com
You can choose one view and still have friendlier URLs, take a look at
Rails' parameterize method, it's perfect for that sort of thing. Also,
try not to use query strings wherever possible, they're just ugly.

/Jonas

David Kahn

unread,
Sep 18, 2010, 12:23:27 PM9/18/10
to cu...@googlegroups.com
Thanks. Just looked at it, the parameterize method looks useful.

David Kahn

unread,
Sep 18, 2010, 1:15:34 PM9/18/10
to cu...@googlegroups.com
Well, my pain continues :)

This is the weird situation

When I comment the scenario which uses culerity, then my rake cucumber result is:
4 scenarios (4 passed)
18 steps (18 passed)

However when I run the culerity scenario with all, I get:
5 scenarios (3 failed, 2 passed)
36 steps (1 failed, 16 skipped, 19 passed)

How can a scenario that  was passing then fail with the introduction on a new scenario which uses culerity?


The error which results on the second run occurs on the same line:
Now the same line: visit("/login?account_name=#{URI.escape(user.account.name)}")
And note, it happens regardless of the url I place (I have tried without the query string '/login', as below, with 'http://localhost:3000...' and even 'http://www.google.com'). And it is isolated to using culerity as when I comment the scenario which calls it, the same step succeeds fine.

The error output is:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.first (NoMethodError)

./features/step_definitions/login_steps.rb:18:in `/^I am logged in as a lender user$/'
features/comparison.feature:24:in `Given I am logged in as a lender user'

Thanks again,

David
Reply all
Reply to author
Forward
0 new messages