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
Class Method Summary collapse
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
- #configure {|config| ... } ⇒ 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
22 23 24 25 26 |
# File 'lib/applitools/images/eyes.rb', line 22 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 |
Class Method Details
.environment_sdk ⇒ Object
33 34 35 36 37 38 |
# File 'lib/applitools/images/eyes.rb', line 33 def self.environment_sdk { name: :eyes_images, currentVersion: Applitools::EyesImages::VERSION } end |
Instance Method Details
#add_mouse_trigger(action, control, cursor) ⇒ Object
Adds a mouse trigger
163 164 165 |
# File 'lib/applitools/images/eyes.rb', line 163 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
170 171 172 |
# File 'lib/applitools/images/eyes.rb', line 170 def add_text_trigger(control, text) add_text_trigger_base control, text end |
#check(*args) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/applitools/images/eyes.rb', line 72 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 result = check_it(name, target, Applitools::MatchWindowData.new(default_match_settings)) result.nil? ? result : result.as_expected? # from v4 nil 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.
125 126 127 128 129 130 |
# File 'lib/applitools/images/eyes.rb', line 125 def check_image() = { tag: '', ignore_mismatch: false }.merge # image = get_image_from_options(options) target = Applitools::Images::Target.any().ignore_mismatch([:ignore_mismatch]) check([:tag], target) end |
#check_it(name, target, match_window_data) ⇒ Object
103 104 105 106 |
# File 'lib/applitools/images/eyes.rb', line 103 def check_it(name, target, match_window_data) Applitools::ArgumentGuard.not_nil(name, 'name') universal_check(name, target) end |
#check_region(options) ⇒ Object
Performs visual validation for the current image.
147 148 149 150 151 152 153 154 155 |
# File 'lib/applitools/images/eyes.rb', line 147 def check_region() = { tag: '', ignore_mismatch: false }.merge Applitools::ArgumentGuard.not_nil [:region], 'options[:region] can\'t be nil!' # image = get_image_from_options options target = Applitools::Images::Target.any().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
89 90 91 92 93 |
# File 'lib/applitools/images/eyes.rb', line 89 def check_single(name, target, = {}) open_and_close(name, target, ) do |n, t| check_it(n, t, Applitools::MatchSingleCheckData.new) end end |
#configure {|config| ... } ⇒ Object
28 29 30 31 |
# File 'lib/applitools/images/eyes.rb', line 28 def configure return unless block_given? yield(config) end |
#open(options = {}) ⇒ Object
Starts a test.
49 50 51 52 53 54 |
# File 'lib/applitools/images/eyes.rb', line 49 def open( = {}) Applitools::ArgumentGuard.hash , 'open(options)', [:app_name, :test_name] [:viewport_size] = Applitools::RectangleSize.from_any_argument [:viewport_size] # options = Applitools::Utils.extract_options!(args) universal_open() end |
#open_and_close(*args) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/applitools/images/eyes.rb', line 95 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.
64 65 66 67 68 69 70 |
# File 'lib/applitools/images/eyes.rb', line 64 def test( = {}, &_block) open() yield close ensure abort_if_not_closed end |