Method: Protractor#get
- Defined in:
- lib/angular_webdriver/protractor/protractor.rb
#get(destination, opt_timeout = driver.max_page_wait_seconds) ⇒ Object
@see webdriver.WebDriver.get
Navigate to the given destination. Assumes that the page being loaded uses Angular.
If you need to access a page which does not have Angular on load,
use driver_get.
@example
browser.get('https://angularjs.org/');
expect(browser.getCurrentUrl()).toBe('https://angularjs.org/');
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/angular_webdriver/protractor/protractor.rb', line 108 def get destination, opt_timeout=driver.max_page_wait_seconds # do not use driver.get because that redirects to this method # instead driver_get is provided. timeout = opt_timeout raise "Invalid timeout #{timeout}" unless timeout.is_a?(Numeric) unless destination.is_a?(String) || destination.is_a?(URI) raise "Invalid destination #{destination}" end # http://about:blank doesn't work. it must be exactly about:blank about_url = destination.start_with?('about:') # data urls must be preserved and not have http:// prepended. # data:<blah> data_url = destination.start_with?('data:') unless about_url || data_url # URI.join doesn't allow for http://localhost:8081/#/ as a base_url # so this departs from the Protractor behavior and favors File.join instead. # # In protractor: url.resolve('http://localhost:8081/#/', 'async') # => http://localhost:8081/async # In Ruby: File.join('http://localhost:8081/#/', 'async') # => http://localhost:8081/#/async # base_url_exists = base_url && !base_url.empty? tmp_uri = URI.parse(destination) rescue URI.parse('') relative_url = !tmp_uri.scheme || !tmp_uri.host if base_url_exists && relative_url destination = File.join(base_url, destination.to_s) elsif relative_url # prepend 'http://' to urls such as localhost destination = "http://#{destination}" end end msg = lambda { |str| 'Protractor.get(' + destination + ') - ' + str } return driver_get(destination) if ignore_sync driver_get(reset_url) executeScript_( 'window.location.replace("' + destination + '");', msg.call('reset url')) wait(timeout) do url = executeScript_('return window.location.href;', msg.call('get url')) not_on_reset_url = url != reset_url destination_is_reset = destination == reset_url raise 'still on reset url' unless not_on_reset_url || destination_is_reset end # now that the url has changed, make sure Angular has loaded # note that the mock module logic is omitted. # waitForAngular description: 'Protractor.get', timeout: timeout end |