Class: Applitools::Selenium::Driver
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Applitools::Selenium::Driver
- Extended by:
- Forwardable
- Includes:
- Selenium::WebDriver::DriverExtensions::HasInputDevices
- Defined in:
- lib/applitools/selenium/driver.rb
Constant Summary collapse
- RIGHT_ANGLE =
90- IOS =
'IOS'.freeze
- ANDROID =
'ANDROID'.freeze
- LANDSCAPE =
'LANDSCAPE'.freeze
- FINDERS =
{ class: 'class name', class_name: 'class name', css: 'css selector', id: 'id', link: 'link text', link_text: 'link text', name: 'name', partial_link_text: 'partial link text', tag_name: 'tag name', xpath: 'xpath' }.freeze
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#wait_before_screenshots ⇒ Object
Returns the value of attribute wait_before_screenshots.
Class Method Summary collapse
- .normalize_image(driver, image, rotation) ⇒ Object
-
.normalize_rotation(driver, image, rotation) ⇒ Object
Rotates the image as necessary.
- .normalize_width(driver, image) ⇒ Object
Instance Method Summary collapse
- #android? ⇒ Boolean
- #find_element(*args) ⇒ Object
- #find_elements(*args) ⇒ Object
-
#get_screenshot(rotation = nil) ⇒ Object
Return a normalized screenshot.
-
#hide_scrollbars ⇒ Object
Hide the main document’s scrollbars and returns the original overflow value.
-
#initialize(eyes, options) ⇒ Driver
constructor
If driver is not provided, Applitools::Selenium::Driver will raise an EyesError exception.
- #ios? ⇒ Boolean
- #keyboard ⇒ Object
-
#landscape_orientation? ⇒ Boolean
Returns:
trueif the driver orientation is landscape. -
#mobile_device? ⇒ Boolean
Returns:
trueif the platform running the test is a mobile platform. - #mouse ⇒ Object
-
#overflow=(overflow) ⇒ Object
(also: #set_overflow)
Set the overflow value for document element and return the original overflow value.
-
#platform_name ⇒ Object
Returns:
StringThe platform name ornilif it is undefined. -
#platform_version ⇒ Object
Returns:
StringThe platform version ornilif it is undefined. - #visible_screenshot ⇒ Object
Constructor Details
#initialize(eyes, options) ⇒ Driver
If driver is not provided, Applitools::Selenium::Driver will raise an EyesError exception.
36 37 38 39 40 41 42 43 44 |
# File 'lib/applitools/selenium/driver.rb', line 36 def initialize(eyes, ) super([:driver]) @is_mobile_device = .fetch(:is_mobile_device, false) @wait_before_screenshots = 0 @eyes = eyes @browser = Applitools::Selenium::Browser.new(self, @eyes) Applitools::EyesLogger.warn '"screenshot_as" method not found!' unless driver.respond_to? :screenshot_as end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
29 30 31 |
# File 'lib/applitools/selenium/driver.rb', line 29 def browser @browser end |
#wait_before_screenshots ⇒ Object
Returns the value of attribute wait_before_screenshots.
30 31 32 |
# File 'lib/applitools/selenium/driver.rb', line 30 def wait_before_screenshots @wait_before_screenshots end |
Class Method Details
.normalize_image(driver, image, rotation) ⇒ Object
164 165 166 167 |
# File 'lib/applitools/selenium/driver.rb', line 164 def normalize_image(driver, image, rotation) normalize_rotation(driver, image, rotation) normalize_width(driver, image) end |
.normalize_rotation(driver, image, rotation) ⇒ Object
Rotates the image as necessary. The rotation is either manually forced by passing a value in the rotation parameter, or automatically inferred if the rotation parameter is nil.
driver-
Applitools::Selenium::DriverThe driver which produced the screenshot. image-
ChunkyPNG::CanvasThe image to normalize. rotation-
Integer|nilThe degrees by which to rotate the image: positive values = clockwise rotation,
negative values = counter-clockwise, 0 = force no rotation, +nil+ = rotate automatically when needed.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/applitools/selenium/driver.rb', line 176 def normalize_rotation(driver, image, rotation) return if rotation == 0 num_quadrants = 0 if !rotation.nil? if rotation % RIGHT_ANGLE != 0 raise Applitools::EyesError.new('Currently only quadrant rotations are supported. Current rotation: '\ "#{rotation}") end num_quadrants = (rotation / RIGHT_ANGLE).to_i elsif rotation.nil? && driver.mobile_device? && driver.landscape_orientation? && image.height > image.width # For Android, we need to rotate images to the right, and for iOS to the left. num_quadrants = driver.android? ? 1 : -1 end Applitools::Utils::ImageUtils.quadrant_rotate!(image, num_quadrants) end |
.normalize_width(driver, image) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/applitools/selenium/driver.rb', line 194 def normalize_width(driver, image) return if driver.mobile_device? normalization_factor = driver.browser.image_normalization_factor(image) Applitools::Utils::ImageUtils.scale!(image, normalization_factor) unless normalization_factor == 1 end |
Instance Method Details
#android? ⇒ Boolean
131 132 133 |
# File 'lib/applitools/selenium/driver.rb', line 131 def android? platform_name.to_s.upcase == ANDROID end |
#find_element(*args) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/applitools/selenium/driver.rb', line 114 def find_element(*args) how, what = extract_args(args) # Make sure that "how" is a valid locator. raise ArgumentError, "cannot find element by: #{how.inspect}" unless FINDERS[how.to_sym] Applitools::Selenium::Element.new(self, driver.find_element(how, what)) end |
#find_elements(*args) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/applitools/selenium/driver.rb', line 123 def find_elements(*args) how, what = extract_args(args) raise ArgumentError, "cannot find element by: #{how.inspect}" unless FINDERS[how.to_sym] driver.find_elements(how, what).map { |el| Applitools::Selenium::Element.new(self, el) } end |
#get_screenshot(rotation = nil) ⇒ Object
Return a normalized screenshot.
rotation-
Integer|nilThe degrees by which to rotate the image: positive values = clockwise rotation,
negative values = counter-clockwise, 0 = force no rotation, +nil+ = rotate automatically when needed.
Returns: ChunkPng::Image A screenshot object, normalized by scale and rotation.
93 94 95 96 97 |
# File 'lib/applitools/selenium/driver.rb', line 93 def get_screenshot(rotation = nil) image = mobile_device? || !@eyes.force_fullpage_screenshot ? visible_screenshot : @browser.fullpage_screenshot Applitools::Selenium::Driver.normalize_image(self, image, rotation) image end |
#hide_scrollbars ⇒ Object
Hide the main document’s scrollbars and returns the original overflow value.
76 77 78 |
# File 'lib/applitools/selenium/driver.rb', line 76 def @browser. end |
#ios? ⇒ Boolean
135 136 137 |
# File 'lib/applitools/selenium/driver.rb', line 135 def ios? platform_name.to_s.upcase == IOS end |
#keyboard ⇒ Object
110 111 112 |
# File 'lib/applitools/selenium/driver.rb', line 110 def keyboard Applitools::Selenium::Keyboard.new(self, driver.keyboard) end |
#landscape_orientation? ⇒ Boolean
Returns: true if the driver orientation is landscape.
61 62 63 64 65 |
# File 'lib/applitools/selenium/driver.rb', line 61 def landscape_orientation? driver.orientation.to_s.upcase == LANDSCAPE rescue NameError Applitools::EyesLogger.debug 'driver has no "orientation" attribute. Assuming: portrait.' end |
#mobile_device? ⇒ Boolean
Returns: true if the platform running the test is a mobile platform. false otherwise.
69 70 71 72 73 |
# File 'lib/applitools/selenium/driver.rb', line 69 def mobile_device? # We CAN'T check if the device is an +Appium::Driver+ since it is not a RemoteWebDriver. Because of that we use a # flag we got as an option in the constructor. @is_mobile_device end |
#mouse ⇒ Object
106 107 108 |
# File 'lib/applitools/selenium/driver.rb', line 106 def mouse Applitools::Selenium::Mouse.new(self, driver.mouse) end |
#overflow=(overflow) ⇒ Object Also known as: set_overflow
Set the overflow value for document element and return the original overflow value.
81 82 83 |
# File 'lib/applitools/selenium/driver.rb', line 81 def overflow=(overflow) @browser.set_overflow(overflow) end |
#platform_name ⇒ Object
Returns: String The platform name or nil if it is undefined.
48 49 50 |
# File 'lib/applitools/selenium/driver.rb', line 48 def platform_name capabilities['platformName'] end |
#platform_version ⇒ Object
Returns: String The platform version or nil if it is undefined.
54 55 56 57 |
# File 'lib/applitools/selenium/driver.rb', line 54 def platform_version version = capabilities['platformVersion'] version.nil? ? nil : version.to_s end |
#visible_screenshot ⇒ Object
99 100 101 102 103 104 |
# File 'lib/applitools/selenium/driver.rb', line 99 def visible_screenshot Applitools::EyesLogger.debug "Waiting before screenshot: #{wait_before_screenshots} seconds..." sleep(wait_before_screenshots) Applitools::EyesLogger.debug 'Finished waiting.' Applitools::Utils::ImageUtils::Screenshot.new driver.screenshot_as(:png) end |