Module: OnlyofficeWebdriverWrapper::WebdriverNavigationMethods

Extended by:
Gem::Deprecate
Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb

Overview

Methods for webdriver navigations

Instance Method Summary collapse

Instance Method Details

#current_urlString Also known as: get_url

Returns url of current frame, or browser url if it is a root frame.

Returns:

  • (String)

    url of current frame, or browser url if it is a root frame



23
24
25
26
27
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb', line 23

def current_url
  execute_javascript('return window.location.href')
rescue Selenium::WebDriver::Error::NoSuchFrameError, Timeout::Error => e
  raise(e.class, "Browser is crushed or hangup with #{e}")
end

#go_backnil

Go back like pressing ‘Back` button in browser

Returns:

  • (nil)


42
43
44
45
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb', line 42

def go_back
  @driver.navigate.back
  OnlyofficeLoggerHelper.log('Go back to previous page')
end

#open(url) ⇒ nil

Open specific url

Parameters:

  • url (String)

    to open

Returns:

  • (nil)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb', line 9

def open(url)
  url = "http://#{url}" unless url.include?('http') || url.include?('file://')
  ensure_url_available(url)
  @driver.navigate.to url
  sleep(1) # Correct wait for Page to init focus
  OnlyofficeLoggerHelper.log("Opened page: #{url}")
rescue StandardError => e
  message = "Received error `#{e}` while opening page `#{url}`"
  OnlyofficeLoggerHelper.log(message)
  raise e.class, message, e.backtrace
end

#quitnil

Quit current browser session

Returns:

  • (nil)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb', line 49

def quit
  return unless browser_running

  begin
    @driver.execute_script('window.onbeforeunload = null') # off popup window
  rescue StandardError
    StandardError
  end
  begin
    @driver.quit
  rescue StandardError => e
    OnlyofficeLoggerHelper.log("Some error happened on webdriver.quit #{e.backtrace}")
  end
  alert_confirm
  @headless.stop
  cleanup_download_folder
  @browser_running = false
end

#refreshnil

Refresh current page

Returns:

  • (nil)


35
36
37
38
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_navigation_methods.rb', line 35

def refresh
  @driver.navigate.refresh
  OnlyofficeLoggerHelper.log('Refresh page')
end