Class: Applitools::Selenium::Target

Inherits:
Object
  • Object
show all
Includes:
FluentInterface
Defined in:
lib/applitools/selenium/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTarget

Initialize a Applitools::Selenium::Target instance.



27
28
29
30
31
32
33
34
35
# File 'lib/applitools/selenium/target.rb', line 27

def initialize
  self.frames = []
  self.options = {
    ignore_caret: true,
    ignore_mismatch: false,
    send_dom: nil
  }
  reset_for_fullscreen
end

Instance Attribute Details

#coordinate_typeObject

Returns the value of attribute coordinate_type.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def coordinate_type
  @coordinate_type
end

#elementObject

Returns the value of attribute element.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def element
  @element
end

#floating_regionsObject

Returns the value of attribute floating_regions.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def floating_regions
  @floating_regions
end

#framesObject

Returns the value of attribute frames.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def frames
  @frames
end

#ignored_regionsObject

Returns the value of attribute ignored_regions.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def ignored_regions
  @ignored_regions
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def options
  @options
end

#region_to_checkObject

Returns the value of attribute region_to_check.



21
22
23
# File 'lib/applitools/selenium/target.rb', line 21

def region_to_check
  @region_to_check
end

Class Method Details

.frame(element) ⇒ Object



8
9
10
# File 'lib/applitools/selenium/target.rb', line 8

def frame(element)
  new.frame(element)
end

.region(*args) ⇒ Object



16
17
18
# File 'lib/applitools/selenium/target.rb', line 16

def region(*args)
  new.region(*args)
end

.windowObject



12
13
14
# File 'lib/applitools/selenium/target.rb', line 12

def window
  new
end

Instance Method Details

#finalizeObject



176
177
178
179
180
181
# File 'lib/applitools/selenium/target.rb', line 176

def finalize
  return self unless frame_or_element
  region = frame_or_element
  self.frame_or_element = nil
  dup.region(region)
end

#floating(region_or_element, bounds, left, top, right, bottom, padding) ⇒ Object

Sets the wanted floating region

Examples:

target.floating(:id, 'my_id', 10, 10, 10, 10)
target.floating(:id, 'my_id', Applitools::FloatingBounds.new(10, 10, 10, 10))
target.floating(region, Applitools::FloatingBounds.new(10, 10, 10, 10))
target.floating(floating_region)
target.floating(floating_region, bounds)
target.floating(:id, 'my_id', Applitools::FloatingBounds.new(10, 10, 10, 10), Applitools::PaddingBounds.new(10, 10, 10, 10))

Parameters:

  • region_or_element (Applitools::FloatingRegion, Selenium::WebDriver::Element, Applitools::Selenium::Element, Applitools::Region)
  • bounds (Applitools::FloatingBounds)
  • left (Integer)
  • top (Integer)
  • right (Integer)
  • bottom (Integer)
  • padding (Applitools::PaddingBounds)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/applitools/selenium/target.rb', line 99

def floating(*args)
  requested_padding = if args.last.is_a? Applitools::PaddingBounds
                        args.pop
                      else
                        Applitools::PaddingBounds::PIXEL_PADDING
                      end
  value = case args.first
          when Applitools::FloatingRegion
            proc { args.first.padding(requested_padding) }
          when ::Selenium::WebDriver::Element, Applitools::Selenium::Element, ::Applitools::Region
            proc { Applitools::FloatingRegion.any(args.shift, *args).padding(requested_padding) }
          else
            proc do |driver|
              Applitools::FloatingRegion.any(
                driver.find_element(args.shift, args.shift), *args
              ).padding(requested_padding)
            end
          end
  floating_regions << value
  self
end

#frame(element) ⇒ Object



127
128
129
130
131
132
# File 'lib/applitools/selenium/target.rb', line 127

def frame(element)
  frames << frame_or_element if frame_or_element
  self.frame_or_element = element
  reset_for_fullscreen
  self
end

#fullyObject



121
122
123
124
125
# File 'lib/applitools/selenium/target.rb', line 121

def fully
  options[:stitch_content] = true
  handle_frames
  self
end

#ignore(region_or_element, how, what, padding = Applitools::PaddingBounds::PIXEL_PADDING) ⇒ Object

Add the wanted ignored regions.

Parameters:

  • region_or_element (Applitools::Selenium::Element, Applitools::Region, ::Selenium::WebDriver::Element)

    the region to ignore or an element representing the region to ignore

  • how (Symbol, String)

    A finder to be used (see Selenium::WebDriver documentation for complete list of available finders)

  • what (Symbol, String)

    An id or selector to find



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/applitools/selenium/target.rb', line 44

def ignore(*args)
  if args.empty?
    reset_ignore
  else
    requested_padding = if args.last.is_a? Applitools::PaddingBounds
                          args.pop
                        else
                          Applitools::PaddingBounds::PIXEL_PADDING
                        end
    ignored_regions << case args.first
                       when Applitools::Region
                         proc { args.first.padding(requested_padding) }
                       when Applitools::Selenium::Element, ::Selenium::WebDriver::Element
                         proc do
                           region = args.first
                           Applitools::Region.from_location_size(
                             region.location, region.size
                           ).padding(requested_padding)
                         end
                       else
                         proc do |driver|
                           region = driver.find_element(*args)
                           Applitools::Region.from_location_size(
                             region.location, region.size
                           ).padding(requested_padding)
                         end
                       end

  end
  self
end

#region(element, how, what) ⇒ Applitools::Selenium::Target

Add the desired region.

Examples:

Add region by element

target.region(an_element)

Add target region by finder

target.region(:id, 'target_region')

Parameters:

  • element (Applitools::Selenium::Element, Applitools::Region, ::Selenium::WebDriver::Element)

    the target region or an element representing the target region

  • how (Symbol, String)

    The finder to be used (:css, :id, etc. see Selenium::WebDriver documentation for complete list of available finders)

  • what (Symbol, String)

    Selector or id of an element

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/applitools/selenium/target.rb', line 145

def region(*args)
  handle_frames
  self.region_to_check = case args.first
                         when Applitools::Selenium::Element, Applitools::Region, ::Selenium::WebDriver::Element
                           proc { args.first }
                         when String
                           proc do |driver|
                             driver.find_element(name_or_id: args.first)
                           end
                         else
                           proc do |driver|
                             driver.find_element(*args)
                           end
                         end
  self.coordinate_type = Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative]
  options[:timeout] = nil
  reset_ignore
  reset_floating
  self
end

#send_dom(value = true) ⇒ Object



166
167
168
169
# File 'lib/applitools/selenium/target.rb', line 166

def send_dom(value = true)
  options[:send_dom] = value ? true : false
  self
end

#use_dom(value = true) ⇒ Object



171
172
173
174
# File 'lib/applitools/selenium/target.rb', line 171

def use_dom(value = true)
  options[:use_dom] = value ? true : false
  self
end