Class: Applitools::Driver
- Inherits:
-
Object
- Object
- Applitools::Driver
- Includes:
- Selenium::WebDriver::DriverExtensions::HasInputDevices
- Defined in:
- lib/eyes_selenium_ruby/eyes/driver.rb
Constant Summary collapse
- DEFAULT_DRIVER =
:firefox- DRIVER_METHODS =
[ :title, :execute_script, :execute_async_script, :quit, :close, :get, :post, :page_source, :window_handles, :window_handle, :switch_to, :navigate, :manage, :capabilities ]
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#remote_server_url ⇒ Object
readonly
Returns the value of attribute remote_server_url.
-
#screenshot_taker ⇒ Object
readonly
Returns the value of attribute screenshot_taker.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
-
#user_inputs ⇒ Object
Returns the value of attribute user_inputs.
Instance Method Summary collapse
- #clear_user_inputs ⇒ Object
- #create_application ⇒ Object
- #find_element(by, selector) ⇒ Object
- #find_elements(by, selector) ⇒ Object
- #firefox? ⇒ Boolean
- #ie? ⇒ Boolean
-
#initialize(options = {}) ⇒ Driver
constructor
If driver is not provided, Applitools::Driver will default to Firefox driver Driver param can be a Selenium::WebDriver or a named symbol (:chrome).
- #keyboard ⇒ Object
- #mouse ⇒ Object
- #screenshot_as(output_type) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Driver
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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 24 def initialize(={}) browser_obj = .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.})" end end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
8 9 10 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 8 def browser @browser end |
#remote_server_url ⇒ Object (readonly)
Returns the value of attribute remote_server_url.
7 8 9 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 7 def remote_server_url @remote_server_url end |
#screenshot_taker ⇒ Object (readonly)
Returns the value of attribute screenshot_taker.
7 8 9 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 7 def screenshot_taker @screenshot_taker end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
7 8 9 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 7 def user_agent @user_agent end |
#user_inputs ⇒ Object
Returns the value of attribute user_inputs.
8 9 10 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 8 def user_inputs @user_inputs end |
Instance Method Details
#clear_user_inputs ⇒ Object
84 85 86 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 84 def clear_user_inputs user_inputs.clear end |
#create_application ⇒ Object
80 81 82 |
# 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) ⇒ Object
72 73 74 |
# 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) ⇒ Object
76 77 78 |
# 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? ⇒ Boolean
92 93 94 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 92 def firefox? browser.to_s == 'firefox' end |
#ie? ⇒ Boolean
88 89 90 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 88 def ie? browser.to_s == 'ie' end |
#keyboard ⇒ Object
68 69 70 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 68 def keyboard Applitools::EyesKeyboard.new(self, browser.keyboard) end |
#mouse ⇒ Object
64 65 66 |
# File 'lib/eyes_selenium_ruby/eyes/driver.rb', line 64 def mouse Applitools::EyesMouse.new(self, browser.mouse) end |
#screenshot_as(output_type) ⇒ Object
55 56 57 58 59 60 61 62 |
# 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 |