Top Level Namespace
- Includes:
- RbConfig
Defined Under Namespace
Modules: ITMS Classes: TestCaseFailed
Constant Summary collapse
- WAIT =
WAIT instance for explicit wait
Selenium::WebDriver::Wait.new(:timeout => 30)
Instance Method Summary collapse
- #add_selection(label) ⇒ Object
- #answer_on_next_prompt(answer) ⇒ Object
-
#check(element) ⇒ Object
method to check checkbox.
- #choose_cancel_on_next_confirmation ⇒ Object
- #choose_cancel_on_next_prompt ⇒ Object
- #choose_ok_on_next_confirmation ⇒ Object
- #click(element) ⇒ Object
- #click_at(element) ⇒ Object
- #close ⇒ Object
- #debugger ⇒ Object
- #double_click(element) ⇒ Object
- #double_click_at(element, location) ⇒ Object
- #drag_and_drop_to_object(element, drop_element) ⇒ Object
- #echo(message) ⇒ Object
- #edit_content(element, text) ⇒ Object
- #else_if(condition_script) ⇒ Object
- #find_object(string_object) ⇒ Object
-
#get_device_info ⇒ Object
Return android device name and android version using adb command.
-
#get_key ⇒ Object
method to return key by os wise.
- #handle_alert(decesion) ⇒ Object
- #if(condition_script) ⇒ Object
- #load_object_repository ⇒ Object
- #loadYAMLfile(filename) ⇒ Object
- #long_press(element, duration) ⇒ Object
-
#maximize_browser ⇒ Object
Method to maximize browser.
-
#mouse_down(element) ⇒ Object
mouse_down.
-
#mouse_down_at(element, location) ⇒ Object
mouse_down_at.
-
#mouse_move_at ⇒ Object
mouse_move_at.
-
#mouse_out ⇒ Object
mouse_out.
-
#mouse_over(element) ⇒ Object
Method to hover on element.
-
#mouse_up(element) ⇒ Object
mouse_up.
-
#mouse_up_at ⇒ Object
mouse_up_at.
-
#navigate(direction) ⇒ Object
method to navigate back & forward.
-
#open(link) ⇒ Object
method to open link.
- #pause(time) ⇒ Object
-
#print_congifugartion ⇒ Object
method to print configuration.
-
#print_desktop_configuration ⇒ Object
method to print desktop configuration.
-
#print_error_android(browser_type, app_path) ⇒ Object
print error for android.
-
#print_error_android_app ⇒ Object
print error for android app.
-
#print_error_android_web ⇒ Object
print error for android web.
-
#print_error_desktop ⇒ Object
print error for desktop.
-
#print_error_ios ⇒ Object
print error for ios.
-
#print_error_ios_app ⇒ Object
print error for ios app.
-
#print_error_ios_web ⇒ Object
print error for ios web.
- #print_error_object_repository ⇒ Object
-
#print_invalid_platform ⇒ Object
print error if invalid platform.
-
#print_mobile_configuration ⇒ Object
method to print mobile configuration.
-
#quit ⇒ Object
method to quite webdriver instance.
-
#refresh_page ⇒ Object
Method to refresh page.
- #remove_selection ⇒ Object
-
#scroll_page(to) ⇒ Object
method to scroll page to top or end.
-
#scroll_to_element(element) ⇒ Object
Method to scroll page to perticular element.
- #select ⇒ Object
-
#select_all_option_from_multiselect_dropdown(element) ⇒ Object
method to select all option from dropdwon list.
- #select_frame(element) ⇒ Object
-
#select_option_from_dropdown(element, by, option) ⇒ Object
method to select option from dropdwon list.
-
#select_option_from_radio_button_group(element, by, option) ⇒ Object
method to select option from radio button group.
-
#select_radio_button(element) ⇒ Object
method to select radio button.
- #select_window(element) ⇒ Object
-
#send_keys(element, key) ⇒ Object
method to send keys.
-
#set_window_size(resolution) ⇒ Object
Method to resize browser.
- #store(var_name, value) ⇒ Object
- #store_attribute(element, attribute, var_name) ⇒ Object
- #store_json(var_name, value) ⇒ Object
- #store_text(element, var_name) ⇒ Object
- #store_title(var_name) ⇒ Object
- #store_window_handle(var_name) ⇒ Object
- #store_xpath_count(element, var_name) ⇒ Object
- #take_screenshot ⇒ Object
-
#toggle_checkbox(element) ⇒ Object
method to toggle checkbox checked.
-
#type(element, text) ⇒ Object
method to enter text into textfield.
-
#uncheck(element) ⇒ Object
method to uncheck checkbox.
-
#unselect_all_option_from_multiselect_dropdown(element) ⇒ Object
method to unselect all option from dropdwon list.
-
#valid_locator_type?(type) ⇒ Boolean
method to validate locator.
-
#valid_option_by?(option_by) ⇒ Boolean
method to validate dropdown selector.
- #validate_locator(type) ⇒ Object
- #validate_option_by(option_by) ⇒ Object
-
#validate_parameters(platform, browser_type, app_path) ⇒ Object
Method to check browser type.
- #wait_for_element_editable(element, duration) ⇒ Object
- #wait_for_element_not_editable(element, duration) ⇒ Object
- #wait_for_element_not_present(element, duration) ⇒ Object
- #wait_for_element_not_visible(element, duration) ⇒ Object
- #wait_for_element_present(element, duration) ⇒ Object
- #wait_for_element_visible(element, duration) ⇒ Object
- #wait_for_text(element, text) ⇒ Object
- #webdriver_answer_on_visible_prompt ⇒ Object
- #webdriver_choose_cancel_on_visible_confirmation ⇒ Object
- #webdriver_choose_cancel_on_visible_prompt ⇒ Object
- #webdriver_choose_ok_on_visible_confirmation ⇒ Object
- #while(condition_script) ⇒ Object
-
#zoom_in_out(in_out) ⇒ Object
Method to zoom in/out page.
-
#zoom_in_out_till_element_display(element, in_out) ⇒ Object
Method to zoom in/out web page until web element dislays.
Instance Method Details
#add_selection(label) ⇒ Object
79 80 81 82 |
# File 'lib/itms_automation/methods/input_methods.rb', line 79 def add_selection(label) found_element = find_object(element) found_element.find_element(:xpath, "//option[. = '#{label}']").click end |
#answer_on_next_prompt(answer) ⇒ Object
48 49 50 51 52 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 48 def answer_on_next_prompt(answer) alert = $driver.switch_to.alert alert.send_keys(answer) alert.accept() end |
#check(element) ⇒ Object
method to check checkbox
43 44 45 46 |
# File 'lib/itms_automation/methods/input_methods.rb', line 43 def check(element) checkbox = find_object(element) checkbox.click unless checkbox.selected? end |
#choose_cancel_on_next_confirmation ⇒ Object
54 55 56 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 54 def choose_cancel_on_next_confirmation $driver.switch_to.alert.dismiss end |
#choose_cancel_on_next_prompt ⇒ Object
58 59 60 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 58 def choose_cancel_on_next_prompt $driver.switch_to.alert.dismiss end |
#choose_ok_on_next_confirmation ⇒ Object
62 63 64 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 62 def choose_ok_on_next_confirmation $driver.switch_to.alert.accept end |
#click(element) ⇒ Object
3 4 5 6 |
# 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) ⇒ Object
8 9 10 11 |
# 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 ⇒ Object
17 18 19 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 17 def close $drive.close end |
#debugger ⇒ Object
41 42 |
# File 'lib/itms_automation/methods/configuration_methods.rb', line 41 def debugger end |
#double_click(element) ⇒ Object
13 14 15 16 |
# 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) ⇒ Object
18 19 20 21 |
# 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) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/itms_automation/methods/input_methods.rb', line 94 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) ⇒ Object
37 38 39 |
# File 'lib/itms_automation/methods/configuration_methods.rb', line 37 def echo() puts() end |
#edit_content(element, text) ⇒ Object
74 75 76 77 |
# File 'lib/itms_automation/methods/input_methods.rb', line 74 def edit_content(element, text) found_element = find_object(element) $driver.execute_script("if (arguments[0].contentEditable === 'true') {arguments[0].innerText = '#{text}'}", found_element) end |
#else_if(condition_script) ⇒ Object
7 8 9 |
# File 'lib/itms_automation/methods/condition_methods.rb', line 7 def else_if(condition_script) return $driver.execute_script(condition_script) end |
#find_object(string_object) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
Return android device name and android version using adb command
29 30 31 32 33 34 35 |
# 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 ⇒ Object
method to return key by os wise
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 27 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) ⇒ Object
3 4 5 6 7 8 9 |
# 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) ⇒ Object
3 4 5 |
# File 'lib/itms_automation/methods/condition_methods.rb', line 3 def if(condition_script) return $driver.execute_script(condition_script) end |
#load_object_repository ⇒ Object
50 51 52 53 54 55 56 |
# 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 |
#loadYAMLfile(filename) ⇒ Object
58 59 60 61 62 63 64 |
# 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 |
#long_press(element, duration) ⇒ Object
23 24 25 26 27 28 29 |
# 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 ⇒ Object
Method to maximize browser
62 63 64 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 62 def maximize_browser $driver.manage.window.maximize end |
#mouse_down(element) ⇒ Object
mouse_down
78 79 80 81 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 78 def mouse_down(element) element = find_object(element) $driver.action.move_to_element(element).click_and_hold.perform end |
#mouse_down_at(element, location) ⇒ Object
mouse_down_at
84 85 86 87 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 84 def mouse_down_at(element, location) element = find_object(element) $driver.action.move_to_element(element).click_and_hold.perform end |
#mouse_move_at ⇒ Object
mouse_move_at
108 109 110 111 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 108 def mouse_move_at element = find_object(element) $driver.action.move_to_element(element).perform end |
#mouse_out ⇒ Object
mouse_out
90 91 92 93 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 90 def mouse_out element = $driver.find_element(By.CSS_SELECTOR, 'body') $driver.action.move_to_element(element, 0, 0).perform end |
#mouse_over(element) ⇒ Object
Method to hover on element
72 73 74 75 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 72 def mouse_over(element) element = find_object(element) $driver.action.move_to_element(element).perform end |
#mouse_up(element) ⇒ Object
mouse_up
96 97 98 99 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 96 def mouse_up(element) element = find_object(element) $driver.action.move_to_element(element).release.perform end |
#mouse_up_at ⇒ Object
mouse_up_at
102 103 104 105 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 102 def mouse_up_at element = find_object(element) $driver.action.move_to_element(element).release.perform end |
#navigate(direction) ⇒ Object
method to navigate back & forward
9 10 11 12 13 14 15 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 9 def navigate(direction) if direction == 'back' $driver.navigate.back else $driver.navigate.forward end end |
#open(link) ⇒ Object
method to open link
4 5 6 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 4 def open(link) $driver.get link end |
#pause(time) ⇒ Object
3 4 5 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 3 def pause(time) sleep time.to_i end |
#print_congifugartion ⇒ Object
method to print configuration
4 5 6 7 8 9 10 11 12 13 14 |
# 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 |
#print_desktop_configuration ⇒ Object
method to print desktop configuration
17 18 19 20 21 |
# 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_android(browser_type, app_path) ⇒ Object
print error for android
29 30 31 32 33 34 35 36 37 38 39 40 |
# 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_android_app ⇒ Object
print error for android app
43 44 45 46 |
# 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_android_web ⇒ Object
print error for android web
49 50 51 52 53 |
# 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_desktop ⇒ Object
print error for desktop
20 21 22 23 24 25 26 |
# 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_ios ⇒ Object
print error for ios
56 57 58 59 60 61 62 63 64 65 66 67 |
# 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_ios_app ⇒ Object
print error for ios app
70 71 72 73 |
# 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_ios_web ⇒ Object
print error for ios web
76 77 78 79 |
# 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 |
#print_error_object_repository ⇒ Object
89 90 91 92 93 |
# 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_invalid_platform ⇒ Object
print error if invalid platform
82 83 84 85 86 87 |
# 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 |
#print_mobile_configuration ⇒ Object
method to print mobile configuration
24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
#quit ⇒ Object
method to quite webdriver instance
22 23 24 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 22 def quit $driver.quit end |
#refresh_page ⇒ Object
Method to refresh page
67 68 69 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 67 def refresh_page $driver.navigate.refresh end |
#remove_selection ⇒ Object
84 85 86 87 |
# File 'lib/itms_automation/methods/input_methods.rb', line 84 def remove_selection found_element = find_object(element) found_element.find_element(:xpath, "//option[. = '#{label}']").click end |
#scroll_page(to) ⇒ Object
method to scroll page to top or end
120 121 122 123 124 125 126 127 128 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 120 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) ⇒ Object
Method to scroll page to perticular element
114 115 116 117 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 114 def scroll_to_element(element) ele_scroll = find_object(element) ele_scroll.location_once_scrolled_into_view end |
#select ⇒ Object
89 90 91 92 |
# File 'lib/itms_automation/methods/input_methods.rb', line 89 def select found_element = find_object(element) found_element.find_element(:xpath, "//option[. = '#{label}']").click end |
#select_all_option_from_multiselect_dropdown(element) ⇒ Object
method to select all option from dropdwon list
29 30 31 32 33 |
# File 'lib/itms_automation/methods/input_methods.rb', line 29 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) ⇒ Object
111 112 |
# File 'lib/itms_automation/methods/input_methods.rb', line 111 def select_frame(element) end |
#select_option_from_dropdown(element, by, option) ⇒ Object
method to select option from dropdwon list
22 23 24 25 26 |
# File 'lib/itms_automation/methods/input_methods.rb', line 22 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) ⇒ Object
method to select option from radio button group
66 67 68 69 70 71 72 |
# File 'lib/itms_automation/methods/input_methods.rb', line 66 def (element, by, option) = WAIT.until { find_object(element) } getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text } ele = .find { |rb| getter.call(rb, by) == option } ele.click unless ele.selected? end |
#select_radio_button(element) ⇒ Object
method to select radio button
60 61 62 63 |
# File 'lib/itms_automation/methods/input_methods.rb', line 60 def (element) = WAIT.until { find_object(element) } .click unless .selected? end |
#select_window(element) ⇒ Object
108 109 |
# File 'lib/itms_automation/methods/input_methods.rb', line 108 def select_window(element) end |
#send_keys(element, key) ⇒ Object
method to send keys
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/itms_automation/methods/input_methods.rb', line 10 def send_keys(element, 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 key get_key = key.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) ⇒ Object
Method to resize browser
55 56 57 58 59 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 55 def set_window_size(resolution) raise TestCaseFailed, 'Wrong format of resolution. (e.g., 1280x800)' unless resolution.match(/^\d+x\d+$/) width, height = resolution.split("x") $driver.manage.resize_to(width, heigth) end |
#store(var_name, value) ⇒ Object
5 6 7 |
# File 'lib/itms_automation/methods/store_methods.rb', line 5 def store(var_name, value) $vars[var_name] = value end |
#store_attribute(element, attribute, var_name) ⇒ Object
32 33 34 35 36 |
# File 'lib/itms_automation/methods/store_methods.rb', line 32 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) ⇒ Object
9 10 11 |
# File 'lib/itms_automation/methods/store_methods.rb', line 9 def store_json(var_name, value) $vars[var_name] = JSON.parse(value) end |
#store_text(element, var_name) ⇒ Object
13 14 15 16 17 |
# File 'lib/itms_automation/methods/store_methods.rb', line 13 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) ⇒ Object
19 20 21 |
# File 'lib/itms_automation/methods/store_methods.rb', line 19 def store_title(var_name) $vars[var_name] = $driver.title end |
#store_window_handle(var_name) ⇒ Object
28 29 30 |
# File 'lib/itms_automation/methods/store_methods.rb', line 28 def store_window_handle(var_name) $vars[var_name] = $driver.window_handle end |
#store_xpath_count(element, var_name) ⇒ Object
23 24 25 26 |
# File 'lib/itms_automation/methods/store_methods.rb', line 23 def store_xpath_count(element, var_name) found_element = find_object(element) $vars[var_name] = found_element.length end |
#take_screenshot ⇒ Object
3 4 5 6 |
# 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) ⇒ Object
method to toggle checkbox checked
55 56 57 |
# File 'lib/itms_automation/methods/input_methods.rb', line 55 def toggle_checkbox(element) find_object(element).click end |
#type(element, text) ⇒ Object
method to enter text into textfield
4 5 6 7 |
# 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) ⇒ Object
method to uncheck checkbox
49 50 51 52 |
# File 'lib/itms_automation/methods/input_methods.rb', line 49 def uncheck(element) checkbox = find_object(element) checkbox.click if checkbox.selected? end |
#unselect_all_option_from_multiselect_dropdown(element) ⇒ Object
method to unselect all option from dropdwon list
36 37 38 39 40 |
# File 'lib/itms_automation/methods/input_methods.rb', line 36 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) ⇒ Boolean
method to validate locator
11 12 13 |
# 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) ⇒ Boolean
method to validate dropdown selector
20 21 22 |
# 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) ⇒ Object
15 16 17 |
# 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) ⇒ Object
24 25 26 |
# 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) ⇒ Object
Method to check browser type
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
#wait_for_element_editable(element, duration) ⇒ Object
7 8 9 10 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 7 def wait_for_element_editable(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000) wait.until { find_object(element).enabled? } end |
#wait_for_element_not_editable(element, duration) ⇒ Object
12 13 14 15 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 12 def wait_for_element_not_editable(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000) wait.until { !find_object(element).enabled? } end |
#wait_for_element_not_present(element, duration) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 17 def wait_for_element_not_present(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.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) ⇒ Object
28 29 30 31 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 28 def wait_for_element_not_visible(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000) wait.until { !find_object(element).displayed? } end |
#wait_for_element_present(element, duration) ⇒ Object
43 44 45 46 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 43 def wait_for_element_present(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000) wait.until { find_object(element) } end |
#wait_for_element_visible(element, duration) ⇒ Object
38 39 40 41 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 38 def wait_for_element_visible(element, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i / 1000) wait.until { find_object(element).displayed? } end |
#wait_for_text(element, text) ⇒ Object
33 34 35 36 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 33 def wait_for_text(element, text) wait = Selenium::WebDriver::Wait.new(:timeout => 30) wait.until { find_object(element).text == text } end |
#webdriver_answer_on_visible_prompt ⇒ Object
66 67 68 69 70 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 66 def webdriver_answer_on_visible_prompt alert = $driver.switch_to.alert alert.send_keys(answer) alert.accept() end |
#webdriver_choose_cancel_on_visible_confirmation ⇒ Object
72 73 74 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 72 def webdriver_choose_cancel_on_visible_confirmation $driver.switch_to.alert.dismiss end |
#webdriver_choose_cancel_on_visible_prompt ⇒ Object
80 81 82 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 80 def webdriver_choose_cancel_on_visible_prompt $driver.switch_to.alert.dismiss end |
#webdriver_choose_ok_on_visible_confirmation ⇒ Object
76 77 78 |
# File 'lib/itms_automation/methods/progress_methods.rb', line 76 def webdriver_choose_ok_on_visible_confirmation $driver.switch_to.alert.accept end |
#while(condition_script) ⇒ Object
11 12 13 |
# File 'lib/itms_automation/methods/condition_methods.rb', line 11 def while(condition_script) return $driver.execute_script(condition_script) end |
#zoom_in_out(in_out) ⇒ Object
Method to zoom in/out page
39 40 41 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 39 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) ⇒ Object
Method to zoom in/out web page until web element dislays
44 45 46 47 48 49 50 51 52 |
# File 'lib/itms_automation/methods/navigate_methods.rb', line 44 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 |