Class: Applitools::Appium::Target

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FluentInterface

#enable_patterns, #ignore_caret, #ignore_displacements, #ignore_mismatch, included, #match_level, #timeout, #trim

Methods included from MatchLevelSetter

#match_level_with_exact

Constructor Details

#initializeTarget

Returns a new instance of Target.



19
20
21
22
23
24
25
26
27
28
# File 'lib/applitools/appium/target.rb', line 19

def initialize
  self.region_to_check = proc { Applitools::Region::EMPTY }
  self.ignored_regions = []
  self.floating_regions = []
  self.layout_regions = []
  self.content_regions = []
  self.strict_regions = []
  self.accessibility_regions = []
  self.options = {}
end

Instance Attribute Details

#accessibility_regionsObject

Returns the value of attribute accessibility_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def accessibility_regions
  @accessibility_regions
end

#content_regionsObject

Returns the value of attribute content_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def content_regions
  @content_regions
end

#floating_regionsObject

Returns the value of attribute floating_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def floating_regions
  @floating_regions
end

#ignored_regionsObject

Returns the value of attribute ignored_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def ignored_regions
  @ignored_regions
end

#layout_regionsObject

Returns the value of attribute layout_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def layout_regions
  @layout_regions
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def options
  @options
end

#region_to_checkObject

Returns the value of attribute region_to_check.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def region_to_check
  @region_to_check
end

#strict_regionsObject

Returns the value of attribute strict_regions.



7
8
9
# File 'lib/applitools/appium/target.rb', line 7

def strict_regions
  @strict_regions
end

Class Method Details

.region(*args) ⇒ Object



14
15
16
# File 'lib/applitools/appium/target.rb', line 14

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

.windowObject



10
11
12
# File 'lib/applitools/appium/target.rb', line 10

def window
  new
end

Instance Method Details

#accessibility(*args) ⇒ Object



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
176
# File 'lib/applitools/appium/target.rb', line 128

def accessibility(*args)
  options = Applitools::Utils.extract_options! args
  unless options[:type]
    raise Applitools::EyesError,
          'You should call Target.accessibility(region, type: type). The region_type option is required'
  end
  unless Applitools::AccessibilityRegionType.enum_values.include?(options[:type])
    raise Applitools::EyesIllegalArgument,
          "The region type should be one of [#{Applitools::AccessibilityRegionType.enum_values.join(', ')}]"
  end

  accessibility_regions << case args.first
                           when ::Selenium::WebDriver::Element
                             element = args.first
                             Applitools::AccessibilityRegion.new(
                               element,
                               options[:type]
                             )
                           when Applitools::Region
                             result = Applitools::AccessibilityRegion.new(
                                 args.first, options[:type]
                             )
                             if Applitools::Appium::Utils.ios?(Applitools::Appium::Driver::AppiumLib)
                               def result.converted?
                                 true
                               end
                             end
                             result
                           when String
                             proc do |driver|
                               element = driver.find_element(name_or_id: args.first)
                               Applitools::AccessibilityRegion.new(
                                 element,
                                 options[:type]
                               )
                             end
                           else
                             proc do |driver|
                               elements = driver.find_elements(*args)
                               elements.map do |e|
                                 Applitools::AccessibilityRegion.new(
                                   e,
                                   options[:type]
                                 )
                               end
                             end
                           end
  self
end

#content(*args) ⇒ Object



110
111
112
113
114
115
# File 'lib/applitools/appium/target.rb', line 110

def content(*args)
  return match_level(Applitools::MatchLevel::CONTENT) if args.empty?
  region = process_region(*args)
  content_regions << region
  self
end

#exact(*args) ⇒ Object



124
125
126
# File 'lib/applitools/appium/target.rb', line 124

def exact(*args)
  match_level(Applitools::MatchLevel::EXACT, *args)
end

#finalizeObject



178
179
180
# File 'lib/applitools/appium/target.rb', line 178

def finalize
  self
end

#floating(*args) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/applitools/appium/target.rb', line 74

def floating(*args)
  value = case args.first
          when Applitools::FloatingRegion
            args.first
          when Applitools::Region
            result = Applitools::FloatingRegion.any(*args)
            if Applitools::Appium::Utils.ios?(Applitools::Appium::Driver::AppiumLib)
              def result.converted?
                true
              end
            end
            result
          when ::Selenium::WebDriver::Element
            args_dup = args.dup
            Applitools::FloatingRegion.any(*args_dup)
          else
            proc do |driver|
              args_dup = args.dup
              region = driver.find_element(args_dup.shift, args_dup.shift)
              Applitools::FloatingRegion.any(
                  region, *args_dup
              )
            end
          end
  floating_regions << value
  self
end

#ignore(*args) ⇒ Object



42
43
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
# File 'lib/applitools/appium/target.rb', line 42

def ignore(*args)
  requested_padding = if args.last.is_a? Applitools::PaddingBounds
                        args.pop
                      else
                        Applitools::PaddingBounds::ZERO_PADDING
                      end
  ignored_regions <<  case (first_argument = args.first)
                      when ::Selenium::WebDriver::Element
                        proc do
                          Applitools::Region
                            .from_location_size(first_argument.location, first_argument.size)
                            .padding(requested_padding)
                        end
                      when Applitools::Region
                        result = first_argument.padding(requested_padding)
                        if Applitools::Appium::Utils.ios?(Applitools::Appium::Driver::AppiumLib)
                          def result.converted?
                            true
                          end
                        end
                        result
                      else
                        proc do |driver|
                          element = driver.find_element(*args)
                          Applitools::Region
                            .from_location_size(element.location, element.size)
                            .padding(requested_padding)
                        end
                      end
  self
end

#layoutObject



102
103
104
105
106
107
108
# File 'lib/applitools/appium/target.rb', line 102

def layout
  return match_level(Applitools::MatchLevel::LAYOUT) if args.empty?
  region = process_region(*args)
  layout_regions << region
self

end

#region(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/applitools/appium/target.rb', line 30

def region(*args)
  self.region_to_check = case args.first
                         when ::Selenium::WebDriver::Element
                           proc { args.first }
                         else
                           proc do |driver|
                             driver.find_element(*args)
                           end
                         end
  self
end

#strict(*args) ⇒ Object



117
118
119
120
121
122
# File 'lib/applitools/appium/target.rb', line 117

def strict(*args)
  return match_level(Applitools::MatchLevel::STRICT) if args.empty?
  region = process_region(*args)
  strict_regions << region
  self
end