-
Notifications
You must be signed in to change notification settings - Fork 34
Filters
ehrenmurdick edited this page Sep 13, 2010
·
6 revisions
Filters are used to define states of Pages
As an example the Google home page displays a different user control panel in the upper right corner depending on whether or not the user is signed in.
module Google
class HomePage < Taza::Page
filter :logged_in?, :sign_out, :my_account
element(:user_panel) { browser.div(:id,'guser') }
element(:sign_in) { browser.link(:text,'Sign in') }
element(:sign_out) { browser.link(:text,'Sign out') }
element(:my_account) { browser.link(:text,'My Account') }
def logged_in?
user_panel.exists? && !sign_in.exists?
end
end
end
With this filter defined then the following code would throw an exception given the user is not logged in:
Google.new do |google|
google.home_page do |hp|
hp.sign_out.click
end
end
The exception would look something like:
Taza::FilterError Exception: logged_in? returned false for sign_out
This means that filters should return true
or false
.
NOTE: This bug does not exist on the latest revision on Github
Currently filters cannot access methods that are already filtered. That is to say that the following piece of code will fall into infinite recursion:
module Google
class HomePage < Taza::Page
filter :logged_in?, :sign_out, :my_account
element(:user_panel) { browser.div(:id,‘guser’) }
element(:sign_in) { browser.link(:text,‘Sign in’) }
element(:sign_out) { browser.link(:text,‘Sign out’) }
element(:my_account) { browser.link(:text,‘My Account’) }
def logged_in?
sign_out.exists? # sign_out is already filtered so when sign_out is called here it will call logged_in? :P
end
end
end
</code