class Object
Constants
- WAIT
WAIT
instance for explicit wait
Public Instance Methods
# 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
# 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
# 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
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
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
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
# 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
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
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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
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
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
# 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
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
# 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
# File lib/itms_automation/methods/progress_methods.rb, line 63 def choose_cancel_on_next_confirmation $driver.switch_to.alert.dismiss end
# File lib/itms_automation/methods/progress_methods.rb, line 67 def choose_cancel_on_next_prompt $driver.switch_to.alert.dismiss end
# File lib/itms_automation/methods/progress_methods.rb, line 71 def choose_ok_on_next_confirmation $driver.switch_to.alert.accept end
# File lib/itms_automation/methods/click_elements_methods.rb, line 3 def click(element) found_element = find_object(element) found_element.click end
# File lib/itms_automation/methods/click_elements_methods.rb, line 8 def click_at(element) found_element = find_object(element) found_element.click end
# File lib/itms_automation/methods/navigate_methods.rb, line 18 def close $drive.close end
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
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
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
# File lib/itms_automation/methods/configuration_methods.rb, line 41 def debugger end
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
# 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
# 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
# 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
# File lib/itms_automation/methods/configuration_methods.rb, line 37 def echo(message) puts(message) end
# 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
# 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
# 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
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
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
# 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
# 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
# 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
# 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
# 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
Method to maximize browser
# File lib/itms_automation/methods/navigate_methods.rb, line 64 def maximize_browser $driver.manage.window.maximize end
# 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
# 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
# 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
# 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
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
# 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
# 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
# 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
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
# File lib/itms_automation/methods/progress_methods.rb, line 3 def pause(time) value = check_is_using_variable(time) sleep value.to_i end
method to print configuration
# File lib/itms_automation/methods/configuration_methods.rb, line 4 def print_congifugartion puts '' puts "Date : #{Time.now.strftime("%d-%B-%Y")}" puts "Time : #{Time.now.strftime("%I:%M:%S:%p")}" if $platform == 'android' or $platform == 'ios' print_mobile_configuration else print_desktop_configuration end end
method to print desktop configuration
# File lib/itms_automation/methods/configuration_methods.rb, line 17 def print_desktop_configuration puts 'Platform : ' + Selenium::WebDriver::Platform.os.to_s.upcase puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s puts '' end
print error for android
# File lib/itms_automation/methods/error_handling_methods.rb, line 29 def print_error_android(browser_type, app_path) if browser_type=='firefox' and app_path==nil puts "\nOops... not mentioned \"Browser\" or \"App path\"" print_error_android_app print_error_android_web Process.exit(0) elsif browser_type!='firefox' and !%w(native chrome).include? browser_type puts "\nOops... not supported browser" print_error_android_web Process.exit(0) end end
print error for android app
# File lib/itms_automation/methods/error_handling_methods.rb, line 43 def print_error_android_app puts "\nTo run test on android app" puts "\n Usage : cucumber PLATFORM=android APP_PATH=path/to/app" end
print error for android web
# File lib/itms_automation/methods/error_handling_methods.rb, line 49 def print_error_android_web puts "\nTo run test on android mobile web" puts "\n Usage : cucumber PLATFORM=android BROWSER=browser_name" puts "\n Supported browsers are \"chrome\" and \"native\"" end
print error for desktop
# File lib/itms_automation/methods/error_handling_methods.rb, line 20 def print_error_desktop puts "\nInappropraite desktop browser : \"#{ENV['BROWSER']}\"" puts "\nUsage : cucumber BROWSER=browser_name" puts "\nBrowser Supported :\n" puts "\n1.internet_explorer\n2.chrome\n3.firefox\n4.safari\n5.opera\n6.chrome_headless\n7.remote" Process.exit(0) end
print error for ios
# File lib/itms_automation/methods/error_handling_methods.rb, line 56 def print_error_ios if browser_type=='firefox' and app_path==nil puts "\nOops... not mentioned \"Browser\" or \"App path\"" print_error_ios_app print_error_ios_web Process.exit(0) elsif browser_type!='safari' puts "\nOops... not supported browser" print_error_ios_app_web Process.exit(0) end end
print error for ios app
# File lib/itms_automation/methods/error_handling_methods.rb, line 70 def print_error_ios_app puts "\nTo run test on iOS App" puts "\n Usage : cucumber PLATFORM=iOS APP_PATH=path/to/app" end
print error for ios web
# File lib/itms_automation/methods/error_handling_methods.rb, line 76 def print_error_ios_web puts "\nTo run test on iOS mobile web" puts "\n Usage : cucumber PLATFORM=iOS BROWSER=safari" end
# File lib/itms_automation/methods/error_handling_methods.rb, line 89 def print_error_object_repository puts "\nNo Object Repository found." puts "\nPlease create file \"project_object.yml\" in path \"features/step_definitions/repositories/\"" Process.exit(0) end
print error if invalid platform
# File lib/itms_automation/methods/error_handling_methods.rb, line 82 def print_invalid_platform puts "\nOops... Invalid Platform" puts "\nSupported platform are \"android\" and \"iOS\"." puts "\nTo run on Desktop no need to mention platform." Process.exit(0) end
method to print mobile configuration
# File lib/itms_automation/methods/configuration_methods.rb, line 24 def print_mobile_configuration puts "Platform : #{$platform.upcase}" puts "OS version : #{$os_version}" puts "Device : #{$device_name}" if $app_path.nil? puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s else puts "App Tested : #{$app_path}" end puts '' end
method to quite webdriver instance
# File lib/itms_automation/methods/navigate_methods.rb, line 23 def quit $driver.quit end
Method to refresh page
# File lib/itms_automation/methods/navigate_methods.rb, line 69 def refresh_page $driver.navigate.refresh end
# 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
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
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
# 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
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
# File lib/itms_automation/methods/input_methods.rb, line 115 def select_frame(element) end
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
# File lib/itms_automation/methods/input_methods.rb, line 112 def select_window(element) end
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
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
# File lib/itms_automation/methods/store_methods.rb, line 3 def store(var_name, value) $vars[var_name] = value end
# 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
# File lib/itms_automation/methods/store_methods.rb, line 7 def store_json(var_name, value) $vars[var_name] = JSON.parse(value) end
# 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
# File lib/itms_automation/methods/store_methods.rb, line 17 def store_title(var_name) $vars[var_name] = $driver.title end
# File lib/itms_automation/methods/store_methods.rb, line 26 def store_window_handle(var_name) $vars[var_name] = $driver.window_handle end
# 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
# 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
method to toggle checkbox checked
# File lib/itms_automation/methods/input_methods.rb, line 56 def toggle_checkbox(element) find_object(element).click end
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
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
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
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
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
# 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
# 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
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
# 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
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
# 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
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
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
# 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
# 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
# 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
# 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
# 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
# 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
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
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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# File lib/itms_automation/methods/progress_methods.rb, line 82 def webdriver_choose_cancel_on_visible_confirmation $driver.switch_to.alert.dismiss end
# File lib/itms_automation/methods/progress_methods.rb, line 90 def webdriver_choose_cancel_on_visible_prompt $driver.switch_to.alert.dismiss end
# File lib/itms_automation/methods/progress_methods.rb, line 86 def webdriver_choose_ok_on_visible_confirmation $driver.switch_to.alert.accept end
# 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
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
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