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
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.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 23 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.
5 6 7 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 5 def config @config end |
Instance Attribute Details
#aborted ⇒ Object
Returns the value of attribute aborted.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def aborted @aborted end |
#agent_connector ⇒ Object (readonly)
Returns the value of attribute agent_connector.
14 15 16 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 14 def agent_connector @agent_connector end |
#app_name ⇒ Object
Returns the value of attribute app_name.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def app_name @app_name end |
#branch_name ⇒ Object
Returns the value of attribute branch_name.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def branch_name @branch_name end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
14 15 16 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 14 def disabled @disabled end |
#driver ⇒ Object
Returns the value of attribute driver.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def driver @driver end |
#failure_reports ⇒ Object
Returns the value of attribute failure_reports.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def failure_reports @failure_reports end |
#host_app ⇒ Object
Returns the value of attribute host_app.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def host_app @host_app end |
#host_os ⇒ Object
Returns the value of attribute host_os.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def host_os @host_os end |
#is_open ⇒ Object
Returns the value of attribute is_open.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def is_open @is_open end |
#match_level ⇒ Object
Returns the value of attribute match_level.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def match_level @match_level end |
#match_timeout ⇒ Object
Returns the value of attribute match_timeout.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def match_timeout @match_timeout end |
#match_window_task ⇒ Object
Returns the value of attribute match_window_task.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def match_window_task @match_window_task end |
#parent_branch_name ⇒ Object
Returns the value of attribute parent_branch_name.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def parent_branch_name @parent_branch_name end |
#session ⇒ Object
Returns the value of attribute session.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def session @session end |
#session_start_info ⇒ Object
Returns the value of attribute session_start_info.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 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.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 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.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def test_batch @test_batch end |
#test_name ⇒ Object
Returns the value of attribute test_name.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def test_name @test_name end |
#viewport_size ⇒ Object
Returns the value of attribute viewport_size.
15 16 17 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 15 def end |
Instance Method Details
#abort_if_not_closed ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 131 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.message} " ensure self.session = nil end end end |
#check_window(tag) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 63 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 84 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
19 20 21 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 19 def config self.class.config end |
#create_driver(params) ⇒ Object
36 37 38 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 36 def create_driver(params) Applitools::Driver.new(browser: params.fetch(:browser, nil)) end |
#open(params = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 40 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(:view_port_size, nil) self.is_open = true driver end |
#open? ⇒ Boolean
59 60 61 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 59 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/eyes_selenium_ruby/eyes/eyes.rb', line 119 def test(params={}, &block) begin previous_driver = .current_driver previous_browser = .current_session.driver.instance_variable_get(:@browser) .current_driver = :selenium .current_session.driver.instance_variable_set(:@browser, driver) open(params) yield(self, driver) close rescue Applitools::EyesError ensure abort_if_not_closed .current_session.driver.instance_variable_set(:@browser, previous_browser) .current_driver = previous_driver end end |