Class: Applitools::Eyes
- Inherits:
-
Object
- Object
- Applitools::Eyes
- Defined in:
- lib/eyes_selenium_ruby/capybara.rb,
lib/eyes_selenium_ruby/eyes/eyes.rb
Overview
Override create driver to inject into capybara’s driver
Constant Summary collapse
- DEFAULT_MATCH_TIMEOUT =
2.0
- AGENT_ID =
'eyes.selenium.ruby'
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Instance Attribute Summary collapse
-
#aborted ⇒ Object
Returns the value of attribute aborted.
-
#agent_connector ⇒ Object
readonly
Returns the value of attribute agent_connector.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#failure_reports ⇒ Object
Returns the value of attribute failure_reports.
-
#host_app ⇒ Object
Returns the value of attribute host_app.
-
#host_os ⇒ Object
Returns the value of attribute host_os.
-
#is_open ⇒ Object
Returns the value of attribute is_open.
-
#match_level ⇒ Object
Returns the value of attribute match_level.
-
#match_timeout ⇒ Object
Returns the value of attribute match_timeout.
-
#match_window_task ⇒ Object
Returns the value of attribute match_window_task.
-
#parent_branch_name ⇒ Object
Returns the value of attribute parent_branch_name.
-
#session ⇒ Object
Returns the value of attribute session.
-
#session_start_info ⇒ Object
Returns the value of attribute session_start_info.
-
#should_match_window_run_once_on_timeout ⇒ Object
Returns the value of attribute should_match_window_run_once_on_timeout.
-
#test_batch ⇒ Object
Returns the value of attribute test_batch.
-
#test_name ⇒ Object
Returns the value of attribute test_name.
-
#viewport_size ⇒ Object
Returns the value of attribute viewport_size.
Instance Method Summary collapse
- #abort_if_not_closed ⇒ Object
- #check_window(tag) ⇒ Object
- #close ⇒ Object
- #config ⇒ Object
- #create_driver(params) ⇒ Object
-
#initialize(params = {}) ⇒ Eyes
constructor
A new instance of Eyes.
- #open(params = {}) ⇒ Object
- #open? ⇒ Boolean
-
#test(params = {}, &block) ⇒ Object
Use this method to perform seamless testing with selenium through eyes driver.
Constructor Details
#initialize(params = {}) ⇒ Eyes
Returns a new instance of Eyes.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 24 def initialize(params={}) raise "Please supply an apikey: Eyes.config[:apikey] = ..." unless config[:apikey] @disabled = params[:disabled] @driver = create_driver(params) return if disabled? @agent_connector = Applitools::AgentConnector.new(config[:server_url], config[:user], config[:apikey]) @match_timeout = DEFAULT_MATCH_TIMEOUT @failure_reports = Applitools::FailureReports::ON_CLOSE end |
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 6 def config @config end |
Instance Attribute Details
#aborted ⇒ Object
Returns the value of attribute aborted.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def aborted @aborted end |
#agent_connector ⇒ Object (readonly)
Returns the value of attribute agent_connector.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def agent_connector @agent_connector end |
#app_name ⇒ Object
Returns the value of attribute app_name.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def app_name @app_name end |
#branch_name ⇒ Object
Returns the value of attribute branch_name.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def branch_name @branch_name end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def disabled @disabled end |
#driver ⇒ Object
Returns the value of attribute driver.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def driver @driver end |
#failure_reports ⇒ Object
Returns the value of attribute failure_reports.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def failure_reports @failure_reports end |
#host_app ⇒ Object
Returns the value of attribute host_app.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def host_app @host_app end |
#host_os ⇒ Object
Returns the value of attribute host_os.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def host_os @host_os end |
#is_open ⇒ Object
Returns the value of attribute is_open.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def is_open @is_open end |
#match_level ⇒ Object
Returns the value of attribute match_level.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def match_level @match_level end |
#match_timeout ⇒ Object
Returns the value of attribute match_timeout.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def match_timeout @match_timeout end |
#match_window_task ⇒ Object
Returns the value of attribute match_window_task.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def match_window_task @match_window_task end |
#parent_branch_name ⇒ Object
Returns the value of attribute parent_branch_name.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def parent_branch_name @parent_branch_name end |
#session ⇒ Object
Returns the value of attribute session.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def session @session end |
#session_start_info ⇒ Object
Returns the value of attribute session_start_info.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def session_start_info @session_start_info end |
#should_match_window_run_once_on_timeout ⇒ Object
Returns the value of attribute should_match_window_run_once_on_timeout.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def should_match_window_run_once_on_timeout @should_match_window_run_once_on_timeout end |
#test_batch ⇒ Object
Returns the value of attribute test_batch.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def test_batch @test_batch end |
#test_name ⇒ Object
Returns the value of attribute test_name.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def test_name @test_name end |
#viewport_size ⇒ Object
Returns the value of attribute viewport_size.
16 17 18 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 16 def @viewport_size end |
Instance Method Details
#abort_if_not_closed ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 132 def abort_if_not_closed return if disabled? self.is_open = false if session begin agent_connector.stop_session(session,true) rescue Applitools::EyesError => e EyesLogger.info "Failed to abort server session -> #{e.} " ensure self.session = nil end end end |
#check_window(tag) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 64 def check_window(tag) return if disabled? raise Applitools::EyesError.new("Eyes not open") if !open? if !session start_session self.match_window_task = Applitools::MatchWindowTask.new(agent_connector, session, driver, match_timeout) end as_expected = match_window_task.match_window(tag, should_match_window_run_once_on_timeout) if !as_expected self.should_match_window_run_once_on_timeout = true if !session.new_session? #EyesLogger.info %( "mismatch! #{ tag ? "" : "(#{tag})" } ) if failure_reports.to_i == Applitools::FailureReports::IMMEDIATE raise Applitools::TestFailedError.new("Mismatch found in '#{start_info.scenario_id_or_name}'"\ " of '#{start_info.app_id_or_name}'") end end end end |
#close ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 85 def close return if disabled? self.is_open = false return Applitools::TestResults.new if !session session_results_url = session.url results = agent_connector.stop_session(session,false) new_session = session.new_session? self.session = nil if new_session instructions = "Please approve the new baseline at #{session_results_url}" EyesLogger.info "--- New test ended. #{instructions}" = "' #{session_start_info.scenario_id_or_name} of"\ " #{session_start_info.app_id_or_name}. #{instructions}" raise Applitools::NewTestError.new(, results) elsif 0 < results.mismatches || 0 < results.missing EyesLogger.info "--- Failed test ended. See details at #{session_results_url}" = "' #{session_start_info.scenario_id_or_name} of"\ " #{session_start_info.app_id_or_name}'. See details at #{session_results_url}" raise Applitools::TestFailedError.new(, results) end EyesLogger.info "--- Test passed. See details at #{session_results_url}" end |
#config ⇒ Object
20 21 22 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 20 def config self.class.config end |
#create_driver(params) ⇒ Object
37 38 39 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 37 def create_driver(params) Applitools::Driver.new(browser: params.fetch(:browser, nil)) end |
#open(params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 41 def open(params={}) return driver if disabled? if open? abort_if_not_closed msg = 'a test is alread running' EyesLogger.info(msg) and raise Applitools::EyesError.new(msg) end self.app_name = params.fetch(:app_name) self.failure_reports = params.fetch(:failure_reports, self.failure_reports) self.match_level = params.fetch(:match_level,MatchLevel::EXACT) self.test_name = params.fetch(:test_name) self. = params.fetch(:viewport_size, nil) self.is_open = true driver end |
#open? ⇒ Boolean
60 61 62 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 60 def open? self.is_open end |
#test(params = {}, &block) ⇒ Object
Use this method to perform seamless testing with selenium through eyes driver. Using Selenium methods inside the ‘test’ block will send the messages to Selenium after creating the Eyes triggers for them.
Example:
eyes.test(app_name: 'my app1', test_name: 'my test') do |d|
get "http://www.google.com"
check_window("initial")
end
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 120 def test(params={}, &block) begin previous_driver = Capybara.current_driver previous_browser = Capybara.current_session.driver.instance_variable_get(:@browser) Capybara.current_driver = :selenium Capybara.current_session.driver.instance_variable_set(:@browser, driver) open(params) yield(self, driver) close rescue Applitools::EyesError ensure abort_if_not_closed Capybara.current_session.driver.instance_variable_set(:@browser, previous_browser) Capybara.current_driver = previous_driver end end |