Class: WebPage
- Inherits:
-
Object
- Object
- WebPage
- Extended by:
- Capybara::DSL
- Includes:
- Capybara::DSL, Howitzer::Utils::PageValidator, LocatorStore, RSpec::Matchers, Singleton
- Defined in:
- lib/howitzer/web_page.rb
Constant Summary collapse
- BLANK_PAGE =
'about:blank'- IncorrectPageError =
Class.new(StandardError)
Constants included from Howitzer::Utils::PageValidator
Howitzer::Utils::PageValidator::NoValidationError, Howitzer::Utils::PageValidator::UnknownValidationName, Howitzer::Utils::PageValidator::WrongOptionError
Constants included from LocatorStore
LocatorStore::BadLocatorParamsError, LocatorStore::LocatorNotDefinedError
Class Method Summary collapse
-
.current_url ⇒ Object
Returns current url.
-
.given ⇒ Object
Returns singleton instance of current web page.
- .inherited(subclass) ⇒ Object
-
.open(url = "#{app_url}#{self::URL}") ⇒ Object
Opens web-site by given url.
-
.text ⇒ Object
Returns body text of html page.
Instance Method Summary collapse
-
#click_alert_box(flag) ⇒ Object
Accepts or declines JS alert box by given flag.
-
#js_click(css_locator) ⇒ Object
Clicks on button or link using JS event call.
-
#reload ⇒ Object
Reloads current page.
-
#tinymce_fill_in(name, options = {}) ⇒ Object
Fills in field that using Tinymce API.
-
#title ⇒ Object
Returns Page title.
- #wait_for_ajax(timeout = settings.timeout_small, message = nil) ⇒ Object deprecated Deprecated.
-
#wait_for_title(expected_title, timeout = settings.timeout_small) ⇒ Object
Waits until web is loaded with expected title.
-
#wait_for_url(expected_url, timeout = settings.timeout_small) ⇒ Object
Waits until web page is loaded.
Methods included from Howitzer::Utils::PageValidator
#check_correct_page_loaded, included, validations
Methods included from LocatorStore
Class Method Details
.current_url ⇒ Object
Returns current url
Returns:
-
string- Current url
175 176 177 |
# File 'lib/howitzer/web_page.rb', line 175 def self.current_url page.current_url end |
.given ⇒ Object
Returns singleton instance of current web page
Returns:
-
WebPage- Singleton instance
50 51 52 |
# File 'lib/howitzer/web_page.rb', line 50 def self.given self.instance.tap{ |page| page.check_correct_page_loaded } end |
.inherited(subclass) ⇒ Object
18 19 20 |
# File 'lib/howitzer/web_page.rb', line 18 def self.inherited(subclass) subclass.class_eval { include Singleton } end |
.open(url = "#{app_url}#{self::URL}") ⇒ Object
Opens web-site by given url
Parameters:
-
url- Url string that will be opened
Returns:
-
WebPage- New instance of current class
33 34 35 36 37 38 39 40 |
# File 'lib/howitzer/web_page.rb', line 33 def self.open(url="#{app_url}#{self::URL}") log.info "Open #{self.name} page by '#{url}' url" retryable(tries: 2, logger: log, trace: true, on: Exception) do |retries| log.info "Retry..." unless retries.zero? visit url end given end |
.text ⇒ Object
Returns body text of html page
Returns:
-
string- Body text
199 200 201 |
# File 'lib/howitzer/web_page.rb', line 199 def self.text page.find('body').text end |
Instance Method Details
#click_alert_box(flag) ⇒ Object
Accepts or declines JS alert box by given flag
Parameters:
-
flag[TrueClass,FalseClass] - Determines accept or decline alert box
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/howitzer/web_page.rb', line 81 def click_alert_box(flag) if %w[selenium selenium_dev sauce].include? settings.driver if flag page.driver.browser.switch_to.alert.accept else page.driver.browser.switch_to.alert.dismiss end else if flag page.evaluate_script('window.confirm = function() { return true; }') else page.evaluate_script('window.confirm = function() { return false; }') end end end |
#js_click(css_locator) ⇒ Object
Clicks on button or link using JS event call
Parameters:
-
css_locator- Css locator of link or button
105 106 107 108 |
# File 'lib/howitzer/web_page.rb', line 105 def js_click(css_locator) page.execute_script("$('#{css_locator}').trigger('click')") sleep settings.timeout_tiny end |
#reload ⇒ Object
Reloads current page
162 163 164 165 |
# File 'lib/howitzer/web_page.rb', line 162 def reload log.info "Reload '#{current_url}'" visit current_url end |
#tinymce_fill_in(name, options = {}) ⇒ Object
Fills in field that using Tinymce API
Parameters:
-
name- Frame name that contains Tinymce field -
Hash- Not required options
63 64 65 66 67 68 69 70 71 |
# File 'lib/howitzer/web_page.rb', line 63 def tinymce_fill_in(name, = {}) if %w[selenium selenium_dev sauce].include? settings.driver page.driver.browser.switch_to.frame("#{name}_ifr") page.find(:css, '#tinymce').native.send_keys([:with]) page.driver.browser.switch_to.default_content else page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')") end end |
#title ⇒ Object
Returns Page title
Returns:
-
string- Page title
187 188 189 |
# File 'lib/howitzer/web_page.rb', line 187 def title page.title end |
#wait_for_ajax(timeout = settings.timeout_small, message = nil) ⇒ Object
With Capybara 2.x it is extra
112 113 114 115 116 117 118 119 |
# File 'lib/howitzer/web_page.rb', line 112 def wait_for_ajax(timeout=settings.timeout_small, =nil) end_time = ::Time.now + timeout until ::Time.now > end_time return true if page.evaluate_script('$.active') == 0 sleep 0.25 end log.error || "Timed out waiting for ajax requests to complete" end |
#wait_for_title(expected_title, timeout = settings.timeout_small) ⇒ Object
Waits until web is loaded with expected title
Parameters:
-
expected_title- Page title that will be waited for -
time_out- Seconds that will be waiting for web-site to be loaded until raise error
148 149 150 151 152 153 154 155 |
# File 'lib/howitzer/web_page.rb', line 148 def wait_for_title(expected_title, timeout=settings.timeout_small) end_time = ::Time.now + timeout until ::Time.now > end_time operator = expected_title.is_a?(Regexp) ? :=~ : :== return true if title.send(operator, expected_title).tap{|res| sleep 1 unless res} end log.error IncorrectPageError, "Current title: #{title}, expected: #{expected_title}" end |
#wait_for_url(expected_url, timeout = settings.timeout_small) ⇒ Object
Waits until web page is loaded
Parameters:
-
expected_url- Url that will be waiting for -
time_out- Seconds that will be waiting for web-site to be loaded until raise error
130 131 132 133 134 135 136 137 |
# File 'lib/howitzer/web_page.rb', line 130 def wait_for_url(expected_url, timeout=settings.timeout_small) end_time = ::Time.now + timeout until ::Time.now > end_time operator = expected_url.is_a?(Regexp) ? :=~ : :== return true if current_url.send(operator, expected_url).tap{|res| sleep 1 unless res} end log.error IncorrectPageError, "Current url: #{current_url}, expected: #{expected_url}" end |