Class: Applitools::Eyes

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/eyes.rb

Constant Summary collapse

FAILURE_REPORTS =
{
  immediate: 'Immediate',
  on_close: 'OnClose'
}.freeze
MATCH_LEVEL =
{
  none: 'None',
  layout: 'Layout',
  layout2: 'Layout2',
  content: 'Content',
  strict: 'Strict',
  exact: 'Exact'
}.freeze
DEFAULT_MATCH_TIMEOUT =

Seconds

2.0
DEFAULT_WAIT_BEFORE_SCREENSHOTS =

noinspection RubyConstantNamingConvention

0.1
BASE_AGENT_ID =

Seconds

('eyes.selenium.ruby/' + Applitools::VERSION).freeze
ANDROID =
'Android'.freeze
IOS =
'iOS'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Eyes

Returns a new instance of Eyes.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/applitools/eyes.rb', line 104

def initialize(options = {})
  @is_disabled = false

  return if disabled?

  @api_key = nil
  @user_inputs = []

  Applitools::Base::ServerConnector.server_url = options[:server_url]

  @match_timeout = DEFAULT_MATCH_TIMEOUT
  @match_level = Applitools::Eyes::MATCH_LEVEL[:exact]
  @failure_reports = Applitools::Eyes::FAILURE_REPORTS[:on_close]
  @save_new_tests = true
  @save_failed_tests = false
  @dont_get_title = false
  @force_fullpage_screenshot = false
  @hide_scrollbars = false
  @use_css_transition = false
  @wait_before_screenshots = DEFAULT_WAIT_BEFORE_SCREENSHOTS
end

Instance Attribute Details

#agent_idObject

Returns the value of attribute agent_id.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def agent_id
  @agent_id
end

#app_nameObject (readonly)

Attributes:

app_name

String The application name which was provided as an argument to open.

test_name

String The test name which was provided as an argument to open.

is_open

boolean Is there an open session.

viewport_size

Hash The viewport size which was provided as an argument to open. Should include width

and +height+.
driver

Applitools::Selenium::Driver The driver instance wrapping the driver which was provided as an argument

to +open+.
api_key

String The user’s API key.

match_timeout

Float The default timeout for check_XXXX operations. (Seconds)

batch

BatchInfo The current tests grouping, if any.

host_os

String A string identifying the OS running the AUT. Set this if you wish to override Eyes’ automatic

inference.
host_app

String A string identifying the container application running the AUT (e.g., Firefox). Set this if

you wish to override Eyes' automatic inference.
branch_name

String If set, names the branch in which the test should run.

parent_branch_name

String If set, names the parent branch of the branch in which the test should run.

user_inputs

Applitools::Base::MouseTrigger/Applitools::Selenium::KeyboardTrigger Mouse/Keyboard events which

happened after the last visual validation.
save_new_tests

boolean Whether or not new tests should be automatically accepted as baseline.

save_failed_tests

boolean Whether or not failed tests should be automatically accepted as baseline.

match_level

String The default match level for the entire session. See Applitools::Eyes::MATCH_LEVEL.

baseline_name

String A string identifying the baseline which the test will be compared against. Set this if

you wish to override Eyes' automatic baseline inference.
is_disabled

boolean Set to true if you wish to disable Eyes without deleting code (Eyes’ methods act as a

mock, and will do nothing).
server_url

String The Eyes’ server. Set this if you wish to override the default Eyes server URL.

agent_id

String An optional string identifying the current library using the SDK.

log_handler

Logger The logger to which Eyes will send info/debug messages.

failure_reports

String Whether the current test will report mismatches immediately or when it is finished.

See +Applitools::Eyes::FAILURE_REPORTS+.
rotation

Integer|nil The degrees by which to rotate the screenshots received from the driver. Set this to

override Eyes' automatic rotation inference. Positive values = clockwise rotation, negative
values = counter-clockwise, 0 = force no rotation, +nil+ = use Eyes' automatic rotation inference.
scale_ratio

Float|nil The ratio by which to scale the screenshots received from the driver. Set this to

override Eyes' automatic scaling inference. Values must be >=0 or +nil+. 1 = Don't scale, +nil+ = use Eyes'
automatic scaling inference.
force_fullpage_screenshot

boolean Whether or not to force fullpage screenshot taking, if the browser doesn’t

support it explicitly.
hide_scrollbars

