class Object

Public Instance Methods

assert_eql(element1, element2) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 154
def assert_eql(element1, element2)
  expect(element1).to eq(element2)
end
assert_eql_with_rescue(element1, element2) click to toggle source

————————————————-Asserts————————————————————

# File lib/SurfCustomCalabash/CommonMethods.rb, line 145
def assert_eql_with_rescue(element1, element2)
  begin
    expect(element1).to eq(element2)
    true
  rescue RSpec::Expectations::ExpectationNotMetError
    false
  end
end
assert_false(element) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 166
def assert_false(element)
  expect(element).to be false
end
assert_nil(element) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 170
def assert_nil(element)
  expect(element).to be_nil
end
assert_not_eql(element1, element2) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 158
def assert_not_eql(element1, element2)
  expect(element1).not_to eql(element2)
end
assert_true(element) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 162
def assert_true(element)
  expect(element).to be true
end
back_swipe() click to toggle source
# File lib/SurfCustomCalabash/IosMethods.rb, line 132
def back_swipe
  pan_coordinates({x:0, y:300}, {x:500, y:300})
end
check_cyrillic(str) click to toggle source

check cyrillic symbols in string

# File lib/SurfCustomCalabash/CommonMethods.rb, line 310
def check_cyrillic(str)
  regexp = /\p{Cyrillic}+.*?\.?/
  if str.match(regexp).nil?
    return false
  else
    return true
  end
end
check_no_text(text, sleep_duration: 0, timeout_duration: 5) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 235
def check_no_text(text, sleep_duration: 0, timeout_duration: 5)
  wait_no_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
end
check_text(text, sleep_duration: 0, timeout_duration: 5) click to toggle source

wait text

# File lib/SurfCustomCalabash/CommonMethods.rb, line 226
def check_text(text, sleep_duration: 0, timeout_duration: 5)
  wait_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
end
close_keyboard(x_start: 0, y_start:0) click to toggle source

close keyboard, parameters use ios only

# File lib/SurfCustomCalabash/DroidMethods.rb, line 5
def close_keyboard(x_start: 0, y_start:0)
  if keyboard_visible?
    hide_soft_keyboard
  end
end
cross_coordinate(element_front, element_behind, delta: 100) click to toggle source

if elements cross - return true, if not - false

# File lib/SurfCustomCalabash/CommonMethods.rb, line 263
def cross_coordinate(element_front, element_behind, delta: 100)
  cross = false

  if element_exists(element_front) && element_exists(element_behind)
    coordinate_front = get_coordinate_y(element_front)
    coordinate_behind = get_coordinate_y(element_behind)

    if coordinate_front < coordinate_behind + delta
      cross = true
    else
      cross = false
    end
  end
  # Kernel.puts(cross)
  return cross
end
drag_element(element_from , element_to) click to toggle source

Drag element from one place to place of other element

# File lib/SurfCustomCalabash/CommonMethods.rb, line 253
def drag_element(element_from , element_to)
  x_from = get_coordinate_x(element_from)
  y_from = get_coordinate_y(element_from)

  x_to = get_coordinate_x(element_to)
  y_to = get_coordinate_y(element_to)
  drag_coordinates(x_from, y_from, x_to, y_to, 10, 0.5, 0.5)
end
enter_text_from_keyboard(text, timeout_duration: 5) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 3
def enter_text_from_keyboard(text, timeout_duration: 5)
  wait_for_keyboard(timeout: timeout_duration)
  keyboard_enter_text(text)
end
extract_last_num_from_str(text) click to toggle source

get last digital from string

# File lib/SurfCustomCalabash/CommonMethods.rb, line 201
def extract_last_num_from_str(text)
  text.gsub!(/[[:space:]]/, '')
  num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).last
  p num
end
extract_num_from_str(text) click to toggle source

get first digital from string

# File lib/SurfCustomCalabash/CommonMethods.rb, line 194
def extract_num_from_str(text)
  text.gsub!(/[[:space:]]/, '')
  num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).first
  p num
end
get_app_location(element, sleep_duration: 1) click to toggle source

