Module: Applitools::UniversalNewApi

Included in:
EyesBase
Defined in:
lib/applitools/core/universal_new_api.rb

Instance Method Summary collapse

Instance Method Details

#extract_text(*args) ⇒ Object

export type OCRExtractSettings<TElement, TSelector> =

target: RegionReference<TElement, TSelector>
hint?: string
minMatch?: number
language?: string



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/applitools/core/universal_new_api.rb', line 12

def extract_text(*args)
  image_target = args[0].is_a?(Hash) ? args[0] : nil
  targets_array = args[0].is_a?(Hash) ? args[1].to_a : args[0]
  targets_array.map do |target|
    target['target'] = { elementId: target['target'].ref } if target['target'].is_a?(::Selenium::WebDriver::Element)
    target['target']['x'] = target['target'].delete('left') if target['target']['left']
    target['target']['y'] = target['target'].delete('top') if target['target']['top']
    target[:region] = target.delete('target')
    target
  end
  driver_target = respond_to?(:driver) ? driver.universal_driver_config : image_target
  universal_eyes.extract_text(targets_array, driver_target)
end

#extract_text_regions(patterns_array) ⇒ Object

export type OCRSearchSettings<TPattern extends string> =

patterns: TPattern[]
ignoreCase?: boolean
firstOnly?: boolean
language?: string



33
34
35
36
37
# File 'lib/applitools/core/universal_new_api.rb', line 33

def extract_text_regions(patterns_array)
  driver_target = respond_to?(:driver) ? driver.universal_driver_config : { image: patterns_array.delete('image') }
  results = universal_eyes.extract_text_regions(patterns_array, driver_target)
  Applitools::Utils.deep_stringify_keys(results)
end

#locate(locate_settings) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/applitools/core/universal_new_api.rb', line 40

def locate(locate_settings)
  settings = {
    locatorNames: locate_settings[:locator_names],
    firstOnly: !!locate_settings[:first_only]
  }
  driver_target = locate_settings.has_key?(:image) ? {image: locate_settings[:image]} : driver.universal_driver_config
  results = universal_eyes.locate(settings, driver_target)

  old_style = results.map do |k, v|
    val = v.map {|r| {left: r[:x], top: r[:y], width: r[:width], height: r[:height]} }
    [k, val]
  end.to_h

  Applitools::Utils.deep_stringify_keys(old_style)
end