idea for SeleniumSession#within method

3 views
Skip to first unread message

Woody Peterson

unread,
Oct 27, 2009, 3:09:00 PM10/27/09
to webrat
It'd be cool to have a SeleniumSession#within so the code:

within(selector) do |content|
content.should contain(text)
end

would work.

I had the idea:

class Webrat::SeleniumSession
def within(selector)
yield(response.selenium.text(selector))
end
end

response.selenium.text(selector) returns a very useful html-less
string, ex. the following is the result of a two-row table and header:

Changed Value To Date Date Info Variation Qty Price % Price +$ Qty
Price % Price +$ 10/27/2009 10:58AM Default Admin: Products page
Condition: NM- | Language: English +4 -5.00% $0.00 10 95.00% $0.00
10/27/2009 10:58AM Default Admin: Products page Condition: NM |
Language: English +5 0.00% $0.00 10 100.00% $0.00

I'm looking for English +4, so it's great that it puts them right next
to each other w/o html. I have the gut feeling that this is different
than the normal within() though. Notably, under the hood
'content.should contain(text)' is a lot more complicated than
something like 'content.should include(text)'; what's the added value
(i.e. the HasContent class).

I don't mind adding this functionality, but I'd hate to go in the
wrong direction and was looking for a little advice in terms of making
it as compatible with the current within()

Thanks,

-Woody

ps, in the mean time, the following works well:

Then /^I should see "([^\"]*)" within "([^\"]*)"$/ do |text,
selector|
if response.is_a?(Webrat::SeleniumResponse)
response.selenium.text(selector).should include(text)
else
within(selector) do |content|
content.should contain(text)
end
end
end

Jeroen van Dijk

unread,
Nov 5, 2009, 9:31:16 AM11/5/09
to webrat
I have the following hack to fake compatibility between webrat and
selenium http://gist.github.com/225061 You might find it useful for
your situation.

This should somehow be ported to the webrat core, but I think there
are others issues to solve first.
Message has been deleted

ashie1287

unread,
Nov 11, 2009, 1:15:29 PM11/11/09
to webrat
Jeroen,

Could you explain how to use your hack? Adding the methods directly
to selenium_session.rb causes:

protected method `within' called for #<Webrat::SeleniumSession:
0x7ffa44f9fd58> (NoMethodError)
(eval):2:in `within'
./features/step_definitions/webrat_steps.rb:140:in `/^I should
see "([^\"]*)" within "([^\"]*)"$/'

since an instance method of Webrat::Session is being called somewhere
during execution.

Thanks,
-Ash

P.S. Sorry if this is a repost, first one didn't seem to send.

On Nov 5, 9:31 am, Jeroen van Dijk <jeroentjevand...@gmail.com> wrote:
> I have the following hack to fake compatibility between webrat and
> seleniumhttp://gist.github.com/225061You might find it useful for
Reply all
Reply to author
Forward
0 new messages