Class: Ferris::Core
- Inherits:
-
Object
- Object
- Ferris::Core
- Extended by:
- Region
- Includes:
- Watir::Waitable
- Defined in:
- lib/ferris/core.rb
Class Attribute Summary collapse
-
.base_url ⇒ Object
Returns the value of attribute base_url.
-
.require_url ⇒ Object
readonly
Returns the value of attribute require_url.
- .required_element_list ⇒ Object
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
- .element(name, required: false, &block) ⇒ Object
- .inherited(subclass) ⇒ Object
- .page_title ⇒ Object
- .page_url(required: false) ⇒ Object (also: partial_url)
Instance Method Summary collapse
- #check_required_elements ⇒ Object
- #check_title ⇒ Object
- #check_url ⇒ Object
-
#initialize(browser = Browser.browser) ⇒ Core
constructor
A new instance of Core.
- #inspect ⇒ Object (also: #selector_string)
- #loaded? ⇒ Boolean
- #present? ⇒ Boolean
- #verifiable? ⇒ Boolean
- #visit(*args) ⇒ Object
Methods included from Region
Constructor Details
Class Attribute Details
.base_url ⇒ Object
Returns the value of attribute base_url.
99 100 101 |
# File 'lib/ferris/core.rb', line 99 def base_url @base_url end |
.require_url ⇒ Object (readonly)
Returns the value of attribute require_url.
98 99 100 |
# File 'lib/ferris/core.rb', line 98 def require_url @require_url end |
.required_element_list ⇒ Object
111 112 113 |
# File 'lib/ferris/core.rb', line 111 def required_element_list @required_element_list ||= [] end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
47 48 49 |
# File 'lib/ferris/core.rb', line 47 def base_url @base_url end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
47 48 49 |
# File 'lib/ferris/core.rb', line 47 def browser @browser end |
#root ⇒ Object
Returns the value of attribute root.
48 49 50 |
# File 'lib/ferris/core.rb', line 48 def root @root end |
Class Method Details
.element(name, required: false, &block) ⇒ Object
119 120 121 122 |
# File 'lib/ferris/core.rb', line 119 def element(name, required: false, &block) define_method(name) {|*args| self.instance_exec(*args, &block) } required_element_list << name.to_sym if required end |
.inherited(subclass) ⇒ Object
115 116 117 |
# File 'lib/ferris/core.rb', line 115 def inherited(subclass) subclass.required_element_list = required_element_list.dup end |
.page_title ⇒ Object
107 108 109 |
# File 'lib/ferris/core.rb', line 107 def page_title define_method('page_title') {|*args| yield(*args) } end |
.page_url(required: false) ⇒ Object Also known as: partial_url
101 102 103 104 |
# File 'lib/ferris/core.rb', line 101 def page_url(required: false) @require_url = required define_method('page_url') {|*args| base_url + yield(*args) } end |
Instance Method Details
#check_required_elements ⇒ Object
90 91 92 93 94 |
# File 'lib/ferris/core.rb', line 90 def check_required_elements browser.wait_until { |_b| self.class.required_element_list.all? { |e| send(e).present? } } rescue Watir::Wait::TimeoutError false end |
#check_title ⇒ Object
86 87 88 |
# File 'lib/ferris/core.rb', line 86 def check_title browser.title == page_title end |
#check_url ⇒ Object
82 83 84 |
# File 'lib/ferris/core.rb', line 82 def check_url page_url[%r{^#{URI.parse(page_url).scheme}://(.*?)/?$}, 1] == browser.url[%r{^#{URI.parse(browser.url).scheme}://(.*?)/?$}, 1] end |
#inspect ⇒ Object Also known as: selector_string
55 56 57 |
# File 'lib/ferris/core.rb', line 55 def inspect '#<%s url=%s title=%s>' % [self.class, url.inspect, title.inspect] end |
#loaded? ⇒ Boolean
77 78 79 80 |
# File 'lib/ferris/core.rb', line 77 def loaded? raise Selenium::WebDriver::Error::WebDriverError, 'Cannot verify a page/region without requirements' unless page_verifiable? [!self.class.require_url || check_url, !respond_to?(:page_title) || check_title, !self.class.required_element_list.any? || check_required_elements].all? end |
#present? ⇒ Boolean
60 61 62 63 |
# File 'lib/ferris/core.rb', line 60 def present? raise 'No root element set.' unless root root.present? end |
#verifiable? ⇒ Boolean
73 74 75 |
# File 'lib/ferris/core.rb', line 73 def verifiable? self.class.require_url || self.respond_to?(:page_title) || self.class.required_element_list.any? end |
#visit(*args) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/ferris/core.rb', line 65 def visit(*args) browser.goto page_url(*args) exception = Selenium::WebDriver::Error::WebDriverError = "Expected to be on #{self.class}, but conditions not met" raise exception, if verifiable? && !loaded? self end |