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_image(options) ⇒ Object
Matches the input image with the next expected image.
-
#check_region(options) ⇒ Object
Performs visual validation for the current image.
-
#initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) ⇒ Eyes
constructor
Creates a new eyes object.
-
#open(options = {}) ⇒ Object
Starts a test.
-
#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
25 26 27 28 |
# File 'lib/applitools/images/eyes.rb', line 25 def initialize(server_url = Applitools::Connectivity::ServerConnector::DEFAULT_SERVER_URL) super self.base_agent_id = "eyes.images.ruby/#{Applitools::VERSION}".freeze 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_image(options) ⇒ Object
Matches the input image with the next expected image. Takes a hash as an argument. Returns boolean
as result of matching.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/applitools/images/eyes.rb', line 78 def check_image() = { tag: nil, ignore_mismatch: false }.merge if disabled? logger.info "check_image(image, #{[:tag]}, #{[:ignore_mismatch]}): Ignored" return false end image = logger.info "check_image(image, #{[:tag]}, #{[:ignore_mismatch]})" if image.is_a? Applitools::Screenshot self. = Applitools::RectangleSize.new image.width, image.height if .nil? self.screenshot = EyesImagesScreenshot.new image end self.title = [:tag] || '' region_provider = Object.new region_provider.instance_eval do define_singleton_method :region do Applitools::Region::EMPTY end define_singleton_method :coordinate_type do nil end end mr = check_window_base region_provider, [:tag], [:ignore_mismatch], Applitools::EyesBase::USE_DEFAULT_TIMEOUT mr.as_expected? end |
#check_region(options) ⇒ Object
Performs visual validation for the current image.
124 125 126 127 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 |
# File 'lib/applitools/images/eyes.rb', line 124 def check_region() = { tag: nil, ignore_mismatch: false }.merge if disabled? logger.info "check_region(image, #{[:tag]}, #{[:ignore_mismatch]}): Ignored" return false end Applitools::ArgumentGuard.not_nil [:region], 'options[:region] can\'t be nil!' image = logger.info "check_region(image, #{[:region]}, #{[:tag]}, #{[:ignore_mismatch]})" if image.is_a? Applitools::Screenshot self. = Applitools::RectangleSize.new image.width, image.height if .nil? self.screenshot = EyesImagesScreenshot.new image end self.title = [:tag] || '' region_provider = Object.new region_provider.instance_eval do define_singleton_method :region do [:region] end define_singleton_method :coordinate_type do Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is] end end mr = check_window_base region_provider, [:tag], [:ignore_mismatch], Applitools::EyesBase::USE_DEFAULT_TIMEOUT mr.as_expected? end |
#open(options = {}) ⇒ Object
Starts a test.
39 40 41 42 43 |
# File 'lib/applitools/images/eyes.rb', line 39 def open( = {}) Applitools::ArgumentGuard.hash , 'open(options)', [:app_name, :test_name] [:viewport_size] = Applitools::RectangleSize.from_any_argument [:viewport_size] open_base 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.
53 54 55 56 57 58 59 |
# File 'lib/applitools/images/eyes.rb', line 53 def test( = {}, &_block) open() yield close ensure abort_if_not_closed end |