views:

164

answers:

2

I am using Cucumber, webrat and selenium to test a web application. I use 'I should see "something"' to verify changes. However, in many places, text to be verified only changes from hidden to visible (this might be caused by removing 'hidden' class from itself or one of its ancestors). In this case, above test does not actually verify the change. I am trying to use 'response.should_not have_tag("div#myId.hidden")', which does not work. What is the recommended way to test this?

Environment: cucumber 0.3.11, selenium-client 1.2.17, webrat 0.6.0

Thank you.

+2  A: 

For cases as these I use those two custom steps:

Then /^the element matched by "([^\"]*)" should be visible$/ do |locator|
  selenium.should be_visible(locator)
end

Then /^the element matched by "([^\"]*)" should not be visible$/ do |locator|
  selenium.should_not be_visible(locator)
end

Put those into a Ruby file under step_definitions/ directory.

So, in your case, instead of Then I should see "something" use Then the element matched by "something" should be visible.

Michał Kwiatkowski
Should locator be a css selector or some text seen on the page?
Guoliang Cao
selenium.should be_visible "div#myId"produces this error: Element div#myId not found (Selenium::CommandError)I'm sure its a valid css selector. What might have gone wrong?
Guoliang Cao
Use "css=div#myId" (and read more on that here: http://seleniumhq.org/docs/04_selenese_commands.html#locating-by-css).
Michał Kwiatkowski
If this works no matter how I make the part visible/invisible, then it is better than manually check presence of hidden class. I'll see whether that is the case.Thanks a lot.
Guoliang Cao
Yes, it works by looking for "visibility: hidden" or "display: none" properties. For full docs see http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/ruby/classes/Selenium/Client/GeneratedDriver.html#M000170
Michał Kwiatkowski
+1  A: 

Does it work when using have_selector("div#myId.hidden") instead?

schmitzelburger
That works. Thanks a lot.
Guoliang Cao
You're welcome, and Happy New Year :-)
schmitzelburger