————————————————–Localization—————————————————— get locale apps - Ru or Eng parameter - element with text

# File lib/SurfCustomCalabash/CommonMethods.rb, line 292
def get_app_location(element, sleep_duration: 1)
  sleep(sleep_duration)
  if element_exists(element)
    text_element = remember(element)
    if check_cyrillic(text_element)
      locale = 'RUS'
    else
      locale = 'ENG'
    end
  else
    p "Fail localization"
    locale = ''
  end
  p locale
  return locale
end
get_coordinate_x(element) click to toggle source

get element's coordinates

# File lib/SurfCustomCalabash/CommonMethods.rb, line 240
def get_coordinate_x(element)
  el = query(element)
  coordinate = el[0]['rect']['center_x']
  return coordinate.to_i
end
get_coordinate_y(element) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 246
def get_coordinate_y(element)
  el = query(element)
  coordinate = el[0]['rect']['center_y']
  return coordinate.to_i
end
get_random_email() click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 189
def get_random_email
  return get_random_text_string(7) + "@" + get_random_text_string(2) + ".test"
end
get_random_num_string(length) click to toggle source

——————————————Generate String———————————————————–

# File lib/SurfCustomCalabash/CommonMethods.rb, line 175
def get_random_num_string(length)
  source = (0..9).to_a
  key = ""
  length.times{ key += source[rand(source.size)].to_s }
  return key
end
get_random_text_string(length) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 182
def get_random_text_string(length)
  source = ("a".."z").to_a
  key = ""
  length.times{ key += source[rand(source.size)].to_s }
  return key
end
label_with_locale(mark1, mark2) click to toggle source

if apps support two localization, this method check exists label in different locations

# File lib/SurfCustomCalabash/CommonMethods.rb, line 356
def label_with_locale(mark1, mark2)
  if element_exists("* marked:'#{mark1}'")
    return "* marked:'#{mark1}'"
  elsif element_exists("* marked:'#{mark2}'")
    return "* marked:'#{mark2}'"
  else
    return false
  end
