Module: Applitools::Calabash::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/applitools/calabash/utils.rb

Instance Method Summary collapse

Instance Method Details

#clear_directories(eyes_settings) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/applitools/calabash/utils.rb', line 17

def clear_directories(eyes_settings)
  tmp_dir = File.join Dir.getwd, eyes_settings.tmp_dir
  log_dir = File.join Dir.getwd, eyes_settings.log_dir

  FileUtils.remove_dir(tmp_dir) if File.exist?(tmp_dir)
  FileUtils.remove_dir(log_dir) if File.exist?(log_dir)
end

#create_directories(eyes_settings) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/applitools/calabash/utils.rb', line 8

def create_directories(eyes_settings)
  FileUtils.mkpath(
    File.join(Dir.getwd, eyes_settings.tmp_dir, eyes_settings.screenshot_dir)
  )
  FileUtils.mkpath(
    File.join(Dir.getwd, eyes_settings.log_dir)
  )
end

#get_android_element(context, query, index) ⇒ Object


55
56
57
58
59
60
61
62
63
# File 'lib/applitools/calabash/utils.rb', line 55

def get_android_element(context, query, index)
  element_query = if (id = context.query(query, :getId)[index.to_i]) && id > 0
                    "* id:#{id}"
                  else
                    query + " index:#{index.to_i}"
                  end
  element = context.query(element_query).first
  Applitools::Calabash::CalabashElement.new(element, element_query)
end

#get_ios_element(context, query, index) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/applitools/calabash/utils.rb', line 65

def get_ios_element(context, query, index)
  hash = context.query(query, :hash)[index.to_i]
  return unless hash
  element_query = "* hash:#{hash}"
  element = context.query(element_query).first
  Applitools::Calabash::CalabashElement.new(element, element_query)
end

#grub_android_class_name(context, element) ⇒ Object


47
48
49
# File 'lib/applitools/calabash/utils.rb', line 47

def grub_android_class_name(context, element)
  request_element(context, element, :class)
end

#grub_ios_class_name(context, element) ⇒ Object


51
52
53
# File 'lib/applitools/calabash/utils.rb', line 51

def grub_ios_class_name(context, element)
  request_element(context, element, :className)
end

#region_from_element(element) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'lib/applitools/calabash/utils.rb', line 31

def region_from_element(element)
  region = Applitools::Region.new(
    element['rect']['x'],
    element['rect']['y'],
    element['rect']['width'],
    element['rect']['height']
  )
  return region if Applitools::Calabash::EnvironmentDetector.android?
  region.scale_it!(Applitools::Calabash::EyesSettings.instance.eyes.density)
end

#request_element(context, element, method) ⇒ Object


42
43
44
45
# File 'lib/applitools/calabash/utils.rb', line 42

def request_element(context, element, method)
  Applitools::ArgumentGuard.is_a?(element, 'element', Applitools::Calabash::CalabashElement)
  context.query(element.element_query, method)
end

#using_screenshot(context) {|context.screenshot(screenshot_options)| ... } ⇒ Object

Yields:

  • (context.screenshot(screenshot_options))

25
26
27
28
29
# File 'lib/applitools/calabash/utils.rb', line 25

def using_screenshot(context)
  return unless block_given?
  screenshot_options = Applitools::Calabash::EyesSettings.instance.screenshot_names.next
  yield context.screenshot(screenshot_options)
end