boolean Whether or not hide scrollbars.

use_css_transition

boolean Whether or not to perform CSS transition.

wait_before_screenshot

Integer The number of milliseconds to wait before each screenshot. Use -1 to reset to

the default value.


75
76
77
# File 'lib/applitools/eyes.rb', line 75

def app_name
  @app_name
end

#baseline_nameObject

Returns the value of attribute baseline_name.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def baseline_name
  @baseline_name
end

#batchObject

Returns the value of attribute batch.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def batch
  @batch
end

#branch_nameObject

Returns the value of attribute branch_name.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def branch_name
  @branch_name
end

#driverObject (readonly)

Attributes:

app_name

String The application name which was provided as an argument to open.

test_name

String The test name which was provided as an argument to open.

is_open

boolean Is there an open session.

viewport_size

Hash The viewport size which was provided as an argument to open. Should include width

and +height+.
driver

Applitools::Selenium::Driver The driver instance wrapping the driver which was provided as an argument

to +open+.
api_key

String The user’s API key.

match_timeout

Float The default timeout for check_XXXX operations. (Seconds)

batch

BatchInfo The current tests grouping, if any.

host_os

String A string identifying the OS running the AUT. Set this if you wish to override Eyes’ automatic

inference.
host_app

String A string identifying the container application running the AUT (e.g., Firefox). Set this if

you wish to override Eyes' automatic inference.
branch_name

String If set, names the branch in which the test should run.

parent_branch_name

String If set, names the parent branch of the branch in which the test should run.

user_inputs

Applitools::Base::MouseTrigger/Applitools::Selenium::KeyboardTrigger Mouse/Keyboard events which

happened after the last visual validation.
save_new_tests

boolean Whether or not new tests should be automatically accepted as baseline.

save_failed_tests

boolean Whether or not failed tests should be automatically accepted as baseline.

match_level

String The default match level for the entire session. See Applitools::Eyes::MATCH_LEVEL.

baseline_name

String A string identifying the baseline which the test will be compared against. Set this if

you wish to override Eyes' automatic baseline inference.
is_disabled

boolean Set to true if you wish to disable Eyes without deleting code (Eyes’ methods act as a

mock, and will do nothing).
server_url

String The Eyes’ server. Set this if you wish to override the default Eyes server URL.

agent_id

String An optional string identifying the current library using the SDK.

log_handler

Logger The logger to which Eyes will send info/debug messages.

failure_reports

String Whether the current test will report mismatches immediately or when it is finished.

See +Applitools::Eyes::FAILURE_REPORTS+.
rotation

Integer|nil The degrees by which to rotate the screenshots received from the driver. Set this to

override Eyes' automatic rotation inference. Positive values = clockwise rotation, negative
values = counter-clockwise, 0 = force no rotation, +nil+ = use Eyes' automatic rotation inference.
scale_ratio

Float|nil The ratio by which to scale the screenshots received from the driver. Set this to

override Eyes' automatic scaling inference. Values must be >=0 or +nil+. 1 = Don't scale, +nil+ = use Eyes'
automatic scaling inference.
force_fullpage_screenshot

boolean Whether or not to force fullpage screenshot taking, if the browser doesn’t

support it explicitly.
hide_scrollbars

boolean Whether or not hide scrollbars.

use_css_transition

boolean Whether or not to perform CSS transition.

wait_before_screenshot

Integer The number of milliseconds to wait before each screenshot. Use -1 to reset to

the default value.


75
76
77
# File 'lib/applitools/eyes.rb', line 75

def driver
  @driver
end

#failure_reportsObject

Returns the value of attribute failure_reports.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def failure_reports
  @failure_reports
end

#force_fullpage_screenshotObject

Returns the value of attribute force_fullpage_screenshot.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def force_fullpage_screenshot
  @force_fullpage_screenshot
end

#hide_scrollbarsObject

Returns the value of attribute hide_scrollbars.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def hide_scrollbars
  @hide_scrollbars
end

#host_appObject

Returns the value of attribute host_app.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def host_app
  @host_app
end

#host_osObject

Returns the value of attribute host_os.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def host_os
  @host_os
end

#is_disabledObject

Returns the value of attribute is_disabled.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def is_disabled
  @is_disabled
end

#is_openObject (readonly)

Attributes:

app_name

String The application name which was provided as an argument to open.

test_name

String The test name which was provided as an argument to open.

