Module: WatirAngular

Defined in:
lib/watir_angular.rb

Class Method Summary collapse

Class Method Details

.inject_wait(browser) ⇒ Object



28
29
30
# File 'lib/watir_angular.rb', line 28

def self.inject_wait(browser)
  browser.after_hooks.add ->(browser) { wait_for_angular(browser) }
end

.wait_for_angular(browser, timeout: Watir.default_timeout) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/watir_angular.rb', line 10

def self.wait_for_angular(browser, timeout: Watir.default_timeout)
  wd = browser.wd
  angular_element = "document.querySelectorAll('[ng-app]')[0]"
  wd.execute_script("angular.element(#{angular_element}).scope().pageFinishedRendering = false")
  wd.execute_script("angular.getTestability(#{angular_element}).whenStable(function(){angular.element(#{angular_element}).scope().pageFinishedRendering = true})")
  browser.wait_until(timeout: timeout, message: "waiting for angular to render") do
    wd.execute_script("return angular.element(#{angular_element}).scope().pageFinishedRendering")
  end
rescue Selenium::WebDriver::Error::InvalidElementStateError
  # no ng-app found on page, continue as normal
rescue Selenium::WebDriver::Error::JavascriptError
  # angular not used in the application, continue as normal
rescue Selenium::WebDriver::Error::UnknownError => ex
  # TODO - this may be a bug in chromedriver that it is not a JavaScriptError
  raise unless ex.message.include? "angular is not defined"
  # angular not used in the application, continue as normal
end