eyes_selenium 1.19.0 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzUwYzEwOGI0MDJiOTdhOWI1MDA5ZDUwNzk3OTFlOGIzM2MwYmY1Ng==
4
+ MDEyOTk3MGRjYmJkZGIxZDk4ZjZhODY2MjMxYjJkZDMzZTQ5NjRiOQ==
5
5
  data.tar.gz: !binary |-
6
- NDQ2MjczNDBjNTA2NDk0M2Q5ZDNiOTFiNzY5Yjg1ZDA3ZjMwNGRmNg==
6
+ ZjllN2EwMDYwZTVlZGEzMWQyMmMxMzE1Yjg0ZTY1ZGQ1MjliNGM4MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjEzMzg5NmYwY2FhZDcwMjMxNTE1YTU5YmE1ZDUyNDdmN2E1ZWM5MDkxOTUx
10
- NTIwMDk1MTMwZDY5YTc1MjMyNTkwZDU4YzgxMTY5YzFjNjRhOTU2MTY0NzEw
11
- NDU3NTZmNGMyNzU4OWY0YTVjYjU0MzM1ZDBlZTkyZDMzNWZhNTM=
9
+ ZTg0NWExYmI0ZGI3N2NjYzRiZGZjOGZkMTQ5ZjExOThhN2E0YjdjZGQ5Mzc5
10
+ YTM2Y2Y4ZDI3ZWI2Y2RlOThmOWRmNTM3M2YxNGU0ZDQzZGI4MGY0NzNhMTE0
11
+ MzdhMWFhMGJmY2YyZDEzN2Q5NGRkN2M5NzZlMjk0NzU2NGQ5MzM=
12
12
  data.tar.gz: !binary |-
13
- NzQwYmE0ZjViOTk1OTAzYzJiZmIwZmVmYmFjODk0NDYyYjhmMjYwY2FhNjIz
14
- M2I3M2MzODY3MTJjZDUxYTEyZGQ0YjhiYWJhYzQxMGMxYjBlNzI1YzU5ZWQx
15
- MWE5YjZiNzBmMTJjYjBkYzMyNjc2OWJhYzM3ODllMjVlMDBiYzM=
13
+ MWRhYTk3NGUyMjc0NWIyN2JkZWE0NTUwMjgxM2UxY2M4MzQ0NTVjZTQ4M2Uw
14
+ Y2EwMDk3NTUyOGNiYTkzMzdmMTk1YzRkNTEyMzBkMTQ3NGI5NTVhMzhlZDM0
15
+ MjY2MWQ1NGNlMWE0NmJjMzI0YTZiZGI4NzgyNTY1YTg4ODZiMGE=
@@ -18,7 +18,6 @@ module Applitools
18
18
  require 'eyes_selenium/utils'
19
19
  require 'eyes_selenium/version'
20
20
  require 'eyes_selenium/eyes/agent_connector'
21
- require 'eyes_selenium/eyes/target_app'
22
21
  require 'eyes_selenium/eyes/batch_info'
23
22
  require 'eyes_selenium/eyes/dimension'
24
23
  require 'eyes_selenium/eyes/driver'
@@ -4,7 +4,7 @@ class Applitools::Driver
4
4
 
5
5
  include Selenium::WebDriver::DriverExtensions::HasInputDevices
6
6
 
7
- attr_reader :remote_server_url, :remote_session_id, :user_agent, :screenshot_taker, :eyes
7
+ attr_reader :remote_server_url, :remote_session_id, :screenshot_taker, :eyes
8
8
  attr_accessor :driver
9
9
 