is_open

boolean Is there an open session.

viewport_size

Hash The viewport size which was provided as an argument to open. Should include width

and +height+.
driver

Applitools::Selenium::Driver The driver instance wrapping the driver which was provided as an argument

to +open+.
api_key

String The user’s API key.

match_timeout

Float The default timeout for check_XXXX operations. (Seconds)

batch

BatchInfo The current tests grouping, if any.

host_os

String A string identifying the OS running the AUT. Set this if you wish to override Eyes’ automatic

inference.
host_app

String A string identifying the container application running the AUT (e.g., Firefox). Set this if

you wish to override Eyes' automatic inference.
branch_name

String If set, names the branch in which the test should run.

parent_branch_name

String If set, names the parent branch of the branch in which the test should run.

user_inputs

Applitools::Base::MouseTrigger/Applitools::Selenium::KeyboardTrigger Mouse/Keyboard events which

happened after the last visual validation.
save_new_tests

boolean Whether or not new tests should be automatically accepted as baseline.

save_failed_tests

boolean Whether or not failed tests should be automatically accepted as baseline.

match_level

String The default match level for the entire session. See Applitools::Eyes::MATCH_LEVEL.

baseline_name

String A string identifying the baseline which the test will be compared against. Set this if

you wish to override Eyes' automatic baseline inference.
is_disabled

boolean Set to true if you wish to disable Eyes without deleting code (Eyes’ methods act as a

mock, and will do nothing).
server_url

String The Eyes’ server. Set this if you wish to override the default Eyes server URL.

agent_id

String An optional string identifying the current library using the SDK.

log_handler

Logger The logger to which Eyes will send info/debug messages.

failure_reports

String Whether the current test will report mismatches immediately or when it is finished.

See +Applitools::Eyes::FAILURE_REPORTS+.
rotation

Integer|nil The degrees by which to rotate the screenshots received from the driver. Set this to

override Eyes' automatic rotation inference. Positive values = clockwise rotation, negative
values = counter-clockwise, 0 = force no rotation, +nil+ = use Eyes' automatic rotation inference.
scale_ratio

Float|nil The ratio by which to scale the screenshots received from the driver. Set this to

override Eyes' automatic scaling inference. Values must be >=0 or +nil+. 1 = Don't scale, +nil+ = use Eyes'
automatic scaling inference.
force_fullpage_screenshot

boolean Whether or not to force fullpage screenshot taking, if the browser doesn’t

support it explicitly.
hide_scrollbars

boolean Whether or not hide scrollbars.

use_css_transition

boolean Whether or not to perform CSS transition.

wait_before_screenshot

Integer The number of milliseconds to wait before each screenshot. Use -1 to reset to

the default value.


75
76
77
# File 'lib/applitools/eyes.rb', line 75

def is_open
  @is_open
end

#match_levelObject

Returns the value of attribute match_level.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def match_level
  @match_level
end

#match_timeoutObject

Returns the value of attribute match_timeout.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def match_timeout
  @match_timeout
end

#parent_branch_nameObject

Returns the value of attribute parent_branch_name.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def parent_branch_name
  @parent_branch_name
end

#rotationObject

Returns the value of attribute rotation.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def rotation
  @rotation
end

#save_failed_testsObject

Returns the value of attribute save_failed_tests.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def save_failed_tests
  @save_failed_tests
end

#save_new_testsObject

Returns the value of attribute save_new_tests.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def save_new_tests
  @save_new_tests
end

#scale_ratioObject

Returns the value of attribute scale_ratio.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def scale_ratio
  @scale_ratio
end

#server_urlObject

Returns the value of attribute server_url.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def server_url
  @server_url
end

#test_nameObject (readonly)

Attributes:

app_name

String The application name which was provided as an argument to open.

test_name

String The test name which was provided as an argument to open.

is_open

boolean Is there an open session.

viewport_size

Hash The viewport size which was provided as an argument to open. Should include width

and +height+.
driver

Applitools::Selenium::Driver The driver instance wrapping the driver which was provided as an argument

to +open+.
api_key

String The user’s API key.

match_timeout

Float The default timeout for check_XXXX operations. (Seconds)

batch

BatchInfo The current tests grouping, if any.

host_os

String A string identifying the OS running the AUT. Set this if you wish to override Eyes’ automatic

inference.
host_app

String A string identifying the container application running the AUT (e.g., Firefox). Set this if

