diff --git a/features-skeleton/support/env.rb b/features-skeleton/support/env.rb index 85e842d..9ed6741 100644 --- a/features-skeleton/support/env.rb +++ b/features-skeleton/support/env.rb @@ -8,6 +8,7 @@ $device_name = ENV['DEVICE_NAME'] $udid = ENV['UDID'] $app_path = ENV['APP_PATH'] +$lookup_table = YAML.load(File.open(File.join(File.dirname(__FILE__), '../variables.yaml'))) # check for valid parameters validate_parameters $platform, $browser_type, $app_path diff --git a/features-skeleton/variables.yaml b/features-skeleton/variables.yaml new file mode 100644 index 0000000..a902d38 --- /dev/null +++ b/features-skeleton/variables.yaml @@ -0,0 +1,2 @@ +--- +'name1': "locator1" diff --git a/lib/selenium-cucumber/methods/assertion_methods.rb b/lib/selenium-cucumber/methods/assertion_methods.rb index 17001d3..bcccf37 100644 --- a/lib/selenium-cucumber/methods/assertion_methods.rb +++ b/lib/selenium-cucumber/methods/assertion_methods.rb @@ -38,7 +38,7 @@ def check_partial_title(partial_text_title, test_case) # param 1 : String : Locator type (id, name, class, xpath, css) # param 2 : String : Locator value def get_element_text(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").text + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").text end # Method to check element text @@ -49,9 +49,9 @@ def get_element_text(access_type, access_name) def check_element_text(access_type, expected_value, access_name, test_case) element_text = get_element_text(access_type, access_name) if test_case - expect(element_text).to eq expected_value + expect(element_text).to eq lookup(expected_value) else - expect(element_text).to_not eq expected_value + expect(element_text).to_not eq lookup(expected_value) end end @@ -64,9 +64,9 @@ def check_element_partial_text(access_type, expected_value, access_name, test_ca element_text = get_element_text(access_type, access_name) if test_case - expect(element_text).to include(expected_value) + expect(element_text).to include("#{lookup(expected_value)}") else - expect(element_text).to_not include(expected_value) + expect(element_text).to_not include("#{lookup(expected_value)}") end end @@ -74,7 +74,7 @@ def check_element_partial_text(access_type, expected_value, access_name, test_ca # param 1 : String : Locator type (id, name, class, xpath, css) # param 2 : String : Locator value def is_element_enabled(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").enabled? + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").enabled? end # Element enabled checking @@ -95,7 +95,7 @@ def check_element_enable(access_type, access_name, test_case) # param 2 : String : Expected element text # param 3 : String : atrribute name def get_element_attribute(access_type, access_name, attribute_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").attribute("#{attribute_name}") + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").attribute("#{attribute_name}") end # method to check attribute value @@ -120,7 +120,7 @@ def check_element_attribute(access_type, attribute_name, attribute_value, access # param 2 : String : Locator value def is_element_displayed(access_type, access_name) begin - $driver.find_element(:"#{access_type}" => "#{access_name}").displayed? + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").displayed? rescue Selenium::WebDriver::Error::NoSuchElementError # elements not found return false false @@ -140,7 +140,7 @@ def check_element_presence(access_type, access_name, test_case) # param 2 : String : Locator value # param 3 : Boolean : test case [true or flase] def is_checkbox_checked(access_type, access_name, should_be_checked = true) - checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}") + checkbox = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") expect(checkbox.selected?).to be should_be_checked end @@ -150,13 +150,13 @@ def is_checkbox_checked(access_type, access_name, should_be_checked = true) # param 2 : String : Locator value # param 3 : Boolean : test case [true or flase] def is_radio_button_selected(access_type, access_name, should_be_selected = true) - radio_button = $driver.find_element(:"#{access_type}" => "#{access_name}") + radio_button = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") expect(radio_button.selected?).to be should_be_selected end # method to assert option from radio button group is selected/unselected def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected = true) - radio_button_group = $driver.find_elements(:"#{access_type}" => "#{access_name}") + radio_button_group = $driver.find_elements(:"#{access_type}" => "#{lookup(access_name)}") getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text } @@ -176,7 +176,7 @@ def check_alert_text(text) end def is_option_from_dropdown_selected(access_type, by, option, access_name, should_be_selected=true) - dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}") + dropdown = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") select_list = Selenium::WebDriver::Support::Select.new(dropdown) if by == 'text' diff --git a/lib/selenium-cucumber/methods/click_elements_methods.rb b/lib/selenium-cucumber/methods/click_elements_methods.rb index 0ae219d..3605696 100644 --- a/lib/selenium-cucumber/methods/click_elements_methods.rb +++ b/lib/selenium-cucumber/methods/click_elements_methods.rb @@ -1,7 +1,7 @@ require_relative 'required_files' def click(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").click + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").click end def click_by_text(access_type, access_name, text) @@ -11,7 +11,7 @@ def click_by_text(access_type, access_name, text) raise "Text '#{text}' was not found in the page source" unless text_found # enter loop if the text is found if text_found - elements = $driver.find_elements(:"#{access_type}" => "#{access_name}") + elements = $driver.find_elements(:"#{access_type}" => "#{lookup(access_name)}") elements.each do |element| if element.text == text element_found = true @@ -24,7 +24,7 @@ def click_by_text(access_type, access_name, text) end def click_forcefully(access_type, access_name) - $driver.execute_script('arguments[0].click();', $driver.find_element(:"#{access_type}" => "#{access_name}")) + $driver.execute_script('arguments[0].click();', $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}")) end def double_click(access_type, access_value) @@ -33,7 +33,7 @@ def double_click(access_type, access_value) end def submit(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").submit + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").submit end diff --git a/lib/selenium-cucumber/methods/input_methods.rb b/lib/selenium-cucumber/methods/input_methods.rb index 1eed69c..1023e5c 100644 --- a/lib/selenium-cucumber/methods/input_methods.rb +++ b/lib/selenium-cucumber/methods/input_methods.rb @@ -2,44 +2,44 @@ # method to enter text into textfield def enter_text(access_type, text, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").send_keys text + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").send_keys lookup(text) end # method to clear text from textfield def clear_text(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").clear + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").clear end # method to select option from dropdwon list def select_option_from_dropdown(access_type, by, option, access_name) - dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}") + dropdown = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") select_list = Selenium::WebDriver::Support::Select.new(dropdown) select_list.select_by(:"#{by}", "#{option}") end # method to select all option from dropdwon list def select_all_option_from_multiselect_dropdown(access_type, access_name) - dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}") + dropdown = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") select_list = Selenium::WebDriver::Support::Select.new(dropdown) select_list.select_all end # method to unselect all option from dropdwon list def unselect_all_option_from_multiselect_dropdown(access_type, access_name) - dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}") + dropdown = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") select_list = Selenium::WebDriver::Support::Select.new(dropdown) select_list.deselect_all end # method to check checkbox def check_checkbox(access_type, access_name) - checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}") + checkbox = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") checkbox.click unless checkbox.selected? end # method to uncheck checkbox def uncheck_checkbox(access_type, access_name) - checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}") + checkbox = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") if checkbox.selected? checkbox.click @@ -48,18 +48,18 @@ def uncheck_checkbox(access_type, access_name) # method to select radio button def toggle_checkbox(access_type, access_name) - $driver.find_element(:"#{access_type}" => "#{access_name}").click + $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").click end # method to select radio button def select_radio_button(access_type, access_name) - radio_button = $driver.find_element(:"#{access_type}" => "#{access_name}") + radio_button = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") radio_button.click unless radio_button.selected? end # method to select option from radio button group def select_option_from_radio_button_group(access_type, by, option, access_name) - radio_button_group = $driver.find_elements(:"#{access_type}" => "#{access_name}") + radio_button_group = $driver.find_elements(:"#{access_type}" => "#{lookup(access_name)}") getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text } ele = radio_button_group.find { |rb| getter.call(rb, by) == option } diff --git a/lib/selenium-cucumber/methods/misc_methods.rb b/lib/selenium-cucumber/methods/misc_methods.rb index c00b97a..638c0d7 100644 --- a/lib/selenium-cucumber/methods/misc_methods.rb +++ b/lib/selenium-cucumber/methods/misc_methods.rb @@ -32,3 +32,7 @@ def get_device_info IO.popen('adb shell getprop ro.build.version.release') { |f| $os_version = f.gets.chomp.upcase} return $device, $os_version end + +def lookup(key) + $lookup_table[key] || key +end diff --git a/lib/selenium-cucumber/methods/mobile_methods.rb b/lib/selenium-cucumber/methods/mobile_methods.rb index 3f9bd9b..99b3b2d 100644 --- a/lib/selenium-cucumber/methods/mobile_methods.rb +++ b/lib/selenium-cucumber/methods/mobile_methods.rb @@ -53,11 +53,11 @@ def swipe_direction(direction) end def swipe_element_with_direction(access_type, access_name, direction) - ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.location + ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") }.location x_start = ele_from.x y_start = ele_from.y - ele_size = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") } + ele_size = WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") } ele_height = ele_size.size.height.to_i ele_width = ele_size.size.width.to_i #puts ele_size.width @@ -148,7 +148,7 @@ def swipe_element_with_direction(access_type, access_name, direction) def swipe_coordinates_with_direction(start_x, start_y, direction) - # ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.size + # ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") }.size # height = size.height.to_i - 5 # puts "height : #{height}" # 1776 # width = size.width.to_i - 5 @@ -190,7 +190,7 @@ def swipe_coordinates_with_direction(start_x, start_y, direction) def long_press_on_element_default_duration(access_type, access_name) begin - ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.location + ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") }.location x = ele_from.x y = ele_from.y @@ -207,7 +207,7 @@ def long_press_on_element_default_duration(access_type, access_name) def long_press_on_element_with_duration(access_type, access_name, duration) begin - ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.location + ele_from = WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") }.location x = ele_from.x y = ele_from.y diff --git a/lib/selenium-cucumber/methods/navigate_methods.rb b/lib/selenium-cucumber/methods/navigate_methods.rb index d8c9a24..88c69e6 100644 --- a/lib/selenium-cucumber/methods/navigate_methods.rb +++ b/lib/selenium-cucumber/methods/navigate_methods.rb @@ -2,7 +2,7 @@ # method to open link def navigate_to(link) - $driver.get link + $driver.get lookup(link) end # method to navigate back & forword @@ -61,7 +61,7 @@ def zoom_in_out(operation) # Method to zoom in/out web page until web element displyas def zoom_in_out_till_element_display(access_type, operation, access_name) while true - if WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.displayed? + if WAIT.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") }.displayed? break else zoom_in_out(operation) @@ -81,13 +81,13 @@ def maximize_browser # Method to hover on element def hover_over_element(access_type, access_name) - element = $driver.find_element(:"#{access_type}" => "#{access_name}") + element = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") $driver.action.move_to(element).perform end # Method to scroll page to perticular element def scroll_to_element(access_type, access_name) - ele_scroll = $driver.find_element(:"#{access_type}" => "#{access_name}") + ele_scroll = $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}") ele_scroll.location_once_scrolled_into_view end diff --git a/lib/selenium-cucumber/methods/progress_methods.rb b/lib/selenium-cucumber/methods/progress_methods.rb index 1a2d1db..4a53c9b 100644 --- a/lib/selenium-cucumber/methods/progress_methods.rb +++ b/lib/selenium-cucumber/methods/progress_methods.rb @@ -6,10 +6,10 @@ def wait(time) def wait_for_element_to_display(access_type, access_name, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds - wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").displayed? } + wait.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").displayed? } end def wait_for_element_to_enable(access_type, access_name, duration) wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds - wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").enabled? } + wait.until { $driver.find_element(:"#{access_type}" => "#{lookup(access_name)}").enabled? } end