class Applitools::Driver
Constants
- DEFAULT_DRIVER
- DRIVER_METHODS
Attributes
browser[RW]
remote_server_url[R]
remote_session_id[R]
screenshot_taker[R]
user_agent[R]
user_inputs[RW]
Public Class Methods
new(options={})
click to toggle source
If driver is not provided, Applitools::Driver
will default to Firefox driver Driver
param can be a Selenium::WebDriver
or a named symbol (:chrome)
Example: eyes.open(browser: :chrome) ##=> will create chrome webdriver eyes.open(browser: Selenium::WebDriver.for(:chrome) ##=> will create the same thing eyes.open ##=> will create a webdriver according to Applitools::Driver::DEFAULT_DRIVER
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 24 def initialize(options={}) browser_obj = options.delete(:browser) || DEFAULT_DRIVER @browser ||= case browser_obj when Symbol Selenium::WebDriver.for browser_obj else browser_obj end at_exit { quit rescue nil } @user_inputs = [] @remote_server_url = address_of_remote_server @remote_session_id = remote_session_id @user_agent = get_user_agent begin if browser.capabilities.takes_screenshot? @screenshot_taker = false else @screenshot_taker = Applitools::ScreenshotTaker.new(@remote_server_url, @remote_session_id) end rescue => e raise Applitools::EyesError.new "Can't take screenshots (#{e.message})" end end
Public Instance Methods
clear_user_inputs()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 84 def clear_user_inputs user_inputs.clear end
create_application()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 80 def create_application Applitools::TargetApp.new(remote_server_url, remote_session_id, user_agent) end
find_element(by, selector)
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 72 def find_element(by, selector) Applitools::Element.new(self, browser.find_element(by, selector)) end
find_elements(by, selector)
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 76 def find_elements(by, selector) browser.find_elements(by, selector).map { |el| Applitools::Element.new(self, el) } end
firefox?()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 92 def firefox? browser.to_s == 'firefox' end
ie?()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 88 def ie? browser.to_s == 'ie' end
keyboard()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 68 def keyboard Applitools::EyesKeyboard.new(self, browser.keyboard) end
mouse()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 64 def mouse Applitools::EyesMouse.new(self, browser.mouse) end
screenshot_as(output_type)
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 55 def screenshot_as(output_type) return browser.screenshot_as(output_type) if !screenshot_taker if output_type.downcase.to_sym != :base64 raise Applitools::EyesError.new("#{output_type} ouput type not supported for screenshot") end screenshot_taker.screenshot end
Private Instance Methods
address_of_remote_server()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 98 def address_of_remote_server uri = URI(browser.current_url) raise Applitools::EyesError.new("Failed to get remote web driver url") if uri.to_s.empty? webdriver_host = uri.host if ['127.0.0.1', 'localhost'].include?(webdriver_host) && !firefox? && !ie? uri.host = get_local_ip || 'localhost' end uri end
get_local_ip()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 120 def get_local_ip begin Socket.ip_address_list.detect do |intf| intf.ipv4? and !intf.ipv4_loopback? and !intf.ipv4_multicast? end.ip_address rescue SocketError => e raise Applitools::EyesError.new("Failed to get local IP! (#{e})") end end
get_user_agent()
click to toggle source
# File lib/eyes_selenium_ruby/eyes/driver.rb, line 114 def get_user_agent execute_script "return navigator.userAgent" rescue => e puts "getUserAgent(): Failed to obtain user-agent string (#{e.message})" end