class Object

Constants

WAIT

WAIT instance for explicit wait

Public Instance Methods

add_selection(element, label) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 81
def add_selection(element, label)
  value = check_is_using_variable(label)
  found_element = find_object(element)
  found_element.find_element(:xpath, "//option[. = '#{value}']").click
end
answer_on_next_prompt(answer) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 56
def answer_on_next_prompt(answer)
  value = check_is_using_variable(answer)
  alert = $driver.switch_to.alert
  alert.send_keys(value)
  alert.accept()
end
assert(var_name, value) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 115
def assert(var_name, value)
  if (value == "true" || value == "false")
    _value = value
  else elseif (value == '0' || !!number_or_nil(value))
    _value = value
  end
  result = if _value
    expect($vars[var_name]).to eq(_value)
  else
    expect($vars[var_name]).to eq(value)
  end
end
assert_alert(text) click to toggle source

method to check javascript pop-up alert text

# File lib/itms_automation/methods/assertion_methods.rb, line 51
def assert_alert(text)
  value = check_is_using_variable(text)
  alert_text = $driver.switch_to.alert.text
  expect(alert_text).to eq(value)
end
assert_checked(element) click to toggle source

method to assert checkbox check param 1 : String : Element

# File lib/itms_automation/methods/assertion_methods.rb, line 40
def assert_checked(element)
  checkbox = find_object(element)
  expect(checkbox.selected?).to be_truthy
end
assert_confirmation(text) click to toggle source

method to check javascript pop-up alert text

# File lib/itms_automation/methods/assertion_methods.rb, line 58
def assert_confirmation(text)
  value = check_is_using_variable(text)
  alert_text = $driver.switch_to.alert.text
  expect(alert_text).to eq(value)
end
assert_editable(element) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 64
def assert_editable(element)
  found_element = find_object(element)
  expect(found_element.enabled?).to be_truthy
end
assert_element_not_present(element) click to toggle source

method to check element not presence param 1: String: Element

# File lib/itms_automation/methods/assertion_methods.rb, line 33
def assert_element_not_present(element)
  found_element = find_object(element)
  expect(found_element.length).to eq(0)
end
assert_element_present(element) click to toggle source

method to check element presence param 1: String: Element

# File lib/itms_automation/methods/assertion_methods.rb, line 26
def assert_element_present(element)
  found_element = find_object(element)
  expect(found_element.length).to be > 0
end
assert_not_checked(element) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 45
def assert_not_checked(element)
  checkbox = find_object(element)
  expect(checkbox.selected?).to be_falsey
end
assert_not_editable() click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 69
def assert_not_editable
  found_element = find_object(element)
  expect(found_element.enabled?).to be_falsey