you wish to override Eyes' automatic inference.
branch_name

String If set, names the branch in which the test should run.

parent_branch_name

String If set, names the parent branch of the branch in which the test should run.

user_inputs

Applitools::Base::MouseTrigger/Applitools::Selenium::KeyboardTrigger Mouse/Keyboard events which

happened after the last visual validation.
save_new_tests

boolean Whether or not new tests should be automatically accepted as baseline.

save_failed_tests

boolean Whether or not failed tests should be automatically accepted as baseline.

match_level

String The default match level for the entire session. See Applitools::Eyes::MATCH_LEVEL.

baseline_name

String A string identifying the baseline which the test will be compared against. Set this if

you wish to override Eyes' automatic baseline inference.
is_disabled

boolean Set to true if you wish to disable Eyes without deleting code (Eyes’ methods act as a

mock, and will do nothing).
server_url

String The Eyes’ server. Set this if you wish to override the default Eyes server URL.

agent_id

String An optional string identifying the current library using the SDK.

log_handler

Logger The logger to which Eyes will send info/debug messages.

failure_reports

String Whether the current test will report mismatches immediately or when it is finished.

See +Applitools::Eyes::FAILURE_REPORTS+.
rotation

Integer|nil The degrees by which to rotate the screenshots received from the driver. Set this to

override Eyes' automatic rotation inference. Positive values = clockwise rotation, negative
values = counter-clockwise, 0 = force no rotation, +nil+ = use Eyes' automatic rotation inference.
scale_ratio

Float|nil The ratio by which to scale the screenshots received from the driver. Set this to

override Eyes' automatic scaling inference. Values must be >=0 or +nil+. 1 = Don't scale, +nil+ = use Eyes'
automatic scaling inference.
force_fullpage_screenshot

boolean Whether or not to force fullpage screenshot taking, if the browser doesn’t

support it explicitly.
hide_scrollbars

boolean Whether or not hide scrollbars.

use_css_transition

boolean Whether or not to perform CSS transition.

wait_before_screenshot

Integer The number of milliseconds to wait before each screenshot. Use -1 to reset to

the default value.


75
76
77
# File 'lib/applitools/eyes.rb', line 75

def test_name
  @test_name
end

#use_css_transitionObject

Returns the value of attribute use_css_transition.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def use_css_transition
  @use_css_transition
end

#user_inputsObject

Returns the value of attribute user_inputs.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def user_inputs
  @user_inputs
end

#viewport_sizeObject (readonly)

Attributes:

app_name

String The application name which was provided as an argument to open.

test_name

String The test name which was provided as an argument to open.

is_open

boolean Is there an open session.

viewport_size

Hash The viewport size which was provided as an argument to open. Should include width

and +height+.
driver

Applitools::Selenium::Driver The driver instance wrapping the driver which was provided as an argument

to +open+.
api_key

String The user’s API key.

match_timeout

Float The default timeout for check_XXXX operations. (Seconds)

batch

BatchInfo The current tests grouping, if any.

host_os

String A string identifying the OS running the AUT. Set this if you wish to override Eyes’ automatic

inference.
host_app

String A string identifying the container application running the AUT (e.g., Firefox). Set this if

you wish to override Eyes' automatic inference.
branch_name

String If set, names the branch in which the test should run.

parent_branch_name

String If set, names the parent branch of the branch in which the test should run.

user_inputs

Applitools::Base::MouseTrigger/Applitools::Selenium::KeyboardTrigger Mouse/Keyboard events which

happened after the last visual validation.
save_new_tests

boolean Whether or not new tests should be automatically accepted as baseline.

save_failed_tests

boolean Whether or not failed tests should be automatically accepted as baseline.

match_level

String The default match level for the entire session. See Applitools::Eyes::MATCH_LEVEL.

baseline_name

String A string identifying the baseline which the test will be compared against. Set this if

you wish to override Eyes' automatic baseline inference.
is_disabled

boolean Set to true if you wish to disable Eyes without deleting code (Eyes’ methods act as a

mock, and will do nothing).
server_url

String The Eyes’ server. Set this if you wish to override the default Eyes server URL.

agent_id

String An optional string identifying the current library using the SDK.

log_handler

Logger The logger to which Eyes will send info/debug messages.

failure_reports

String Whether the current test will report mismatches immediately or when it is finished.

