Class: Applitools::Images::Eyes
- Inherits:
-
EyesBase
- Object
- EyesBase
- Applitools::Images::Eyes
- Defined in:
- lib/applitools/images/eyes.rb
Overview
A class to perform visual validation on images. Allows to handle user data like Mouse trigger and Text trigger
Instance Method Summary collapse
-
#add_mouse_trigger(action, control, cursor) ⇒ Object
Adds a mouse trigger.
-
#add_text_trigger(control, text) ⇒ Object
Adds a keyboard trigger.
- #check(*args) ⇒ Object
-
#check_image(options) ⇒ Object
Matches the input image with the next expected image.
- #check_it(name, target, match_window_data) ⇒ Object
-
#check_region(options) ⇒ Object
Performs visual validation for the current image.
- #check_single(name, target, options = {}) ⇒ Object
- #get_app_output_with_screenshot(*_args) ⇒ Object
- #get_region_provider(target) ⇒ Object
-
#initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) ⇒ Eyes
constructor
Creates a new eyes object.
-
#open(options = {}) ⇒ Object
Starts a test.
- #open_and_close(*args) ⇒ Object
-
#test(options = {}, &_block) ⇒ Object
Opens eyes using passed options, yields the block and then closes eyes session.
Constructor Details
#initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) ⇒ Eyes
Creates a new eyes object
27 28 29 30 31 |
# File 'lib/applitools/images/eyes.rb', line 27 def initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) super self.base_agent_id = "eyes.images.ruby/#{Applitools::VERSION}".freeze self.runner = Applitools::ClassicRunner.new end |
Instance Method Details
#add_mouse_trigger(action, control, cursor) ⇒ Object
Adds a mouse trigger
203 204 205 |
# File 'lib/applitools/images/eyes.rb', line 203 def add_mouse_trigger(action, control, cursor) add_mouse_trigger_base action, control, cursor end |
#add_text_trigger(control, text) ⇒ Object
Adds a keyboard trigger
210 211 212 |
# File 'lib/applitools/images/eyes.rb', line 210 def add_text_trigger(control, text) add_text_trigger_base control, text end |
#check(*args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/applitools/images/eyes.rb', line 64 def check(*args) args.compact! case (first_arg = args.shift) when String name = first_arg target = args.shift when Applitools::Selenium::Target target = first_arg when Hash target = first_arg[:target] name = first_arg[:name] || first_arg[:tag] end check_it(name, target, Applitools::MatchWindowData.new(default_match_settings)).as_expected? end |
#check_image(options) ⇒ Object
Matches the input image with the next expected image. Takes a hash as an argument. Returns boolean
as result of matching.
165 166 167 168 169 170 |
# File 'lib/applitools/images/eyes.rb', line 165 def check_image() = { tag: '', ignore_mismatch: false }.merge image = () target = Applitools::Images::Target.any(image).ignore_mismatch([:ignore_mismatch]) check([:tag], target) end |
#check_it(name, target, match_window_data) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/applitools/images/eyes.rb', line 94 def check_it(name, target, match_window_data) Applitools::ArgumentGuard.not_nil(name, 'name') region_provider = get_region_provider(target) match_window_data.tag = name match_window_data.read_target(target, nil) image = target.image self. = Applitools::RectangleSize.new image.width, image.height if .nil? self.screenshot = EyesImagesScreenshot.new image if match_window_data.is_a? Applitools::MatchSingleCheckData return check_single_base( region_provider, target.[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end check_window_base( region_provider, target.[:timeout] || Applitools::EyesBase::USE_DEFAULT_TIMEOUT, match_window_data ) end |
#check_region(options) ⇒ Object
Performs visual validation for the current image.
187 188 189 190 191 192 193 194 195 |
# File 'lib/applitools/images/eyes.rb', line 187 def check_region() = { tag: nil, ignore_mismatch: false }.merge Applitools::ArgumentGuard.not_nil [:region], 'options[:region] can\'t be nil!' image = target = Applitools::Images::Target.any(image).ignore_mismatch([:ignore_mismatch]) target.region([:region]) logger.info "check_region(image, #{[:region]}, #{[:tag]}, #{[:ignore_mismatch]})" check([:tag], target) end |
#check_single(name, target, options = {}) ⇒ Object
80 81 82 83 84 |
# File 'lib/applitools/images/eyes.rb', line 80 def check_single(name, target, = {}) open_and_close(name, target, ) do |n, t| check_it(n, t, Applitools::MatchSingleCheckData.new) end end |
#get_app_output_with_screenshot(*_args) ⇒ Object
214 215 216 217 218 |
# File 'lib/applitools/images/eyes.rb', line 214 def get_app_output_with_screenshot(*_args) result = super self.screenshot_url = nil result end |
#get_region_provider(target) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/applitools/images/eyes.rb', line 120 def get_region_provider(target) if (region_to_check = target.region_to_check).nil? Object.new.tap do |prov| prov.instance_eval do define_singleton_method :region do Applitools::Region::EMPTY end define_singleton_method :coordinate_type do nil end end end else Object.new.tap do |prov| prov.instance_eval do define_singleton_method :region do region_to_check end define_singleton_method :coordinate_type do Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative] end end end end end |
#open(options = {}) ⇒ Object
Starts a test.
42 43 44 45 46 |
# File 'lib/applitools/images/eyes.rb', line 42 def open( = {}) Applitools::ArgumentGuard.hash , 'open(options)', [:app_name, :test_name] [:viewport_size] = Applitools::RectangleSize.from_any_argument [:viewport_size] open_base end |
#open_and_close(*args) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/applitools/images/eyes.rb', line 86 def open_and_close(*args) = Applitools::Utils.(args) open() result = yield(*args) close(true, true) result end |
#test(options = {}, &_block) ⇒ Object
Opens eyes using passed options, yields the block and then closes eyes session. Use Applitools::Images::Eyes method inside the block to perform the test. If the block throws an exception, eyes session will be closed correctly.
56 57 58 59 60 61 62 |
# File 'lib/applitools/images/eyes.rb', line 56 def test( = {}, &_block) open() yield close ensure abort_if_not_closed end |