end
assert_not_selected_value(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 74
def assert_not_selected_value(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).not_to eq(value)
end
assert_not_text(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 81
def assert_not_text(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  expect(found_element.text).not_to eq(value)
end
assert_prompt(text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 87
def assert_prompt(text)
  value = check_is_using_variable(text)
  alert_text = $driver.switch_to.alert.text
  expect(alert_text).to eq(value)
end
assert_selected_label(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 93
def assert_selected_label(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  locator = "option[@value='#{found_element.attribute('value')}']"
  selected_text = found_element.find_element(:xpath, locator).text
  expect(selected_text).to eq(value)
end
assert_selected_value(text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 108
def assert_selected_value(text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).to eq(value)
end
assert_text(element, expected_value) click to toggle source

Method to check element text param 1 : String : Element param 2 : String : Expected element text

# File lib/itms_automation/methods/assertion_methods.rb, line 17
def assert_text(element, expected_value)
  text = check_is_using_variable(expected_value)
  found_element = find_object(element)
  element_text = found_element.text
  expect(element_text).to eq(text)
end
assert_title(title) click to toggle source

Method to verify title param 1: String : expected title

# File lib/itms_automation/methods/assertion_methods.rb, line 9
def assert_title(title)
  text = check_is_using_variable(title)
  expect($driver.title).to eq(text)
end
assert_value(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 101
def assert_value(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).to eq(value)
end
check(element) click to toggle source

method to check checkbox

# File lib/itms_automation/methods/input_methods.rb, line 44
def check(element)
  checkbox = find_object(element)
  checkbox.click unless checkbox.selected?
end
check_using_variable(text) click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 66
def check_using_variable(text)
  regex = /\$\{(.*?)\}/
  text.scan(regex).each do |var|
    value = $vars[var[0].to_sym]
    if value
      replace = "${#{var[0]}}"
      text.gsub!(replace, "#{value}")
    end
  end
  text
end
choose_cancel_on_next_confirmation() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 63
def choose_cancel_on_next_confirmation
  $driver.switch_to.alert.dismiss
end
choose_cancel_on_next_prompt() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 67
def choose_cancel_on_next_prompt
  $driver.switch_to.alert.dismiss
end
choose_ok_on_next_confirmation() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 71
def choose_ok_on_next_confirmation
  $driver.switch_to.alert.accept
end
click(element) click to toggle source
# File lib/itms_automation/methods/click_elements_methods.rb, line 3
def click(element)
  found_element = find_object(element)
  found_element.click
end
click_at(element) click to toggle source
# File lib/itms_automation/methods/click_elements_methods.rb, line 8
def click_at(element)
  found_element = find_object(element)
  found_element.click
end
close() click to toggle source
# File lib/itms_automation/methods/navigate_methods.rb, line 18
def close
  $drive.close
end
compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name) click to toggle source

Method to compare two images param 1 : String : Locator type (id, name, class, xpath, css, url) param 2 : String : Locator value param 3 : String : Locator type (id, name, class, xpath, css, url, image_name) param 4 : String : Locator value

# File lib/itms_automation/methods/assertion_methods.rb, line 241
def compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
  if actual_img_access_type == 'url'
    actual_img_url = actual_img_access_name
  else
    actual_img_url = get_element_attribute(actual_img_access_type, actual_img_access_name, 'src')
  end

  if excp_img_access_type == 'url'
    expected_img_url = excp_img_access_name
  elsif excp_img_access_type == 'image_name'
    expected_img_url = './features/expected_images/' + excp_img_access_name
  else
    expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, 'src')
  end

  # replace 'https' with 'http' from actual image url
  if actual_img_url.include? 'https'
    actual_img_url['https'] = 'http'
  end

  # replace 'https' with 'http' from expected image url
  if expected_img_url.include? 'https'
    expected_img_url['https'] = 'http'
  end

  if expected_img_url.include? '.png'
    image_type = 'png'
  else
    image_type = 'jpg'
  end

  # Storing actual image locally
  open('./features/actual_images/actual_image.' + image_type, 'wb') do |file|
    file << open(actual_img_url).read
  end

  actual_img_url = './features/actual_images/actual_image.' + image_type

  # Storing Expected image locally
  if excp_img_access_type != 'image_name'
    open('./features/expected_images/expected_image.' + image_type, 'wb') do |file|
      file << open(expected_img_url).read
    end
    expected_img_url = './features/expected_images/expected_image.' + image_type
  end

  # Verify image extension and call respective compare function
  if image_type == 'png'
    return compare_png_images(expected_img_url, actual_img_url)
  end

  compare_jpeg_images(expected_img_url, actual_img_url)
end
compare_jpeg_images(expected_img_url, actual_img_url) click to toggle source

Comparing jpg images

# File lib/itms_automation/methods/assertion_methods.rb, line 296
def compare_jpeg_images(expected_img_url, actual_img_url)
  if open(expected_img_url).read == open(actual_img_url).read
    return true
  else
    puts 'Difference in images'
    return false
  end
end
compare_png_images(expected_img_url, actual_img_url) click to toggle source

Comparing png images

# File lib/itms_automation/methods/assertion_methods.rb, line 306
def compare_png_images(expected_img_url, actual_img_url)
  images = [
    ChunkyPNG::Image.from_file(expected_img_url),
    ChunkyPNG::Image.from_file(actual_img_url)
  ]

  diff = []

  images.first.height.times do |y|
    images.first.row(y).each_with_index do |pixel, x|
      diff << [x, y] unless pixel == images.last[x, y]
    end
  end

  if diff.length != 0
    puts "\npixels (total):     #{images.first.pixels.length}"
    puts "pixels changed:     #{diff.length}"
    puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%"

    x, y = diff.map { |xy| xy[0] }, diff.map { |xy| xy[1] }
    images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0, 255, 0))
    cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
    images.last.save("./features/image_difference/difference_#{cur_time}.png")

    puts "\nDifference between images saved as : difference_#{cur_time}.png\n"
    return false
  end
  true
end
debugger() click to toggle source
# File lib/itms_automation/methods/configuration_methods.rb, line 41
def debugger
end
does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name) click to toggle source

Method to find difference between images

# File lib/itms_automation/methods/assertion_methods.rb, line 230
def does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
  if !compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
    raise TestCaseFailed, 'Actual image is different from expected image'
  end
end
double_click(element) click to toggle source
# File lib/itms_automation/methods/click_elements_methods.rb, line 13
def double_click(element)
  found_element = find_object(element)
  $driver.action.double_click(found_element).perform
end
double_click_at(element, location) click to toggle source
# File lib/itms_automation/methods/click_elements_methods.rb, line 18
def double_click_at(element, location)
  found_element = find_object(element)
  $driver.action.double_click(found_element).perform
end
drag_and_drop_to_object(element, drop_element) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 98
def drag_and_drop_to_object(element, drop_element)
  dragged = find_object(element)
  object_value_regex = /^(class=|css=|id=|name=|xpath=|className=|link=|linkText=|partialLinkText=)/
  object_type_regex = /^(class|css|id|name|xpath|className|link|linkText|partialLinkText)/
  if object_value_regex.match?(drop_element)
    object_value = drop_element.gsub(object_value_regex, "")
    object_type = drop_element.split(object_type_regex)[1].underscore
    dropped = $driver.find_element(object_type.to_sym, object_value)
    $driver.action.drag_and_drop(dragged, dropped).perform
  else
    raise TestCaseFailed, "Option locator not supported"
  end
end
echo(message) click to toggle source
# File lib/itms_automation/methods/configuration_methods.rb, line 37
def echo(message)
  puts(message)
end
edit_content(element, text) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 75
def edit_content(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  $driver.execute_script("if (arguments[0].contentEditable === 'true') {arguments[0].innerText = '#{value}'}", found_element)
end
else_if(condition_script) click to toggle source
# File lib/itms_automation/methods/condition_methods.rb, line 8
def else_if(condition_script)
  value = check_is_using_variable(condition_script)
  $driver.execute_script(value)
end
find_object(string_object) click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 37
def find_object(string_object)
  $OBJECT = load_object_repository
  string_object = string_object.gsub(/"/, "'")
  hash_object = $OBJECT[string_object]
  if hash_object == nil
    raise "Object not found - Object: #{string_object} is not found in Object Repository."
  end
  locator_type = hash_object.keys.first.to_s
  locator_value = hash_object[locator_type]
  validate_locator(locator_type)
  $driver.find_element(:"#{locator_type}" => "#{locator_value}")
end
get_device_info() click to toggle source

Return android device name and android version using adb command

# File lib/itms_automation/methods/misc_methods.rb, line 29
def get_device_info
  IO.popen('adb shell getprop ro.product.brand') { |f| $device = f.gets.chomp.upcase}
  $device += ' '
  IO.popen('adb shell getprop ro.product.model') { |f| $device += f.gets.chomp.upcase}
  IO.popen('adb shell getprop ro.build.version.release') { |f| $os_version = f.gets.chomp.upcase}
  return $device, $os_version
end
get_key() click to toggle source

method to return key by os wise

# File lib/itms_automation/methods/navigate_methods.rb, line 28
def get_key
  os = Selenium::WebDriver::Platform.os
  if os.to_s == 'windows'
    return 'control'
  elsif os.to_s == 'macosx'
    return 'command'
  else
    raise 'Invalid OS'
  end
end
handle_alert(decesion) click to toggle source
# File lib/itms_automation/methods/javascript_handling_methods.rb, line 3
def handle_alert(decesion)
  if decesion == 'accept'
    $driver.switch_to.alert.accept
  else
    $driver.switch_to.alert.dismiss
  end
end
if(condition_script) click to toggle source
# File lib/itms_automation/methods/condition_methods.rb, line 3
def if(condition_script)
  value = check_is_using_variable(condition_script)
  $driver.execute_script(value)
end
loadYAMLfile(filename) click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 58
def loadYAMLfile(filename)
  begin
    return YAML.load_file(filename)
  rescue Psych::SyntaxError => ex
    raise "Syntax error when reading file: #{ex}"
  end
end
load_object_repository() click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 50
def load_object_repository
  begin
    loadYAMLfile("features/step_definitions/repositories/project_object.yml")
  rescue => exception
    print_error_object_repository
  end
end
long_press(element, duration) click to toggle source
# File lib/itms_automation/methods/click_elements_methods.rb, line 23
def long_press(element, duration)
  found_element = find_object(element)
  parameters = { "element" => "#{found_element}", "duration" => "#{duration}" }
  args = parameters.select { |k, v| [:element, :duration].include? k }
  args = args_with_ele_ref(args)
  chain_method(:longPress, args)
end
maximize_browser() click to toggle source

Method to maximize browser

# File lib/itms_automation/methods/navigate_methods.rb, line 64
def maximize_browser
  $driver.manage.window.maximize
end
mouse_down(element) click to toggle source

mouse_down

# File lib/itms_automation/methods/navigate_methods.rb, line 80
def mouse_down(element)
  element = find_object(element)
  $driver.action.move_to_element(element).click_and_hold.perform
end
mouse_down_at(element, location) click to toggle source

mouse_down_at

# File lib/itms_automation/methods/navigate_methods.rb, line 86
def mouse_down_at(element, location)
  element = find_object(element)
  $driver.action.move_to_element(element).click_and_hold.perform
end
mouse_move_at() click to toggle source

mouse_move_at

# File lib/itms_automation/methods/navigate_methods.rb, line 110
def mouse_move_at
  element = find_object(element)
  $driver.action.move_to_element(element).perform
end
mouse_out() click to toggle source

mouse_out

# File lib/itms_automation/methods/navigate_methods.rb, line 92
def mouse_out
  element = $driver.find_element(By.CSS_SELECTOR, 'body')
  $driver.action.move_to_element(element, 0, 0).perform
end
mouse_over(element) click to toggle source

Method to hover on element

# File lib/itms_automation/methods/navigate_methods.rb, line 74
def mouse_over(element)
  element = find_object(element)
  $driver.action.move_to_element(element).perform
end
mouse_up(element) click to toggle source

mouse_up

# File lib/itms_automation/methods/navigate_methods.rb, line 98
def mouse_up(element)
  element = find_object(element)
  $driver.action.move_to_element(element).release.perform
end
mouse_up_at() click to toggle source

mouse_up_at

# File lib/itms_automation/methods/navigate_methods.rb, line 104
def mouse_up_at
  element = find_object(element)
  $driver.action.move_to_element(element).release.perform
end
navigate(direction) click to toggle source

method to navigate back & forward

number_or_nil(string) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 336
def number_or_nil(string)
  num = string.to_i
  num if num.to_s == string
end
open(link) click to toggle source

method to open link

# File lib/itms_automation/methods/navigate_methods.rb, line 4
def open(link)
  value = check_is_using_variable(link)
  $driver.get(value)
end
pause(time) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 3
def pause(time)
  value = check_is_using_variable(time)
  sleep value.to_i
end
print_congifugartion() click to toggle source

method to print configuration

print_desktop_configuration() click to toggle source

method to print desktop configuration

print_error_android(browser_type, app_path) click to toggle source

print error for android

print_error_android_app() click to toggle source

print error for android app

print_error_android_web() click to toggle source

print error for android web

print_error_desktop() click to toggle source

print error for desktop

print_error_ios() click to toggle source

print error for ios

print_error_ios_app() click to toggle source

print error for ios app

print_error_ios_web() click to toggle source

print error for ios web

print_error_object_repository() click to toggle source
print_invalid_platform() click to toggle source

print error if invalid platform

print_mobile_configuration() click to toggle source

method to print mobile configuration

quit() click to toggle source

method to quite webdriver instance

# File lib/itms_automation/methods/navigate_methods.rb, line 23
def quit
  $driver.quit
end
refresh_page() click to toggle source

Method to refresh page

# File lib/itms_automation/methods/navigate_methods.rb, line 69
def refresh_page
  $driver.navigate.refresh
end
remove_selection(element, label) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 87
def remove_selection(element, label)
  value = check_is_using_variable(label)
  found_element = find_object(element)
  found_element.find_element(:xpath, "//option[. = '#{value}']").click
end
scroll_page(to) click to toggle source

method to scroll page to top or end

# File lib/itms_automation/methods/navigate_methods.rb, line 122
def scroll_page(to)
  if to == 'end'
    $driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
  elsif to == 'top'
    $driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
  else
    raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
  end
end
scroll_to_element(element) click to toggle source

Method to scroll page to perticular element

# File lib/itms_automation/methods/navigate_methods.rb, line 116
def scroll_to_element(element)
  ele_scroll = find_object(element)
  ele_scroll.location_once_scrolled_into_view
end
select(element) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 93
def select(element)
  found_element = find_object(element)
  found_element.find_element(:xpath, "//option[. = '#{label}']").click
end
select_all_option_from_multiselect_dropdown(element) click to toggle source

method to select all option from dropdwon list

# File lib/itms_automation/methods/input_methods.rb, line 30
def select_all_option_from_multiselect_dropdown(element)
  dropdown = WAIT.until { find_object(element) }
  select_list = Selenium::WebDriver::Support::Select.new(dropdown)
  select_list.select_all
end
select_frame(element) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 115
def select_frame(element)
end
select_option_from_dropdown(element, by, option) click to toggle source

method to select option from dropdwon list

# File lib/itms_automation/methods/input_methods.rb, line 23
def select_option_from_dropdown(element, by, option)
  dropdown = WAIT.until { find_object(element) }
  select_list = Selenium::WebDriver::Support::Select.new(dropdown)
  select_list.select_by(:"#{by}", "#{option}")
end
select_option_from_radio_button_group(element, by, option) click to toggle source

method to select option from radio button group

# File lib/itms_automation/methods/input_methods.rb, line 67
def select_option_from_radio_button_group(element, by, option)
  radio_button_group = WAIT.until { find_object(element) }

  getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
  ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
  ele.click unless ele.selected?
end
select_radio_button(element) click to toggle source

method to select radio button

# File lib/itms_automation/methods/input_methods.rb, line 61
def select_radio_button(element)
  radio_button = WAIT.until { find_object(element) }
  radio_button.click unless radio_button.selected?
end
select_window(element) click to toggle source
# File lib/itms_automation/methods/input_methods.rb, line 112
def select_window(element)
end
send_keys(element, key) click to toggle source

method to send keys

# File lib/itms_automation/methods/input_methods.rb, line 10
def send_keys(element, key)
  value = check_is_using_variable(key)
  keys_support = ["KEY_LEFT", "KEY_UP", "KEY_RIGHT", "KEY_DOWN", "KEY_PAGE_UP", "KEY_PAGE_DOWN", "KEY_BACKSPACE", "KEY_DELETE", "KEY_ENTER", "KEY_TAB"]
  foundElement = find_object(element)
  if value
    get_key = value.strip[/^\$\{(.*?)\}$/, 1]
    raise TestCaseFailed, "${get_key} key is not supported. Supported keys: KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_PAGE_UP, KEY_PAGE_DOWN, KEY_BACKSPACE, KEY_DELETE, KEY_ENTER, KEY_TAB" unless keys_support.include?(get_key)
    key_convert = get_key[/^KEY_(.*?)$/, 1].downcase.to_sym
    foundElement.send_keys(key_convert)
  end
end
set_window_size(resolution) click to toggle source

Method to resize browser

# File lib/itms_automation/methods/navigate_methods.rb, line 56
def set_window_size(resolution)
  value = check_is_using_variable(resolution)
  raise TestCaseFailed, 'Wrong format of resolution. (e.g., 1280x800)' unless value.match(/^\d+x\d+$/)
  width, height = value.split("x")
  $driver.manage.resize_to(width, heigth)
end
store(var_name, value) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 3
def store(var_name, value)
  $vars[var_name] = value
end
store_attribute(element, attribute, var_name) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 30
def store_attribute(element, attribute, var_name)
  found_element = find_object(element)
  value = found_element.attribute(attribute)
  $vars[var_name] = value
end
store_json(var_name, value) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 7
def store_json(var_name, value)
  $vars[var_name] = JSON.parse(value)
end
store_text(element, var_name) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 11
def store_text(element, var_name)
  found_element = find_object(element)
  element_text = found_element.text
  $vars[var_name] = element_text
end
store_title(var_name) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 17
def store_title(var_name)
  $vars[var_name] = $driver.title
end
store_window_handle(var_name) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 26
def store_window_handle(var_name)
  $vars[var_name] = $driver.window_handle
end
store_xpath_count(element, var_name) click to toggle source
# File lib/itms_automation/methods/store_methods.rb, line 21
def store_xpath_count(element, var_name)
  found_element = find_object(element)
  $vars[var_name] = found_element.length
end
take_screenshot() click to toggle source
# File lib/itms_automation/methods/screenshot_methods.rb, line 3
def take_screenshot
  cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
  $driver.save_screenshot('./features/screenshots/screenshot' + cur_time + '.png')
end
toggle_checkbox(element) click to toggle source

method to toggle checkbox checked

# File lib/itms_automation/methods/input_methods.rb, line 56
def toggle_checkbox(element)
  find_object(element).click
end
type(element, text) click to toggle source

method to enter text into textfield

# File lib/itms_automation/methods/input_methods.rb, line 4
def type(element, text)
  foundElement = find_object(element)
  foundElement.send_keys(text)
end
uncheck(element) click to toggle source

method to uncheck checkbox

# File lib/itms_automation/methods/input_methods.rb, line 50
def uncheck(element)
  checkbox = find_object(element)
  checkbox.click if checkbox.selected?
end
unselect_all_option_from_multiselect_dropdown(element) click to toggle source

method to unselect all option from dropdwon list

# File lib/itms_automation/methods/input_methods.rb, line 37
def unselect_all_option_from_multiselect_dropdown(element)
  dropdown = WAIT.until { find_object(element) }
  select_list = Selenium::WebDriver::Support::Select.new(dropdown)
  select_list.deselect_all
end
valid_locator_type?(type) click to toggle source

method to validate locator

# File lib/itms_automation/methods/misc_methods.rb, line 11
def valid_locator_type? type
  %w(id class css name xpath class_name link link_text partial_link_text).include? type
end
valid_option_by?(option_by) click to toggle source

method to validate dropdown selector

# File lib/itms_automation/methods/misc_methods.rb, line 20
def valid_option_by? option_by
  %w(text value index).include? option_by
end
validate_locator(type) click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 15
def validate_locator type
  raise "Invalid locator type - #{type}" unless valid_locator_type? type
end
validate_option_by(option_by) click to toggle source
# File lib/itms_automation/methods/misc_methods.rb, line 24
def validate_option_by option_by
  raise "Invalid option by - #{option_by}" unless valid_option_by? option_by
end
validate_parameters(platform, browser_type, app_path) click to toggle source

Method to check browser type

# File lib/itms_automation/methods/error_handling_methods.rb, line 4
def validate_parameters(platform, browser_type, app_path)
  if platform == 'desktop'
    if !%w(firefox internet_explorer chrome safari opera chrome_headless remote).include? browser_type
      print_error_desktop
    end
  elsif platform == 'android'
      print_error_android browser_type, app_path
  elsif platform == 'iOS'
    puts "Not Implemented..."
    # print_error_ios browser_type, app_path
  else
    print_invalid_platform
  end
end
verify(var_name, value) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 216
def verify(var_name, value)
  if (value == "true" || value == "false")
    _value = value
  else elseif (value == '0' || !!number_or_nil(value))
    _value = value
  end
  result = if _value
    expect($vars[var_name]).to eq(_value)
  else
    expect($vars[var_name]).to eq(value)
  end
end
verify_checked(element) click to toggle source

method to assert checkbox check param 1 : String : Element

# File lib/itms_automation/methods/assertion_methods.rb, line 161
def verify_checked(element)
  checkbox = find_object(element)
  expect(checkbox.selected?).to be_truthy
end
verify_editable(element) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 171
def verify_editable(element)
  found_element = find_object(element)
  expect(found_element.enabled?).to be_truthy
end
verify_element_not_present(element) click to toggle source

method to check element not presence param 1: String: Element

# File lib/itms_automation/methods/assertion_methods.rb, line 154
def verify_element_not_present(element)
  found_element = find_object(element)
  expect(found_element.length).to eq(0)
end
verify_element_present(element) click to toggle source

method to check element presence param 1: String: Element

# File lib/itms_automation/methods/assertion_methods.rb, line 147
def verify_element_present(element)
  found_element = find_object(element)
  expect(found_element.length).to be > 0
end
verify_not_checked(element) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 166
def verify_not_checked(element)
  checkbox = find_object(element)
  expect(checkbox.selected?).to be_falsey
end
verify_not_editable() click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 176
def verify_not_editable
  found_element = find_object(element)
  expect(found_element.enabled?).to be_falsey
end
verify_not_selected_value(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 181
def verify_not_selected_value(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).not_to eq(value)
end
verify_not_text(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 188
def verify_not_text(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  expect(found_element.text).not_to eq(value)
end
verify_selected_label(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 194
def verify_selected_label(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  locator = "option[@value='#{found_element.attribute('value')}']"
  selected_text = found_element.find_element(:xpath, locator).text
  expect(selected_text).to eq(value)
end
verify_selected_value(text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 209
def verify_selected_value(text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).to eq(value)
end
verify_text(element, expected_value) click to toggle source

Method to check element text param 1 : String : Element param 2 : String : Expected element text

# File lib/itms_automation/methods/assertion_methods.rb, line 138
def verify_text(element, expected_value)
  text = check_is_using_variable(expected_value)
  found_element = find_object(element)
  element_text = found_element.text
  expect(element_text).to eq(text)
end
verify_title(title) click to toggle source

Method to verify title param 1: String : expected title

# File lib/itms_automation/methods/assertion_methods.rb, line 130
def verify_title(title)
  value = check_is_using_variable(title)
  expect($driver.title).to eq(value)
end
verify_value(element, text) click to toggle source
# File lib/itms_automation/methods/assertion_methods.rb, line 202
def verify_value(element, text)
  value = check_is_using_variable(text)
  found_element = find_object(element)
  value = found_element.attribute("value")
  expect(value).to eq(value)
end
wait_for_element_editable(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 8
def wait_for_element_editable(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until { find_object(element).enabled? }
end
wait_for_element_not_editable(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 14
def wait_for_element_not_editable(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until { !find_object(element).enabled? }
end
wait_for_element_not_present(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 20
def wait_for_element_not_present(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until do
    begin
      !find_object(element)
    rescue Selenium::WebDriver::Error::NoSuchElementError
      true
    end
  end
end
wait_for_element_not_visible(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 32
def wait_for_element_not_visible(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until { !find_object(element).displayed? }
end
wait_for_element_present(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 50
def wait_for_element_present(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until { find_object(element) }
end
wait_for_element_visible(element, duration) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 44
def wait_for_element_visible(element, duration)
  value = check_is_using_variable(duration)
  wait = Selenium::WebDriver::Wait.new(:timeout => value.to_i / 1000)
  wait.until { find_object(element).displayed? }
end
wait_for_text(element, text) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 38
def wait_for_text(element, text)
  value = check_is_using_variable(text)
  wait = Selenium::WebDriver::Wait.new(:timeout => 30)
  wait.until { find_object(element).text == value }
end
webdriver_answer_on_visible_prompt(answer) click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 75
def webdriver_answer_on_visible_prompt(answer)
  value = check_is_using_variable(answer)
  alert = $driver.switch_to.alert
  alert.send_keys(value)
  alert.accept()
end
webdriver_choose_cancel_on_visible_confirmation() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 82
def webdriver_choose_cancel_on_visible_confirmation
  $driver.switch_to.alert.dismiss
end
webdriver_choose_cancel_on_visible_prompt() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 90
def webdriver_choose_cancel_on_visible_prompt
  $driver.switch_to.alert.dismiss
end
webdriver_choose_ok_on_visible_confirmation() click to toggle source
# File lib/itms_automation/methods/progress_methods.rb, line 86
def webdriver_choose_ok_on_visible_confirmation
  $driver.switch_to.alert.accept
end
while(condition_script) click to toggle source
# File lib/itms_automation/methods/condition_methods.rb, line 13
def while(condition_script)
  value = check_is_using_variable(condition_script)
  $driver.execute_script(value)
end
zoom_in_out(in_out) click to toggle source

Method to zoom in/out page

# File lib/itms_automation/methods/navigate_methods.rb, line 40
def zoom_in_out(in_out)
  $driver.action.key_down(:"#{get_key}").send_keys(:"#{in_out}").key_up(:"#{get_key}").perform
end
zoom_in_out_till_element_display(element, in_out) click to toggle source

Method to zoom in/out web page until web element dislays

# File lib/itms_automation/methods/navigate_methods.rb, line 45
def zoom_in_out_till_element_display(element, in_out)
  while true
    if find_object(element).displayed?
      break
    else
      $driver.action.key_down(:"#{get_key}").send_keys(:"#{in_out}").key_up(:"#{get_key}").perform
    end
  end
end