Class: Applitools::Images::Target
- Inherits:
-
Object
- Object
- Applitools::Images::Target
- Includes:
- FluentInterface
- Defined in:
- lib/applitools/images/target.rb
Instance Attribute Summary collapse
-
#accessibility_regions ⇒ Object
Returns the value of attribute accessibility_regions.
-
#floating_regions ⇒ Object
Returns the value of attribute floating_regions.
-
#ignored_regions ⇒ Object
Returns the value of attribute ignored_regions.
-
#image ⇒ Object
Returns the value of attribute image.
-
#options ⇒ Object
Returns the value of attribute options.
-
#region_to_check ⇒ Object
Returns the value of attribute region_to_check.
Class Method Summary collapse
- .any(screenshot) ⇒ Object
- .blob(blob_image) ⇒ Object
- .image(image) ⇒ Object
- .path(path) ⇒ Object
- .screenshot(screenshot) ⇒ Object
Instance Method Summary collapse
- #accesibility(*args) ⇒ Object
- #convert_image_arg(image_arg) ⇒ Object
- #floating(*args) ⇒ Object
- #get_bounds(args) ⇒ Object
- #get_requested_padding(padding, args) ⇒ Object
- #ignore(*args) ⇒ Object
-
#initialize(image_arg) ⇒ Target
constructor
A new instance of Target.
- #region(region = nil) ⇒ Object
- #region_from_args(args) ⇒ Object
Constructor Details
#initialize(image_arg) ⇒ Target
Returns a new instance of Target.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/applitools/images/target.rb', line 58 def initialize(image_arg) image = convert_image_arg(image_arg) Applitools::ArgumentGuard.not_nil(image, 'image') Applitools::ArgumentGuard.is_a? image, 'image', String self.image = image self.ignored_regions = [] self.floating_regions = [] self.accessibility_regions = [] self. = { trim: false } end |
Instance Attribute Details
#accessibility_regions ⇒ Object
Returns the value of attribute accessibility_regions.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def accessibility_regions @accessibility_regions end |
#floating_regions ⇒ Object
Returns the value of attribute floating_regions.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def floating_regions @floating_regions end |
#ignored_regions ⇒ Object
Returns the value of attribute ignored_regions.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def ignored_regions @ignored_regions end |
#image ⇒ Object
Returns the value of attribute image.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def image @image end |
#options ⇒ Object
Returns the value of attribute options.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def @options end |
#region_to_check ⇒ Object
Returns the value of attribute region_to_check.
36 37 38 |
# File 'lib/applitools/images/target.rb', line 36 def region_to_check @region_to_check end |
Class Method Details
.any(screenshot) ⇒ Object
31 32 33 |
# File 'lib/applitools/images/target.rb', line 31 def any(screenshot) new(screenshot) end |
.blob(blob_image) ⇒ Object
13 14 15 16 17 |
# File 'lib/applitools/images/target.rb', line 13 def blob(blob_image) Applitools::ArgumentGuard.not_nil blob_image, 'blob_image' Applitools::ArgumentGuard.is_a? blob_image, 'blob_image', String new(blob_image) end |
.image(image) ⇒ Object
19 20 21 22 23 |
# File 'lib/applitools/images/target.rb', line 19 def image(image) Applitools::ArgumentGuard.not_nil image, 'image' # Applitools::ArgumentGuard.is_a? image, 'image', ChunkyPNG::Image new(image) end |
.path(path) ⇒ Object
7 8 9 10 11 |
# File 'lib/applitools/images/target.rb', line 7 def path(path) raise Applitools::EyesIllegalArgument unless File.exist?(path) # new Applitools::Screenshot.from_image(ChunkyPNG::Image.from_file(path)) new(path) end |
.screenshot(screenshot) ⇒ Object
25 26 27 28 29 |
# File 'lib/applitools/images/target.rb', line 25 def screenshot(screenshot) Applitools::ArgumentGuard.not_nil screenshot, 'screenshot' Applitools::ArgumentGuard.is_a? screenshot, 'screenshot', Applitools::Screenshot new screenshot end |
Instance Method Details
#accesibility(*args) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/applitools/images/target.rb', line 139 def accesibility(*args) accessibility_regions << case args.first when Applitools::AccessibilityRegion args.first when Applitools::Region Applitools::AccessibilityRegion.new(args.first, args.last) else accessibility_region_type = args.pop region = Applitools::Region.new(*args) Applitools::AccessibilityRegion.new(region, accessibility_region_type) end end |
#convert_image_arg(image_arg) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/applitools/images/target.rb', line 38 def convert_image_arg(image_arg) if image_arg.is_a?(Applitools::Screenshot) Base64.strict_encode64(image_arg.to_blob).force_encoding('UTF-8') elsif image_arg.class.name === 'ChunkyPNG::Image' Base64.strict_encode64(image_arg.to_blob).force_encoding('UTF-8') elsif image_arg.is_a?(Hash) && !image_arg[:image_path].nil? image_arg[:image_path] elsif image_arg.is_a?(Hash) && !image_arg[:image].nil? Base64.strict_encode64(image_arg[:image]).force_encoding('UTF-8') elsif image_arg.is_a?(Hash) raise Applitools::EyesIllegalArgument.new "Image is unrecognized, try to use image_path: path_or_url or image: buffer" elsif image_arg.is_a?(String) && File.exist?(image_arg) # Path image_arg elsif image_arg.is_a?(String) # URL ? Buffer raise Applitools::EyesIllegalArgument.new "Passed image is not explicit, try to use image_path: path_or_url or image: buffer" else raise Applitools::EyesIllegalArgument.new "Passed image is unrecognized" end end |
#floating(*args) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/applitools/images/target.rb', line 113 def floating(*args) = Applitools::Utils.(args) padding = && [:padding] requested_padding = get_requested_padding(padding, args) bounds = get_bounds(args) value = convert_to_universal(args) value = { type: args[0], selector: args[1] } if value.nil? value = value[:selector] if value.is_a?(Hash) && (value[:type].to_s === 'id') region = { region: value } region.merge!(bounds) if bounds != {} region.merge!(padding: requested_padding) if requested_padding != {} region.merge!(regionId: [:region_id]) if [:region_id] floating_regions << region self end |
#get_bounds(args) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/applitools/images/target.rb', line 77 def get_bounds(args) return args.pop.to_hash if args.last.is_a?(Applitools::FloatingBounds) last4 = args.last(4) if last4.size === 4 && last4.all? { |e| e.is_a?(Numeric) } FloatingBounds.new(*last4).to_hash else {} end end |
#get_requested_padding(padding, args) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/applitools/images/target.rb', line 101 def get_requested_padding(padding, args) return padding.to_hash if padding && padding.is_a?(Applitools::PaddingBounds) return padding if padding && (padding.is_a?(Hash) || padding.is_a?(Numeric)) if args.last.is_a? Applitools::PaddingBounds args.pop # elsif args.last.is_a?(Applitools::FloatingBounds) # args.pop.to_hash else {} end end |
#ignore(*args) ⇒ Object
71 72 73 74 75 |
# File 'lib/applitools/images/target.rb', line 71 def ignore(*args) region = region_from_args(args) ignored_regions << region if region self end |
#region(region = nil) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/applitools/images/target.rb', line 129 def region(region = nil) if region Applitools::ArgumentGuard.is_a? region, 'region', Applitools::Region self.region_to_check = region.to_hash else self.region_to_check = nil end self end |
#region_from_args(args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/applitools/images/target.rb', line 87 def region_from_args(args) = Applitools::Utils.(args) padding = && [:padding] requested_padding = get_requested_padding(padding, args) value = convert_to_universal(args) value = { type: args[0], selector: args[1] } if value.nil? value = value[:selector] if value.is_a?(Hash) && (value[:type].to_s === 'id') return nil if value === {selector: nil, type: nil} region = { region: value } region.merge!(padding: requested_padding) if requested_padding != {} region.merge!(regionId: [:region_id]) if [:region_id] region end |