end
light_swipe(dr, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 46
def light_swipe(dr, sleep_duration: 0)
  if dr == "up"
    perform_action('drag', 50, 50, 15, 30, 25)
  elsif dr == "down"
    perform_action('drag', 50, 50, 30, 15, 25)
  elsif dr == "left"
    perform_action('drag', 25, 0, 50, 50, 10)
  elsif dr == "right"
    perform_action('drag', 0, 25, 50, 50, 10)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
light_swipe_element(element, dir, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 91
def light_swipe_element(element, dir, sleep_duration: 0)
  if dir == 'left'
    pan(element, :left)
  elsif  dir == 'right'
    pan(element, :right)
  elsif dir == 'down'
    pan(element, :up)
  elsif dir == 'up'
    pan(element, :down)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
light_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 108
def light_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      light_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
light_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 132
def light_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      light_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
light_swipe_trait_until_exists(dir, element_destination, sleep_duration: 0, timeout_duration: 30) click to toggle source

swipe trait-element from element_destination

# File lib/SurfCustomCalabash/DroidMethods.rb, line 107
def light_swipe_trait_until_exists(dir, element_destination, sleep_duration: 0, timeout_duration: 30)
  light_swipe_element_until_exists(dir, trait, element_destination, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
end
light_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 84
def light_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      light_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
light_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 60
def light_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      light_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
no_check_text(text, timeout_duration: 5) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 230
def no_check_text(text, timeout_duration: 5)
  warn "Deprecated with 0.1.9 version SurfCustomCalabash, use check_no_text intead"
  check_no_text(text, timeout_duration: timeout_duration)
end
normal_swipe(dr, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 31
def normal_swipe(dr, sleep_duration: 0)
  if dr == "up"
    perform_action('drag', 50, 50, 15, 45, 25)
  elsif dr == "down"
    perform_action('drag', 50, 50, 45, 15, 25)
  elsif dr == "left"
    perform_action('drag', 50, 0, 50, 50, 10)
  elsif dr == "right"
    perform_action('drag', 0, 50, 50, 50, 10)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
normal_swipe_element(element, dir, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 76
def normal_swipe_element(element, dir, sleep_duration: 0)
  if dir == 'left'
    pan(element, :left)
  elsif  dir == 'right'
    pan(element, :right)
  elsif dir == 'down'
    pan(element, :up)
  elsif dir == 'up'
    pan(element, :down)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
normal_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 100
def normal_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      normal_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
normal_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 124
def normal_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      normal_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
normal_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 76
def normal_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      normal_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
normal_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 52
def normal_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      normal_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
ptr() click to toggle source

pull-to-refresh screen

# File lib/SurfCustomCalabash/DroidMethods.rb, line 112
def ptr
  perform_action('drag', 50, 50, 15, 75, 4)
end
remember(element, sleep_duration: 1, timeout_duration: 5) click to toggle source

get text from first element

# File lib/SurfCustomCalabash/CommonMethods.rb, line 208
def remember(element, sleep_duration: 1, timeout_duration: 5)
  wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
  name = query(element)
  save_name = name.first['text']
  Kernel.puts(save_name)
  return save_name
end
remember_last_text(element, sleep_duration: 1, timeout_duration: 5) click to toggle source

get text from last element

# File lib/SurfCustomCalabash/CommonMethods.rb, line 217
def remember_last_text(element, sleep_duration: 1, timeout_duration: 5)
  wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
  name = query(element)
  save_name = name.last['text']
  Kernel.puts(save_name)
  return save_name
end
strong_swipe(dr, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 16
def strong_swipe(dr, sleep_duration: 0)
  if dr == "up"
    perform_action('drag', 50, 50, 15, 75, 25)
  elsif dr == "down"
    perform_action('drag', 50, 50, 75, 15, 25)
  elsif dr == "left"
    perform_action('drag', 90, 0, 50, 50, 10)
  elsif dr == "right"
    perform_action('drag', 0, 90, 50, 50, 10)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
strong_swipe_element(element, dir, sleep_duration: 0) click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 61
def strong_swipe_element(element, dir, sleep_duration: 0)
  if dir == 'left'
    flick(element, :left)
  elsif  dir == 'right'
    flick(element, :right)
  elsif dir == 'down'
    flick(element, :up)
  elsif dir == 'up'
    flick(element, :down)
  else
    p "Use direction 'up', 'down', 'left', 'right'"
  end
  sleep(sleep_duration)
end
strong_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 92
def strong_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      strong_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
strong_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 116
def strong_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      strong_swipe_element(element, dir, sleep_duration: sleep_duration)
    end
  end
end
strong_swipe_until_exists(dir, element_destination, sleep_duration: 0.5, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 68
def strong_swipe_until_exists(dir, element_destination, sleep_duration: 0.5, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_does_not_exist(element_destination) do
      strong_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
strong_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30) click to toggle source

—————————————————-Custom Swipe—————————————————-

# File lib/SurfCustomCalabash/CommonMethods.rb, line 44
def strong_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
  Timeout::timeout(timeout_duration) do
    while element_exists(element_destination) do
      strong_swipe(dir, sleep_duration: sleep_duration)
    end
  end
end
submit_keyboard() click to toggle source
# File lib/SurfCustomCalabash/DroidMethods.rb, line 11
def submit_keyboard
  press_user_action_button
end
swipe_if_cross(element_front, element_behind, timeout_duration: 30, sleep_duration: 1) click to toggle source

swipe down if two element cross

# File lib/SurfCustomCalabash/CommonMethods.rb, line 281
def swipe_if_cross(element_front, element_behind, timeout_duration: 30, sleep_duration: 1)
  Timeout::timeout(timeout_duration) do
    while cross_coordinate(element_front, element_behind) do
      light_swipe("down", sleep_duration: sleep_duration)
    end
  end
end
swipe_to_down() click to toggle source

strong swipe to down of the screen

# File lib/SurfCustomCalabash/DroidMethods.rb, line 122
def swipe_to_down
  5.times {perform_action('drag', 50, 50, 60, 10, 1)}
end
swipe_to_text(dir, text, sleep_duration:0.2, timeout_duration: 30) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 140
def swipe_to_text(dir, text, sleep_duration:0.2, timeout_duration: 30)
  light_swipe_until_exists(dir, "* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
end
swipe_to_up() click to toggle source

strong swipe to up of the screen

# File lib/SurfCustomCalabash/DroidMethods.rb, line 117
def swipe_to_up
  5.times {perform_action('drag', 50, 50, 15, 70, 1)}
end
tap_on(element, timeout_duration: 15, sleep_duration: 0.5) click to toggle source

———————————————-Custom Taps———————————————————– wait element and tap

# File lib/SurfCustomCalabash/CommonMethods.rb, line 10
def tap_on(element, timeout_duration: 15, sleep_duration: 0.5)
  wait_element(element, timeout_duration: timeout_duration, sleep_duration: sleep_duration)
  touch(element)
end
tap_on_text(text, timeout_duration: 15, sleep_duration: 0.5) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 15
def tap_on_text(text, timeout_duration: 15, sleep_duration: 0.5)
  tap_on("* {text CONTAINS'#{text}'}", timeout_duration: timeout_duration, sleep_duration: sleep_duration)
end
tap_or_swipe(element, timeout_duration: 30, sleep_duration: 0.5) click to toggle source

if element exists - tap, if not - swipe until element exists and tap

# File lib/SurfCustomCalabash/CommonMethods.rb, line 20
def tap_or_swipe(element, timeout_duration: 30, sleep_duration: 0.5)
  if element_does_not_exist(element)
    light_swipe_until_exists('down', element, timeout_duration: timeout_duration)
  end
  tap_on(element, sleep_duration: sleep_duration)
end
text_with_locale(text_locale1, text_locale2, sleep_duration: 1) click to toggle source

if apps support two localization, this method check exists text in different locations

# File lib/SurfCustomCalabash/CommonMethods.rb, line 320
def text_with_locale(text_locale1, text_locale2, sleep_duration: 1)
  sleep(sleep_duration)

  # $locale is global variables
  # $locale setup in first app launch
  if !$locale.nil?
    if check_cyrillic(text_locale1)
      rus_locale = "* {text CONTAINS '#{text_locale1}'}"
      eng_locale = "* {text CONTAINS '#{text_locale2}'}"
    elsif check_cyrillic(text_locale2)
      rus_locale = "* {text CONTAINS '#{text_locale2}'}"
      eng_locale = "* {text CONTAINS '#{text_locale1}'}"
    end

    if $locale == "RUS"
      return rus_locale
    elsif $locale == "ENG"
      return eng_locale
    end
  else
    # if $locale is not Rus or Eng
    # wait element on screen with text_locale1 or text_locale2
    locale_el1 = "* {text CONTAINS '#{text_locale1}'}"
    locale_el2 = "* {text CONTAINS '#{text_locale2}'}"

    if element_exists(locale_el1)
      return locale_el1
    elsif element_exists(locale_el2)
      return locale_el2
    else
      return ("No such query!")
    end
  end
end
wait_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3) click to toggle source

—————————————————-Custom Waits—————————————————-

# File lib/SurfCustomCalabash/CommonMethods.rb, line 28
def wait_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
  wait_for_element_exists(element, timeout: timeout_duration, retry_frequency: retry_frequency)
  sleep(sleep_duration)
end
wait_for_screen(timeout_duration: 30, sleep_duration: 0, retry_frequency: 0.3) click to toggle source

wait trait-element on screen

# File lib/SurfCustomCalabash/CommonMethods.rb, line 39
def wait_for_screen(timeout_duration: 30, sleep_duration: 0, retry_frequency: 0.3)
  wait_element(trait, sleep_duration: sleep_duration, timeout_duration: timeout_duration, retry_frequency: retry_frequency)
end
wait_no_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3) click to toggle source
# File lib/SurfCustomCalabash/CommonMethods.rb, line 33
def wait_no_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
  wait_for_element_does_not_exist(element, timeout: timeout_duration, retry_frequency: retry_frequency)
  sleep(sleep_duration)
end