See +Applitools::Eyes::FAILURE_REPORTS+.
rotation

Integer|nil The degrees by which to rotate the screenshots received from the driver. Set this to

override Eyes' automatic rotation inference. Positive values = clockwise rotation, negative
values = counter-clockwise, 0 = force no rotation, +nil+ = use Eyes' automatic rotation inference.
scale_ratio

Float|nil The ratio by which to scale the screenshots received from the driver. Set this to

override Eyes' automatic scaling inference. Values must be >=0 or +nil+. 1 = Don't scale, +nil+ = use Eyes'
automatic scaling inference.
force_fullpage_screenshot

boolean Whether or not to force fullpage screenshot taking, if the browser doesn’t

support it explicitly.
hide_scrollbars

boolean Whether or not hide scrollbars.

use_css_transition

boolean Whether or not to perform CSS transition.

wait_before_screenshot

Integer The number of milliseconds to wait before each screenshot. Use -1 to reset to

the default value.


75
76
77
# File 'lib/applitools/eyes.rb', line 75

def viewport_size
  @viewport_size
end

#wait_before_screenshotsObject

Returns the value of attribute wait_before_screenshots.



76
77
78
# File 'lib/applitools/eyes.rb', line 76

def wait_before_screenshots
  @wait_before_screenshots
end

Instance Method Details

#abort_if_not_closedObject



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/applitools/eyes.rb', line 311

def abort_if_not_closed
  return if disabled?

  @is_open = false

  return unless @session

  begin
    Applitools::Base::ServerConnector.stop_session(@session, true, false)
  rescue => e
    Applitools::EyesLogger.error "Failed to abort server session: #{e.message}!"
  ensure
    @session = nil
  end
end

#check_region(how, what, tag = nil, specific_timeout = -1)) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/applitools/eyes.rb', line 185

def check_region(how, what, tag = nil, specific_timeout = -1)
  Applitools::EyesLogger.debug 'check_region called'
  return if disabled?

  # We have to start the session if it's not started, since we want the viewport size to be set before getting the
  # element's position and size
  raise Applitools::EyesError.new('Eyes not open') unless open?

  unless @session
    Applitools::EyesLogger.debug 'Starting session...'
    start_session
    Applitools::EyesLogger.debug 'Done! Creating match window task...'
    @match_window_task = Applitools::Selenium::MatchWindowTask.new(self, @session, driver, match_timeout)
    Applitools::EyesLogger.debug 'Done!'
  end

  original_overflow = driver.hide_scrollbars if hide_scrollbars
  begin
    if how == :element
      Applitools::EyesLogger.debug 'Element given as an argument...'
      raise Applitools::EyesError.new('Element does not exist') if what.nil?
      element_to_check = what
    else
      Applitools::EyesLogger.debug 'Finding element...'
      element_to_check = driver.find_element(how, what)
    end

    Applitools::EyesLogger.debug 'Done! Getting element location...'
    location = element_to_check.location
    Applitools::EyesLogger.debug 'Done! Getting element size...'
    size = element_to_check.size
    raise Applitools::EyesError.new("Invalid region size: #{size}") if size.width <= 0 || size.height <= 0
    Applitools::EyesLogger.debug 'Done! Creating region...'
    region = Applitools::Base::Region.new(location.x, location.y, size.width, size.height)
    Applitools::EyesLogger.debug "Done! Checking region... #{region}"
    check_region_(region, tag, specific_timeout)
    Applitools::EyesLogger.debug 'Done!'
  ensure
    driver.set_overflow(original_overflow) if hide_scrollbars
  end
end

#check_window(tag = nil, specific_timeout = -1)) ⇒ Object



227
228
229
230
231
232
233
234
# File 'lib/applitools/eyes.rb', line 227

def check_window(tag = nil, specific_timeout = -1)
  original_overflow = driver.hide_scrollbars if hide_scrollbars
  begin
    check_region_(Applitools::Base::Region::EMPTY, tag, specific_timeout)
  ensure
    driver.set_overflow(original_overflow) if hide_scrollbars
  end
end

#clear_user_inputsObject



181
182
183
# File 'lib/applitools/eyes.rb', line 181

def clear_user_inputs
  user_inputs.clear
end

#close(raise_ex = true) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/applitools/eyes.rb', line 236