10
10
  DRIVER_METHODS = [
@@ -20,7 +20,6 @@ class Applitools::Driver
20
20
  @eyes = eyes
21
21
  @remote_server_url = address_of_remote_server
22
22
  @remote_session_id = remote_session_id
23
- @user_agent = get_user_agent
24
23
  begin
25
24
  if driver.capabilities.takes_screenshot?
26
25
  @screenshot_taker = false
@@ -63,10 +62,6 @@ class Applitools::Driver
63
62
  driver.find_elements(by, selector).map { |el| Applitools::Element.new(self, el) }
64
63
  end
65
64
 
66
- def create_application
67
- Applitools::TargetApp.new(remote_server_url, remote_session_id, user_agent)
68
- end
69
-
70
65
  def ie?
71
66
  driver.to_s == 'ie'
72
67
  end
@@ -75,6 +70,12 @@ class Applitools::Driver
75
70
  driver.to_s == 'firefox'
76
71
  end
77
72
 
73
+ def user_agent
74
+ execute_script "return navigator.userAgent"
75
+ rescue => e
76
+ puts "getUserAgent(): Failed to obtain user-agent string (#{e.message})"
77
+ end
78
+
78
79
  private
79
80
 
80
81
  def address_of_remote_server
@@ -93,12 +94,6 @@ class Applitools::Driver
93
94
  driver.remote_session_id
94
95
  end
95
96
 
96
- def get_user_agent
97
- execute_script "return navigator.userAgent"
98
- rescue => e
99
- puts "getUserAgent(): Failed to obtain user-agent string (#{e.message})"
100
- end
101
-
102
97
  def get_local_ip
103
98
  begin
104
99
  Socket.ip_address_list.detect do |intf|
@@ -1,39 +1,51 @@
1
1
  class Applitools::Eyes
2
+
2
3
  DEFAULT_MATCH_TIMEOUT = 2.0
3
4
  AGENT_ID = 'eyes.selenium.ruby/' + Applitools::VERSION
5
+ DEFAULT_EYES_SERVER = 'https://eyes.applitools.com'
4
6
 
5
7
  class << self
6
- attr_accessor :config
8
+ attr_accessor :config, :api_key
7
9
 
8
10
  def log_handler=(handler)
9
11
  EyesLogger.log_handler = handler
10
12
  end
11
13
  end
12
14
 
13
- @config = {
14
- server_url: 'https://eyes.applitools.com',
15
- user: AGENT_ID
16
- # apikey: 'please supply an apikey in your initializer'
17
- }
15
+ # Class instance variables (static variables)
16
+ @config = {}
17
+ @api_key = nil
18
+
19
+ private
20
+ attr_reader :agent_connector
21
+ attr_accessor :session, :session_start_info, :match_window_task, :should_match_window_run_once_on_timeout
18
22
 
19
- attr_reader :agent_connector, :disabled
20
- attr_accessor :app_name, :test_name, :session, :is_open, :aborted, :viewport_size, :match_timeout,
21
- :failure_reports, :test_batch, :match_level, :driver, :host_os, :host_app, :branch_name, :parent_branch_name,
22
- :should_match_window_run_once_on_timeout, :session_start_info, :match_window_task, :user_inputs
23
+ public
24
+ attr_reader :disabled, :app_name, :test_name, :is_open, :viewport_size, :failure_reports, :match_level, :driver
25
+ attr_accessor :match_timeout, :batch, :host_os, :host_app, :branch_name, :parent_branch_name, :user_inputs
23
26
 
24
27
  def config
25
28
  self.class.config
26
29
  end
27
30
 
31
+ def api_key
32
+ self.class.api_key
33
+ end
34
+
28
35
  def initialize(params={})
29
- raise "Please supply an apikey: Eyes.config[:apikey] = ..." unless config[:apikey]
30
36
 
31
37
  @disabled = params[:disabled]
32
38
 
33
39
  return if disabled?
34
40
 
41
+ # TODO Remove this when possible. Allows setting API key using "config" for backwards compatibility.
42
+ self.class.api_key ||= config[:apikey]
43
+
44
+ raise 'Please supply an apikey: Eyes.config[:apikey] = ...' unless api_key
45
+
35
46
  @user_inputs = []
36
- @agent_connector = Applitools::AgentConnector.new(config[:server_url], config[:user], config[:apikey])
47
+ server_url = params.fetch(:server_url, DEFAULT_EYES_SERVER)
48
+ @agent_connector = Applitools::AgentConnector.new(server_url, AGENT_ID, api_key)
37
49
  @match_timeout = DEFAULT_MATCH_TIMEOUT
38
50
  @failure_reports = Applitools::FailureReports::ON_CLOSE
39
51
  end
@@ -43,29 +55,29 @@ class Applitools::Eyes
43
55
  return driver if disabled?
44
56
 
45
57
  if driver.nil? || !driver.is_a?(Selenium::WebDriver::Driver)
46
- raise Applitools::EyesError.new("driver/browser must be a valid Selenium webdriver")
58
+ raise Applitools::EyesError.new('driver/browser must be a valid Selenium webdriver')
47
59
  end
48
60
 
49
- @driver = Applitools::Driver.new(self, {driver: @driver})
61
+ @driver = Applitools::Driver.new(self, {driver: driver})
50
62
 
51
63
  if open?
52
64
  abort_if_not_closed
53
- msg = 'a test is alread running'
65
+ msg = 'a test is already running'
54
66
  EyesLogger.info(msg) and raise Applitools::EyesError.new(msg)
55
67
  end
56
68
 
57
- self.app_name = params.fetch(:app_name)
58
- self.failure_reports = params.fetch(:failure_reports, self.failure_reports)
59
- self.match_level = params.fetch(:match_level,MatchLevel::EXACT)
60
- self.test_name = params.fetch(:test_name)
61
- self.viewport_size = params.fetch(:viewport_size, nil)
69
+ @app_name = params.fetch(:app_name)
70
+ @test_name = params.fetch(:test_name)
71
+ @failure_reports = params.fetch(:failure_reports, self.failure_reports)
72
+ @match_level = params.fetch(:match_level,MatchLevel::EXACT)
73
+ @viewport_size = params.fetch(:viewport_size, nil)
62
74
 
63
- self.is_open = true
75
+ @is_open = true
64
76
  driver
65
77
  end
66
78
 
67
79
  def open?
68
- self.is_open
80
+ is_open
69
81
  end
70
82
 
71
83
  def clear_user_inputs
@@ -74,20 +86,20 @@ class Applitools::Eyes
74
86
 
75
87
  def check_window(tag)
76
88
  return if disabled?
77
- raise Applitools::EyesError.new("Eyes not open") if !open?
78
- if !session
89
+ raise Applitools::EyesError.new('Eyes not open') if !open?
90
+ unless session
79
91
  start_session
80
92
  self.match_window_task = Applitools::MatchWindowTask.new(agent_connector, session, driver, match_timeout)
81
93
  end
82
94
 
83
95
  as_expected = match_window_task.match_window(tag, should_match_window_run_once_on_timeout)
84
- if !as_expected
96
+ unless as_expected
85
97
  self.should_match_window_run_once_on_timeout = true
86
- if !session.new_session?
87
- EyesLogger.info %( "mismatch #{ tag ? "" : "(#{tag})" } )
98
+ unless session.new_session?
99
+ EyesLogger.info %( "mismatch #{ tag ? '' : "(#{tag})" } )
88
100
  if failure_reports.to_i == Applitools::FailureReports::IMMEDIATE
89
- raise Applitools::TestFailedError.new("Mismatch found in '#{start_info.scenario_id_or_name}'"\
90
- " of '#{start_info.app_id_or_name}'")
101
+ raise Applitools::TestFailedError.new("Mismatch found in '#{session_start_info.scenario_id_or_name}'"\
102
+ " of '#{session_start_info.app_id_or_name}'")
91
103
  end
92
104
  end
93
105
  end
@@ -95,7 +107,9 @@ class Applitools::Eyes
95
107
 
96
108
  def close
97
109
  return if disabled?
98
- self.is_open = false
110
+ @is_open = false
111
+
112
+ # if there's no running session, the test was never started (never reached checkWindow)
99
113
  return Applitools::TestResults.new if !session
100
114
 
101
115
  session_results_url = session.url
@@ -128,7 +142,7 @@ class Applitools::Eyes
128
142
  # get "http://www.google.com"
129
143
  # check_window("initial")
130
144
  # end
131
- def test(params={}, &block)
145
+ def test(params={})
132
146
  begin
133
147
  open(params)
134
148
  yield(driver)
@@ -139,19 +153,19 @@ class Applitools::Eyes
139
153
  end
140
154
 
141
155
 
142
- def abort_if_not_closed
143
- return if disabled?
144
- self.is_open = false
145
- if session
146
- begin
147
- agent_connector.stop_session(session,true)
148
- rescue Applitools::EyesError => e
149
- EyesLogger.info "Failed to abort server session -> #{e.message} "
150
- ensure
151
- self.session = nil
152
- end
156
+ def abort_if_not_closed
157
+ return if disabled?
158
+ @is_open = false
159
+ if session
160
+ begin
161
+ agent_connector.stop_session(session,true)
162
+ rescue Applitools::EyesError => e
163
+ EyesLogger.info "Failed to abort server session -> #{e.message} "
164
+ ensure
165
+ self.session = nil
153
166
  end
154
167
  end
168
+ end
155
169
 
156
170
  private
157
171
 
@@ -168,34 +182,34 @@ class Applitools::Eyes
168
182
  params.fetch(:driver, nil)
169
183
  end
170
184
 
185
+ def inferred_environment
186
+ user_agent = driver.user_agent
187
+ if user_agent
188
+ 'useragent:' + user_agent
189
+ end
190
+ end
191
+
171
192
  def start_session
172
193
  assign_viewport_size
173
- test_batch ||= Applitools::BatchInfo.new
174
- application = driver.create_application
175
- inferred = "useragent:" + application.user_agent
176
- app_env = Applitools::Environment.new(host_os, host_app, viewport_size, inferred)
177
- self.session_start_info = Applitools::StartInfo.new(AGENT_ID,
178
- app_name, test_name, test_batch, app_env, application,
179
- match_level,nil, branch_name, parent_branch_name
194
+ self.batch ||= Applitools::BatchInfo.new
195
+ app_env = Applitools::Environment.new(host_os, host_app, viewport_size, inferred_environment)
196
+ self.session_start_info = Applitools::StartInfo.new(
197
+ AGENT_ID, app_name, test_name, batch, app_env, match_level, nil, branch_name, parent_branch_name
180
198
  )
181
199
  self.session = agent_connector.start_session(session_start_info)
182
200
  self.should_match_window_run_once_on_timeout = session.new_session?
183
201
  end
184
202
 
185
203
  def viewport_size?
186
- self.viewport_size
204
+ viewport_size
187
205
  end
188
206
 
189
207
  def assign_viewport_size
190
208
  if viewport_size?
191
- self.viewport_size = Applitools::ViewportSize.new(driver, viewport_size)
192
- self.viewport_size.set
209
+ @viewport_size = Applitools::ViewportSize.new(driver, viewport_size)
210
+ viewport_size.set
193
211
  else
194
- self.viewport_size = Applitools::ViewportSize.new(driver).extract_viewport_from_browser!
212
+ @viewport_size = Applitools::ViewportSize.new(driver).extract_viewport_from_browser!
195
213
  end
196
214
  end
197
-
198
- def to_hash
199
- Hash[dimension.each_pair.to_a]
200
- end
201
215
  end
@@ -1,11 +1,11 @@
1
1
  class Applitools::MouseTrigger
2
2
 
3
- MouseAction = { click: 1, right_click: 2, double_click: 3, move: 4, down: 5, up: 6 }
3
+ MOUSE_ACTION = { click: 'Click', right_click: 'RightClick', double_click: 'DoubleClick', move: 'Move', down: 'Down', up: 'Up' }
4
4
 
5
5
  attr_reader :mouse_action, :control, :location
6
6
 
7
7
  def initialize(mouse_action, control, location)
8
- @mouse_action = MouseAction[mouse_action]
8
+ @mouse_action = MOUSE_ACTION[mouse_action]
9
9
  @control = control
10
10
  @location = location
11
11
  end
@@ -8,16 +8,14 @@ class Applitools::StartInfo
8
8
  end
9
9
 
10
10
  ## add a config file with this stuff, and use hash arg
11
- def initialize(agent_id, app_id_or_name, scenario_id_or_name, batch_info, environment,
12
- application, match_level, ver_id=nil, branch_name=nil,
13
- parent_branch_name=nil)
11
+ def initialize(agent_id, app_id_or_name, scenario_id_or_name, batch_info, environment, match_level, ver_id=nil,
12
+ branch_name=nil, parent_branch_name=nil)
14
13
  @agent_id = agent_id
15
14
  @app_id_or_name = app_id_or_name
16
15
  @ver_id = ver_id
17
16
  @scenario_id_or_name = scenario_id_or_name
18
17
  @batch_info = batch_info
19
18
  @environment = environment
20
- @application = application
21
19
  @match_level = match_level
22
20
  @branch_name = branch_name
23
21
  @parent_branch_name = parent_branch_name
@@ -26,8 +24,7 @@ class Applitools::StartInfo
26
24
  def to_hash
27
25
  {
28
26
  AgentId: agent_id, AppIdOrName: app_id_or_name, VerId: ver_id, ScenarioIdOrName: scenario_id_or_name,
29
- BatchInfo: batch_info.to_hash, Environment: environment.to_hash,
30
- Application: application.to_hash, matchLevel: match_level, branchName: branch_name,
27
+ BatchInfo: batch_info.to_hash, Environment: environment.to_hash, matchLevel: match_level, branchName: branch_name,
31
28
  parentBranchName: parent_branch_name
32
29
  }
33
30
  end
@@ -1,3 +1,3 @@
1
1
  module Applitools
2
- VERSION = "1.19.0"
2
+ VERSION = '1.20.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_selenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Applitools team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-28 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -157,7 +157,6 @@ files:
157
157
  - lib/eyes_selenium/eyes/screenshot_taker.rb
158
158
  - lib/eyes_selenium/eyes/session.rb
159
159
  - lib/eyes_selenium/eyes/start_info.rb
160
- - lib/eyes_selenium/eyes/target_app.rb
161
160
  - lib/eyes_selenium/eyes/test_results.rb
162
161
  - lib/eyes_selenium/eyes/text_trigger.rb
163
162
  - lib/eyes_selenium/eyes/viewport_size.rb
@@ -1,17 +0,0 @@
1
- class Applitools::TargetApp
2
-
3
- attr_reader :url, :session_id, :user_agent
4
-
5
- def initialize(url, session_id, user_agent)
6
- @url = url
7
- @session_id = session_id
8
- @user_agent = user_agent
9
- end
10
-
11
- def to_hash
12
- {
13
- "$type" => "Applitools.Framework.TargetWebDriverApplication, Core",
14
- url: URI.encode(url.to_s), sessionId: session_id, userAgent: user_agent
15
- }
16
- end
17
- end