Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber + webrat + selenium, how do I ignore hidden text?

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.

like image 264
Guoliang Cao Avatar asked Jan 23 '23 19:01

Guoliang Cao


1 Answers

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.

like image 184
Michał Kwiatkowski Avatar answered Feb 06 '23 18:02

Michał Kwiatkowski