def close(raise_ex = true)
  return if disabled?
  @is_open = false

  # If there's no running session, the test was never started (never reached check_window).
  unless @session
    Applitools::EyesLogger.debug 'Server session was not started'
    Applitools::EyesLogger.info '--- Empty test ended.'

    return Applitools::Base::TestResults.new
  end

  session_results_url = @session.url
  new_session = @session.new_session?
  Applitools::EyesLogger.debug 'Ending server session...'
  save = (new_session && save_new_tests) || (!new_session && save_failed_tests)
  results = Applitools::Base::ServerConnector.stop_session(@session, false, save)
  results.is_new = new_session
  results.url = session_results_url
  Applitools::EyesLogger.debug "Results: #{results}"

  @session = nil

  if new_session
    instructions = "Please approve the new baseline at #{session_results_url}"
    Applitools::EyesLogger.info "--- New test ended. #{instructions}"

    if raise_ex
      message = "'#{@session_start_info.scenario_id_or_name}' of '#{@session_start_info.app_id_or_name}'. "\
        "#{instructions}"

      raise Applitools::NewTestError.new(message, results)
    end

    return results
  end

  unless results.passed?
    # Test failed
    Applitools::EyesLogger.info "--- Failed test ended. See details at #{session_results_url}"

    if raise_ex
      message = "'#{@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(message, results)
    end

    return results
  end

  # Test passed
  Applitools::EyesLogger.info "--- Test passed. See details at #{session_results_url}"

  results
end

#full_agent_idObject



88
89
90
# File 'lib/applitools/eyes.rb', line 88

def full_agent_id
  @full_agent_id ||= agent_id.nil? ? BASE_AGENT_ID : "#{agent_id} [#{BASE_AGENT_ID}]"
end

#open(options = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/applitools/eyes.rb', line 126

def open(options = {})
  @driver = get_driver(options)
  return driver if disabled?

  if api_key.nil?
    raise Applitools::EyesError.new('API key not set! Log in to https://applitools.com to obtain your API Key and '\
      "use 'api_key' to set it.")
  end

  if driver.is_a?(Selenium::WebDriver::Driver)
    is_mobile_device = driver.capabilities['platformName'] ? true : false
    @driver = Applitools::Selenium::Driver.new(self, driver: driver, is_mobile_device: is_mobile_device)
  elsif defined?(Appium::Driver) && driver.is_a?(Appium::Driver)
    @driver = Applitools::Selenium::Driver.new(self, driver: driver.driver, is_mobile_device: true)
  elsif defined?(Watir::Browser) && driver.is_a?(Watir::Browser)
    is_mobile_device = driver.driver.capabilities['platformName'] ? true : false
    @driver = Applitools::Selenium::Driver.new(self, driver: driver.driver, is_mobile_device: is_mobile_device)
  else
    unless driver.is_a?(Applitools::Selenium::Driver)
      Applitools::EyesLogger.warn("Unrecognized driver type: (#{driver.class.name})!")
      is_mobile_device = driver.respond_to?(:capabilities) && driver.capabilities['platformName']
      @driver = Applitools::Selenium::Driver.new(self, driver: driver, is_mobile_device: is_mobile_device)
    end
  end

  @driver.wait_before_screenshots = wait_before_screenshots

  if open?
    abort_if_not_closed
    msg = 'a test is already running'
    Applitools::EyesLogger.warn(msg)

    raise Applitools::EyesError.new(msg)
  end

  @user_inputs = []
  @app_name = options.fetch(:app_name)
  if @app_name.nil? || @app_name.empty?
    raise Applitools::EyesError.new('App name must be a non empty string.')
  end
  @test_name = options.fetch(:test_name)
  if @test_name.nil? || @test_name.empty?
    raise Applitools::EyesError.new('Test name must be a non empty string.')
  end
  @viewport_size = options.fetch(:viewport_size, nil)

  @is_open = true

  driver
end

#open?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/applitools/eyes.rb', line 177

def open?
  is_open
end

#test(options = {}, &_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

noinspection RubyUnusedLocalVariable



303
304
305
306
307
308
309
# File 'lib/applitools/eyes.rb', line 303

def test(options = {}, &_block)
  open(options)
  yield(driver)
  close
ensure
  abort_if_not_closed
end

#titleObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/applitools/eyes.rb', line 92

def title
  unless @dont_get_title
    begin
      return driver.title
    rescue
      @dont_get_title = true
    end
  end

  ''
end