Module: Applitools::Selenium::Concerns::SeleniumEyes

Included in:
SeleniumEyes, VisualGridEyes
Defined in:
lib/applitools/selenium/concerns/selenium_eyes.rb

Constant Summary collapse

USE_DEFAULT_MATCH_TIMEOUT =
-1

Instance Method Summary collapse

Instance Method Details

#check_frame(options = {}) ⇒ Applitools::MatchResult

Validates the contents of an iframe and matches it with the expected output.

Parameters:

  • options (Hash) (defaults to: {})

    The specific parameters of the desired screenshot.

Options Hash (options):

  • :timeout (Fixnum)

    The amount of time to retry matching. (Seconds)

  • :tag (String)

    An optional tag to be associated with the snapshot.

  • :frame (String)

    Frame element or frame name or frame id.

  • :name_or_id (String)

    The name or id of the target frame (deprecated. use :frame instead).

  • :frame_element (String)

    The frame element (deprecated. use :frame instead).

Returns:

  • (Applitools::MatchResult)

    The match results.



95
96
97
98
99
100
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 95

def check_frame(options = {})
  options = { timeout: USE_DEFAULT_MATCH_TIMEOUT, tag: nil }.merge!(options)
  frame = options[:frame] || options[:frame_element] || options[:name_or_id]
  target = Applitools::Selenium::Target.frame(frame).timeout(options[:timeout]).fully
  check(options[:tag], target)
end

#check_in_frame(options) ⇒ Object

Validates the contents of an iframe and matches it with the expected output.

Parameters:

  • options (Hash)

    The specific parameters of the desired screenshot.

Options Hash (options):

  • :target_frames (Array)

    The frames to check.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 13

def check_in_frame(options)
  Applitools::ArgumentGuard.is_a? options, 'options', Hash

  frames = options.delete :target_frames

  Applitools::ArgumentGuard.is_a? frames, 'target_frames: []', Array

  return yield if block_given? && frames.empty?

  original_frame_chain = driver.frame_chain

  logger.info 'Switching to target frame according to frames path...'
  driver.switch_to.frames(frames_path: frames)
  frame_chain_to_reset = driver.frame_chain
  logger.info 'Done!'

  ensure_frame_visible

  yield if block_given?

  reset_frames_scroll_position(frame_chain_to_reset)

  logger.info 'Switching back into top level frame...'
  driver.switch_to.default_content
  return unless original_frame_chain
  logger.info 'Switching back into original frame...'
  driver.switch_to.frames frame_chain: original_frame_chain
end

#check_region(element, how = nil, what = nil, options = {}) ⇒ Object

Takes a snapshot of the application under test and matches a region of a specific element with the expected region output.

Examples:

Check region by element

check_region(element, tag: 'Check a region by element', match_timeout: 3, stitch_content: false)

Check region by css selector

check_region(:css, '.form-row .input#e_mail', tag: 'Check a region by element', match_timeout: 3,
stitch_content: false)

Parameters:

  • element (Applitools::Selenium::Element)

    Represents a region to check.

  • how (Symbol) (defaults to: nil)

    a finder, such :css or :id. Selects a finder will be used to find an element See Selenium::Webdriver::Element#find_element documentation for full list of possible finders.

  • what (String) (defaults to: nil)

    The value will be passed to a specified finder. If finder is :css it must be a css selector.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :tag (String)

    An optional tag to be associated with the snapshot.

  • :match_timeout (Fixnum)

    The amount of time to retry matching. (Seconds)

  • :stitch_content (Boolean)

    If set to true, will try to get full content of the element (including hidden content due overflow settings) by scrolling the element, taking and stitching partial screenshots.



78
79
80
81
82
83
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 78

def check_region(*args)
  options = { timeout: USE_DEFAULT_MATCH_TIMEOUT, tag: nil }.merge! Applitools::Utils.extract_options!(args)
  target = Applitools::Selenium::Target.new.region(*args).timeout(options[:match_timeout])
  target.fully if options[:stitch_content]
  check(options[:tag], target)
end

#check_region_in_frame(options = {}) ⇒ Applitools::MatchResult

Validates the contents of a region in an iframe and matches it with the expected output.

Parameters:

  • options (Hash) (defaults to: {})

    The specific parameters of the desired screenshot.

Options Hash (options):

  • :name_or_id (String)

    The name or id of the target frame (deprecated. use :frame instead).

  • :frame_element (String)

    The frame element (deprecated. use :frame instead).

  • :frame (String)

    Frame element or frame name or frame id.

  • :tag (String)

    An optional tag to be associated with the snapshot.

  • :by (Symbol)

    By which identifier to find the region (e.g :css, :id).

  • :timeout (Fixnum)

    The amount of time to retry matching. (Seconds)

  • :stitch_content (Boolean)

    Whether to stitch the content or not.

Returns:

  • (Applitools::MatchResult)

    The match results.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 113

def check_region_in_frame(options = {})
  options = { timeout: USE_DEFAULT_MATCH_TIMEOUT, tag: nil, stitch_content: false }.merge!(options)
  Applitools::ArgumentGuard.not_nil options[:by], 'options[:by]'
  Applitools::ArgumentGuard.is_a? options[:by], 'options[:by]', Array

  how_what = options.delete(:by)
  frame = options[:frame] || options[:frame_element] || options[:name_or_id]

  target = Applitools::Selenium::Target.new.timeout(options[:timeout])
  target.frame(frame) if frame
  target.fully if options[:stitch_content]
  target.region(*how_what)

  check(options[:tag], target)
end

#check_window(*args) ⇒ Object

Takes a snapshot of the application under test and matches it with the expected output.

def check_window(tag = nil, match_timeout = USE_DEFAULT_MATCH_TIMEOUT)

Parameters:

  • tag (String)

    An optional tag to be assosiated with the snapshot.

  • match_timeout (Fixnum)

    The amount of time to retry matching (seconds)



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 47

def check_window(*args)
  tag = args.select { |a| a.is_a?(String) || a.is_a?(Symbol) }.first
  match_timeout = args.select { |a| a.is_a?(Integer) }.first
  fully = args.select { |a| a.is_a?(TrueClass) || a.is_a?(FalseClass) }.first
  target = Applitools::Selenium::Target.window.tap do |t|
    t.timeout(match_timeout || USE_DEFAULT_MATCH_TIMEOUT)
    # fully = force_full_page_screenshot if fully.nil?
    t.fully(fully) if !fully.nil?
  end
  check(tag, target)
end

#test(options = {}) {|driver| ... } ⇒ Object

Use this method to perform seamless testing with selenium through eyes driver. It yields a block and passes to it an Applitools::Selenium::Driver instance, which wraps standard driver. Using Selenium methods inside the ‘test’ block will send the messages to Selenium after creating the Eyes triggers for them. Options are similar to open

Examples:

eyes.test(app_name: 'my app', test_name: 'my test') do |driver|
   driver.get "http://www.google.com"
   driver.check_window("initial")
end

Yield Parameters:



140
141
142
143
144
145
146
# File 'lib/applitools/selenium/concerns/selenium_eyes.rb', line 140

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