Class: Gizmo::Page
- Inherits:
-
Object
- Object
- Gizmo::Page
- Defined in:
- lib/gizmo/page.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #has_selector?(css_selector) ⇒ Boolean
-
#initialize(driver, content, url) ⇒ Page
constructor
A new instance of Page.
- #method_missing(name, *args) ⇒ Object
- #perform(action_name, *params) ⇒ Object
-
#valid? ⇒ Boolean
Pages are valid by default - specific mixins should change this behaviour to require certain elements on the page then you will get an error message saying “Page did not have mixin #name” eg.
Constructor Details
#initialize(driver, content, url) ⇒ Page
Returns a new instance of Page.
7 8 9 10 11 |
# File 'lib/gizmo/page.rb', line 7 def initialize driver, content, url @browser = driver @document = Nokogiri::HTML(content) @url = url end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
33 34 35 36 37 |
# File 'lib/gizmo/page.rb', line 33 def method_missing name, *args method_name = name.to_sym return super unless browser.respond_to?(method_name) browser.send(method_name, *args) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
5 6 7 |
# File 'lib/gizmo/page.rb', line 5 def document @document end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/gizmo/page.rb', line 5 def url @url end |
Instance Method Details
#has_selector?(css_selector) ⇒ Boolean
23 24 25 |
# File 'lib/gizmo/page.rb', line 23 def has_selector? css_selector @document.css(css_selector).length > 0 end |
#perform(action_name, *params) ⇒ Object
27 28 29 30 31 |
# File 'lib/gizmo/page.rb', line 27 def perform action_name, *params method_name = "#{action_name.to_s}_action".to_sym raise NoMethodError, "No action named '#{action_name}' has been defined" unless respond_to? method_name send(method_name, *params) end |
#valid? ⇒ Boolean
Pages are valid by default - specific mixins should change this behaviour to require certain elements on the page then you will get an error message saying “Page did not have mixin #name” eg. def valid?
has_selector?('some_element_selector')
end
21 |
# File 'lib/gizmo/page.rb', line 21 def valid?; true; end |