class Object
Public Instance Methods
accept_alert()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 143 def accept_alert begin page.driver.browser.switch_to.alert.accept rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end end
assert_string_contain(expected, actual)
click to toggle source
# File lib/Ifd_Automation/assertion_helper.rb, line 82 def assert_string_contain(expected, actual) unless (actual.to_s).include? (expected.to_s) raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.") end end
assert_string_equal(expected, actual)
click to toggle source
# File lib/Ifd_Automation/assertion_helper.rb, line 88 def assert_string_equal(expected, actual) if expected.to_s != actual.to_s raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.") end end
assert_string_not_equal(expected, actual)
click to toggle source
# File lib/Ifd_Automation/assertion_helper.rb, line 94 def assert_string_not_equal(expected, actual) if expected.to_s == actual.to_s raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.") end end
back()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 152 def back begin page.execute_script('window.history.back()') rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end end
bind_with_dyn_json_vars(json, bind_json)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 62 def bind_with_dyn_json_vars(json, bind_json) if json.kind_of? Hash json.each_pair do |k, v| if v.kind_of? String bind_json[bind_with_dyn_vars(k)] = bind_with_dyn_json_vars(v, bind_json) elsif v.kind_of? Hash temp = Hash.new v.each_pair do |k1, v1| temp[bind_with_dyn_vars(k1)] = bind_with_dyn_json_vars(v1, temp) end bind_json[bind_with_dyn_vars(k)] = temp elsif v.kind_of? Array temp1 = Array.new v.each { |item| temp2 = Hash.new bind_with_dyn_json_vars(item, temp2) temp1 << temp2 } bind_json[bind_with_dyn_vars(k)] = temp1 end end elsif json.kind_of? Array temp1 = Array.new json.each { |item| temp2 = Hash.new bind_with_dyn_json_vars(item, temp2) temp1 << temp2 } return temp1 else return bind_with_dyn_vars(json) end end
bind_with_dyn_vars(str)
click to toggle source
bind string with $dyn_vars context
# File lib/Ifd_Automation/auto_util.rb, line 44 def bind_with_dyn_vars(str) if $dyn_vars == nil $dyn_vars = binding end strEval = '"' + str + '"' return eval strEval, $dyn_vars end
check_dynamic_value(value)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 16 def check_dynamic_value value if !value.is_a? Fixnum if value.include? "params=" resolve_params value else bind_with_dyn_vars value end else value end end
check_string_letters_only(strToCheck)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 669 def check_string_letters_only(strToCheck) if strToCheck != nil and strToCheck.length > 0 and strToCheck =~ /^[a-zA-Z]+$/ return true end return false end
check_valid_keys?(key)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 479 def check_valid_keys?(key) %w(:cancel :help :backspace :tab :clear :return :enter :shift :control :alt :pause :escape :space :page_up :page_down :end :home :left :up :right :down :insert :delete :semicolon :equals).include? key end
check_valid_option_by?(option_by)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 471 def check_valid_option_by?(option_by) %w(text value).include? option_by end
clear_text(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 170 def clear_text(element) foundElement = find_object(element) if foundElement != nil? begin foundElement.native.clear rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
close_windows()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 259 def close_windows begin page.execute_script "window.close();" rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
do_assertion_csv_tab_non_order(expected_obj, actual_obj)
click to toggle source
Assert two files, rows not in order and REMOVE 1 COLUMN OF ID
# File lib/Ifd_Automation/assertion_helper.rb, line 2 def do_assertion_csv_tab_non_order(expected_obj, actual_obj) for i in (1..expected_obj.length - 1) expected_row = expected_obj[i].drop(1).to_s.split("\t") found = false for j in (1..actual_obj.length - 1) actual_row = actual_obj[j].drop(1).to_s.split("\t") if (expected_row == actual_row) found = true break end end assert(found, "Expected Record: [#{expected_obj[i].to_s}] is not included in reporting file") end end
do_assertion_json(expected_obj, actual_obj, options = {})
click to toggle source
# File lib/Ifd_Automation/assertion_helper.rb, line 48 def do_assertion_json(expected_obj, actual_obj, options = {}) # puts "\n\n actual_obj.class: #{actual_obj.class}" # puts "\n\n expected_obj.class: #{expected_obj.class}" if expected_obj.kind_of? Hash # if options['isIncludedAssertion'].nil? or options['isIncludedAssertion'] == false # do_assertion(expected_obj.keys.size, actual_obj.keys.size) # end expected_obj.keys.each do |key| # puts "\n\n key: #{key}" # puts "\n\n value: #{expected_obj[key]}" # puts "\n\n value: #{actual_obj[key]}" if actual_obj[key].nil? raise "[%s] expected [%s] but actual value was nil." % [key, expected_obj[key].to_s] else do_assertion_json(expected_obj[key], actual_obj[key], options) end end elsif expected_obj.kind_of? Array if options['isIncludedAssertion'].nil? or options['isIncludedAssertion'] == false do_assertion_json(expected_obj.size, actual_obj.size) end for i in (0..expected_obj.length-1) do_assertion_json(expected_obj[i], actual_obj[i], options) end else begin assert_string_equal(expected_obj.to_s, actual_obj.to_s) rescue => e raise("Assert fail. \n\n Expected: '#{expected_obj}' \n\n Got: '#{actual_obj}'. Detail info: #{e.message}") end end end
double_click(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 49 def double_click(element) foundElement = find_object(element) if foundElement != nil begin foundElement.double_click rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
drag_and_drop_by_offset(element, x, y)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 1004 def drag_and_drop_by_offset(element, x, y) foundElement = find_object(element) if foundElement != nil begin page.driver.browser.action.drag_and_drop_by(foundElement, x, y).perform rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
drag_and_drop_to_object(from_element, element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 1019 def drag_and_drop_to_object(from_element, element) found_from_element = find_object(from_element) foundElement = find_object(element) if foundElement != nil and found_from_element != nil found_from_element.drag_to(foundElement) end end
eval_with_dyn_vars(operation)
click to toggle source
evaluate operation/statement with $dyn_vars context
# File lib/Ifd_Automation/auto_util.rb, line 54 def eval_with_dyn_vars(operation) if $dyn_vars == nil $dyn_vars = binding end eval operation, $dyn_vars end
execute_checkproperty(element, property, negate, value, isSpecialChar=false)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 419 def execute_checkproperty(element, property, negate, value, isSpecialChar=false) validate_option_by(property) Capybara.configure do |config| config.ignore_hidden_elements = false end foundElement = find_object(element) check = false if foundElement == nil and value == "" check = true # check.should eq true expect(check).to eq true else # put_log "\n\n\t>>> execute_checkproperty: finish to found element" if foundElement != nil if property.upcase == 'VALUE' actual_value = foundElement.value() elsif property.upcase == 'TEXT' actual_value = foundElement.text() else actual_value = foundElement["#{property}"] end if actual_value == nil actual_value = '' end else put_log "❌ Error: Not found object: #{element}" end Capybara.configure do |config| config.ignore_hidden_elements = true end # if IFD_Assertion.reg_compare(actual_value, value, isSpecialChar) # check = true # end put_log "\n#{property} :: Actual result is: '#{actual_value}' -- Expected result is: '#{value}'" if negate == " not" actual_value.should_not eq value expect(actual_value).not_to eql value elsif actual_value.should eq value expect(actual_value).to eq value end end end
execute_click(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 18 def execute_click(element) foundElement = find_object(element) if foundElement != nil begin foundElement.click rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error >> Not found object: #{element}" exit(1) end end
execute_click_offset(element, x, y)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 33 def execute_click_offset(element, x, y) foundElement = find_object(element) if foundElement != nil begin page.driver.browser.mouse.move_to(foundElement.native,x.to_i,y.to_i) page.driver.browser.mouse.click() rescue Exception => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_javascript(script)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 185 def execute_javascript(script) begin page.execute_script(script) rescue Exception => e puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_mouse_over(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 212 def execute_mouse_over(element) foundElement = find_object(element) if foundElement != nil begin page.driver.browser.action.move_to(foundElement.native, element).click.perform sleep(1) rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_openbrowser(url_site)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 5 def execute_openbrowser(url_site) begin if url_site == "" puts "❌ Error: Null web page URL." exit(1) end visit(url_site) rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
execute_select(element, text)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 194 def execute_select(element, text) #select(text, :xpath => element) foundElement = find_object(element) if foundElement != nil begin option_value = page.evaluate_script("$(\"##{foundElement[:id]} option:contains('#{text}')\").val()") page.execute_script("$('##{foundElement[:id]}').val('#{option_value}')") page.execute_script("$('##{foundElement[:id]}').trigger('liszt:updated').trigger('change')") rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_sendkeys(element, key)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 1027 def execute_sendkeys(element, key) validate_supported_keys(key) foundElement = find_object(element) if foundElement != nil begin foundElement.native.send_keys(key) rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_setstate(element, state)
click to toggle source
Set state
# File lib/Ifd_Automation/web_steps_helper.rb, line 245 def execute_setstate(element, state) foundElement = find_object(element) if foundElement != nil if state foundElement.select_option else foundElement.unselect_option end else puts "❌ Error: Not found object: #{element}" exit(1) end end
execute_settext(element, text)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 64 def execute_settext(element, text) foundElement = find_object(element) if foundElement != nil begin foundElement.set(text) rescue StandardError => e puts "❌ Error: #{e}" end else puts "❌ Error: Not found object: #{element}" exit(1) end end
find_object(string_object)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 487 def find_object string_object startTime = Time.new.to_i string_object = string_object.gsub(/"/, "'") locator_matching = /(.*?)(\{.*?\})/.match(string_object) dyn_pros = {} if locator_matching != nil string_object = locator_matching[1] eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v| dyn_pros[k.to_s.upcase] = v } end hash_object = $OBJECT[string_object] if hash_object == nil puts "❌ ERROR: >>> Object: #{string_object} is not found in Object Repository." exit(1) end upcase_attrb = {} if hash_object != nil hash_object.each {|k,v| k = k.to_s.upcase if k =~ /ph_/i if dyn_pros[k] != nil if v =~ /<ph_value>/i upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k]) else upcase_attrb[k[3..k.size-1]] = dyn_pros[k] end dyn_pros.delete(k) end else upcase_attrb[k.to_s.upcase] = v end } end ph_attrs = {} dyn_pros.each{|k,v| if k =~ /ph_/i ph_attrs[k] = v else upcase_attrb[k.to_s.upcase] = v end } if upcase_attrb.size > 0 strId = "" strClass = "" strName = "" strTagname = "" strCssSelector = "" strXpathSelector = "" strText = "" strRelated = "" strRelatedType = "" index = nil minWidth = -1 maxWidth = -1 minHeight = -1 maxHeight = -1 ano_pros = {} upcase_attrb.each{|key, value| upcase_key = key.to_s.upcase case upcase_key when "XPATH_SELECTOR" strXpathSelector = value when "CSS_SELECTOR" strCssSelector = value when "ID" strId = value when "CLASS" strClass = value when "NAME" strName = value when "TAGNAME" strTagname = value when "TEXT" strText = value when "INDEX" index = value else raise "ERROR: >>> Wrong format type: #{key.to_s} of object: #{string_object}. Available supported format are: XPATH_SELECTOR | CSS_SELECTOR | ID | NAME | CLASS | TEXT | TAGNAME | INDEX" end } continue_run = true; ref_object = nil; if strRelated != nil and strRelated.length > 0 ref_object = find_object(strRelated) if (ref_object == nil) continue_run = false end end if continue_run == true begin if strCssSelector != nil and strCssSelector.length > 0 foundElements = get_objects_by_css_selector(strCssSelector) elsif strXpathSelector != nil and strXpathSelector.length > 0 foundElements = get_objects_by_xpath_selector(strXpathSelector) else strGenerateXpathSel = generate_xpath_selector(strId, strClass, strName, strTagname) if strGenerateXpathSel.length > 0 foundElements = get_objects_by_xpath_selector(strGenerateXpathSel) else if (check_string_letters_only(strId)) foundElements = get_objects_by_Id(strId) elsif (check_string_letters_only(strName)) foundElements = get_objects_by_Name(strName) elsif (check_string_letters_only(strClass)) foundElements = get_objects_by_Class(strClass) elsif (check_string_letters_only(strTagname)) foundElements = get_objects_by_Tagname(strTagname) end end end if foundElements == nil or foundElements.length == 0 currentTime = Time.new.to_i else break end test = currentTime - startTime puts "\n Finding the object #{string_object}... TIME-OUT:: #{test} < #{$wait_time}" sleep(0.5) end while (currentTime - startTime) < $wait_time if foundElements != nil or foundElements.length != 0 if index != nil and index.to_i >= 0 matched_index = 0; return_element = nil foundElements.each{|cur_element| passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros) if passCheck if matched_index == index.to_i return_element = cur_element break else matched_index = matched_index + 1 end end } return return_element else return_element = nil foundElements.each{|cur_element| passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros) if passCheck return_element = cur_element break end } return return_element end # if index != nil and index.to_i >= 0 end #if foundElements != nil or foundElements.length != 0 end #if continue = true end return nil end
find_object_check_Class(element, strClass)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 856 def find_object_check_Class(element, strClass) actual_Class = element[:class] if actual_Class != nil and actual_Class.length > 0 actual_Class = actual_Class.strip if reg_compare(actual_Class, strClass) return true end end return false end
find_object_check_Id(element, strId)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 845 def find_object_check_Id(element, strId) actual_Id = element[:id] if actual_Id != nil and actual_Id.length > 0 actual_Id = actual_Id.strip if reg_compare(actual_Id, strId) return true end end return false end
find_object_check_Name(element, strName)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 867 def find_object_check_Name(element, strName) actual_Name = element[:name] if actual_Name != nil and actual_Name.length > 0 actual_Name = actual_Name.strip if reg_compare(actual_Name, strName) return true end end return false end
find_object_check_Tagname(element, strTagname)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 879 def find_object_check_Tagname(element, strTagname) actual_Tagname = element.tag_name() if actual_Tagname != nil and actual_Tagname.length > 0 actual_Tagname = actual_Tagname.strip if reg_compare(actual_Tagname, strTagname) return true end end return false end
find_object_check_Text(element, strText)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 893 def find_object_check_Text(element, strText) actual_Text = element.text() if actual_Text != nil and actual_Text.length > 0 actual_Text = actual_Text.strip if reg_compare(actual_Text, strText) return true end end return false end
find_object_check_Xpath(element, strXpath)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 890 def find_object_check_Xpath(element, strXpath) end
find_object_check_maxHeight(element, maxHeight)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 928 def find_object_check_maxHeight(element, maxHeight) height = element[:height] if (height <= maxHeight) return true end return false end
find_object_check_maxWidth(element, maxWidth)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 912 def find_object_check_maxWidth(element, maxWidth) width = element[:width] if (width <= maxWidth) return true end return false end
find_object_check_minHeight(element, minHeight)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 920 def find_object_check_minHeight(element, minHeight) height = element[:height] if (height <= minHeight) return true end return false end
find_object_check_minWidth(element, minWidth)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 904 def find_object_check_minWidth(element, minWidth) width = element[:width] if (width >= minWidth) return true end return false end
find_object_check_object(cur_element, ref_object, ref_object_type, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 740 def find_object_check_object(cur_element, ref_object, ref_object_type, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros) passCheck = true if cur_element != nil # Check ref_object if (ref_object != nil) if find_object_check_ref_object(ref_object, ref_object_type, cur_element) == false passCheck = false end end # Check ID if strId != nil and strId.length > 0 if strId =~ /^#/ strId = strId[1..-1] end if find_object_check_Id(cur_element, strId) == false passCheck = false end end # Check Class if passCheck and strClass != nil and strClass.length > 0 if strClass =~ /^#/ strClass = strClass[1..-1] end if find_object_check_Class(cur_element, strClass) == false passCheck = false end end # Check Name if passCheck and strName != nil and strName.length > 0 if strName =~ /^#/ strName = strName[1..-1] end if find_object_check_Name(cur_element, strName) == false passCheck = false end end # Check Tag name if passCheck and strTagname != nil and strTagname.length > 0 if find_object_check_Tagname(cur_element, strTagname) == false passCheck = false end end # Check Text if passCheck and strText != nil and strText.length > 0 if (strText =~ /^#/) strText = strText[1..-1] end if find_object_check_Text(cur_element, strText) == false passCheck = false end end # Check minWidth if passCheck and minWidth > 0 if !find_object_check_minWidth(cur_element, minWidth) passCheck = false end end # Check maxWidth if passCheck and maxWidth > 0 if !find_object_check_maxWidth(cur_element, maxWidth) passCheck = false end end # Check minHeight if passCheck and minHeight > 0 if !find_object_check_minHeight(cur_element, minHeight) passCheck = false end end # Check maxHeight if passCheck and maxHeight > 0 if !find_object_check_maxHeight(cur_element, maxHeight) passCheck = false end end # Check another properties if passCheck and ano_pros.length > 0 ano_pros.each{|property, value| if value =~ /^#/ value = value[1..-1] end if !find_object_check_property(cur_element, property, value) passCheck = false break end } end return passCheck end return false end
find_object_check_ref_object(ref_object, ref_type, target_element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 937 def find_object_check_ref_object(ref_object, ref_type, target_element) begin ref = ref_object.native target = target_element.native if(ref_type == "up" or ref_type == "down") ref_x1 = ref.location.x - 10 ref_x2 = ref.location.x + ref.size.width + 10 target_x1 = target.location.x target_x2 = target_x1 + target.size.width elsif(ref_type == "left" or ref_type == "right") ref_y1 = ref.location.y - 10 ref_y2 = ref.location.y + ref_object.native.size.height + 10 target_y1 = target.location.y target_y2 = target_y1 + target.size.height elsif(ref_type == "child" or ref_type == "parent") ref_W = ref.location.x + ref.size.width ref_H = ref.location.y + ref.size.height target_W = target.location.x + target.size.width target_H = target.location.y + target.size.height end if(ref_type == "up" and target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position target.location.y < ref.location.y) # at row or Y position, target is upper return true elsif(ref_type == "down" and target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position target.location.y > ref.location.y) # at row or Y position, target is at down return true elsif(ref_type == "left" and target.location.x < ref.location.x and # at column or X Position, target is at left target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object return true elsif(ref_type == "right" and target.location.x > ref.location.x and # at column or X Position, target is at right target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object return true elsif(ref_type == "child" and (target_W < ref_W) and (target_H < ref_H) and (target.location.x > ref.location.x) and (target.location.y > ref.location.y)) return true elsif(ref_type == "parent" and (target_W > ref_W) and (target_H > ref_H) and (target.location.x < ref.location.x) and (target.location.y < ref.location.y)) return true end rescue StandardError => e puts "❌ Error: #{e}" end return false; end
generate_xpath_selector(strId, strClass, strName, strTagname)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 646 def generate_xpath_selector(strId, strClass, strName, strTagname) strGenerateXpathSel = "" if strId != nil and strId.length > 0 and (strId =~ /^#/) == nil strGenerateXpathSel = "[@id='#{strId}']" end if strClass != nil and strClass.length > 0 and (strClass =~ /^#/) == nil strGenerateXpathSel = "#{strGenerateXpathSel}[@class='#{strClass}']" end if strName != nil and strName.length > 0 and (strName =~ /^#/) == nil strGenerateXpathSel = "#{strGenerateXpathSel}[@name='#{strName}']" end if strGenerateXpathSel.length > 0 if strTagname != nil and strTagname.length > 0 strGenerateXpathSel = "//#{strTagname}#{strGenerateXpathSel}" else strGenerateXpathSel = "//*#{strGenerateXpathSel}" end end return strGenerateXpathSel end
get_computed_style(element, style)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 287 def get_computed_style(element, style) foundElement = get_object_value(element) computedStyle = "" if foundElement != nil computedStyle = page.evaluate_script("window.getComputedStyle(document.querySelector('#{foundElement}')).#{style}") else puts "❌ Error: Not found object: #{element}" exit(1) end puts "\nActual object style value is: #{computedStyle}" computedStyle end
get_element_attribute(element,value)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 334 def get_element_attribute(element,value) foundElement = find_object(element) if foundElement != nil begin result = foundElement.value() puts "Attribute of #{element}: #{result}" rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
get_element_text(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 318 def get_element_text(element) foundElement = find_object(element) if foundElement != nil begin result = foundElement.text() puts "Text of #{element}: #{result}" rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
get_object_and_store_as_string(object,string)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 990 def get_object_and_store_as_string(object,string) text = execute_gettext(object) txt = "'" + text + "'" set_var(string, txt) end
get_object_and_store_to_file(object,file_name)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 997 def get_object_and_store_to_file(object,file_name) $text = execute_gettext(object) open($test_data_dir+file_name, 'a+') do |f| f << $text + "\n" end end
get_object_value(str_obj)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 304 def get_object_value(str_obj) string_object = str_obj.gsub(/"/, "'") hash_object = $OBJECT[string_object] if hash_object == nil raise ">>> OBJECT: #{str_obj} NAME MAYBE NOT FOUND!!!" exit(1) end if hash_object.keys[0].to_s.upcase != "CSS_SELECTOR" raise ">>> OBJECT: #{str_obj} should be formatted as Css Selector." exit(1) end hash_object[hash_object.keys[0]] end
get_objects_by_Class(strClass)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 687 def get_objects_by_Class(strClass) foundElements = nil begin foundElements = page.all("*[@class='#{strClass}']") rescue StandardError => e puts "❌ Error: #{e}" end return foundElements end
get_objects_by_Id(strId)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 676 def get_objects_by_Id(strId) foundElements = nil begin foundElements = page.all("*[@id='#{strId}']") rescue StandardError => e puts "❌ Error: #{e}" end return foundElements end
get_objects_by_Name(strName)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 698 def get_objects_by_Name(strName) foundElements = nil begin foundElements = page.all("*[@name='#{strName}']") rescue StandardError => e puts "❌ Error: #{e}" end return foundElements end
get_objects_by_Tagname(strTagname)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 709 def get_objects_by_Tagname(strTagname) foundElements = nil begin foundElements = page.all("#{strTagname}") rescue StandardError => e puts "❌ Error: #{e}" end return foundElements end
get_objects_by_css_selector(strCssSelector)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 720 def get_objects_by_css_selector(strCssSelector) foundElements = nil begin foundElements = page.all(:css, strCssSelector) rescue StandardError => e puts "❌ Error: #{e}" end foundElements end
get_objects_by_xpath_selector(strXpathSelector)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 730 def get_objects_by_xpath_selector(strXpathSelector) foundElements = nil begin foundElements = page.all(:xpath, strXpathSelector) rescue StandardError => e puts "❌ Error: #{e}" end foundElements end
maximize_browser()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 78 def maximize_browser begin page.driver.browser.manage.window.maximize rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
movemouseandclick(var, element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 1043 def movemouseandclick var, element Selenium::WebDriver::Support::Select.new(page.driver.browser.find_element(:id, "#{var}")).select_by(:text, "#{element}") page.driver.browser.find_element(:id, "#{var}").click end
print_variable(variable)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 159 def print_variable(variable) puts "VALUE OF #{variable}: #{eval_with_dyn_vars(variable)}" end
put_log(str)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 300 def put_log str p str if $print_log == true end
refresh()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 161 def refresh begin page.execute_script('window.location.reload()') rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end end
reg_compare(sActual, regValue, isSpecialChar=false)
click to toggle source
Assert 2 values
# File lib/Ifd_Automation/assertion_helper.rb, line 18 def reg_compare sActual, regValue, isSpecialChar=false begin if !isSpecialChar sActual = sActual.strip regValue = regValue.strip.gsub("[", "\\[").gsub("]", "\\]").gsub("(", "\\(").gsub(")", "\\)").gsub(">", "\\>") end rescue StandardError => myStandardError puts "❌ ERROR #{myStandardError}" exit(1) end # put_log "\nsActual:#{sActual}, regValue:#{regValue}" if ((sActual.nil? and regValue.nil?) or (!sActual.nil? and sActual.empty? and !regValue.nil? and regValue.empty?)) return true end if ((sActual.nil? and !regValue.nil?) or (!sActual.nil? and regValue.nil?)) return false end if (!sActual.nil? and !sActual.empty?) sCookActual = sActual.gsub(/\n|\r/, " ") if (sCookActual == regValue or (isSpecialChar and sCookActual.include? regValue) or (!isSpecialChar and sCookActual =~ /^.*#{regValue}.*$/)) return true end end return false end
remove_element_attribute(element, attr)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 228 def remove_element_attribute(element, attr) foundElement = find_object(element) if foundElement != nil begin page.driver.browser.execute_script("arguments[0].removeAttribute('#{attr}');", foundElement.native) sleep(1) rescue StandardError => e puts "❌ Error: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
replace_day(str)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 133 def replace_day str t = Time.now() _day = t.day if _day < 10 return str.gsub("{day}", "0#{_day.to_s}") else return str.gsub("{day}", "#{_day.to_s}") end return str end
replace_month(str)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 122 def replace_month str t = Time.now() _month = t.month if _month < 10 return str.gsub("{month}", "0#{_month.to_s}") else return str.gsub("{month}", "#{_month.to_s}") end return str end
replace_pipe(str_pipe)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 144 def replace_pipe str_pipe put_log ">>>> #{str_pipe}" if str_pipe =~ /^.*{pipe}.*$/ return str_pipe.gsub("{pipe}", "|") end return str_pipe end
replace_year(str)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 117 def replace_year str t = Time.now() return str.gsub("{year}", t.year.to_s) end
resize_window_screen(x, y)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 268 def resize_window_screen(x, y) begin page.driver.browser.manage.window.resize_to(x, y) puts page.driver.browser.manage.window.size rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
resolve_params(url)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 29 def resolve_params url condition = url.match(/params='([^']*)'/)[0] if condition params_name = url.match(/params='([^']*)'/)[1] params_value = $PARAMS["#{params_name.downcase}"].to_s.strip if params_value.present? url = url.gsub(condition, params_value) else raise "ERROR: no data found with given params #{params_name}" end end url end
scroll_to_end_page()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 103 def scroll_to_end_page begin page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));') rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
scroll_to_top_page()
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 112 def scroll_to_top_page begin page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);') rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
set_var(var_name, var_value)
click to toggle source
set value to a variable
# File lib/Ifd_Automation/auto_util.rb, line 7 def set_var(var_name, var_value) if $dyn_vars == nil $dyn_vars = binding end strEval = var_name + "=" + var_value eval strEval, $dyn_vars end
store_string_as_variable(string,variable)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 152 def store_string_as_variable(string,variable) # $context_value = bind_with_dyn_vars(string) # set_var(variable, '$context_value') require 'erb' ERB.new(string, 0, "", "#{variable}").result(binding) end
switch_to_frame(element)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 278 def switch_to_frame(element) begin page.driver.browser.switch_to.frame element rescue Exception => e puts "❌ Error: #{e}" exit(1) end end
switch_to_window_by_title(window_title)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 87 def switch_to_window_by_title(window_title) $previous_window = page.driver.browser.window_handle @window_found = false page.driver.browser.window_handles.each { |handle| page.driver.browser.switch_to.window handle if page.title == window_title @window_found = true break end } if @window_found == false raise "Window having title \"#{window_title}\" not found" exit(1) end end
validate_option_by(option_by)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 475 def validate_option_by(option_by) raise "Please select valid option, invalid option - #{option_by}" unless check_valid_option_by? option_by end
validate_supported_keys(key)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 483 def validate_supported_keys(key) raise "Please select valid keys, invalid key - #{key}" unless check_valid_option_by? key end
var_collect(string_var)
click to toggle source
# File lib/Ifd_Automation/auto_util.rb, line 97 def var_collect string_var if string_var =~ /^.*{year}.*$/ string_var = replace_year(string_var) end if string_var =~ /^.*{month}.*$/ string_var = replace_month(string_var) end if string_var =~ /^.*{day}.*$/ string_var = replace_day(string_var) end if string_var =~ /^.*{store_value}.*$/ string_var = $context_value end return string_var end
verify_alert_text(text)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 132 def verify_alert_text(text) begin alert = page.driver.browser.switch_to.alert.text puts "Actual Page alert text : #{alert}, Expected value : #{text}" expect(alert).to eq text rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end
verify_element_not_has_text(element,value)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 367 def verify_element_not_has_text(element,value) foundElement = find_object(element) if foundElement != nil begin actual_value = foundElement.text() put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'" expect(actual_value).not_to eql value rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
verify_element_not_has_value(element,value)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 402 def verify_element_not_has_value(element,value) foundElement = find_object(element) if foundElement != nil begin actual_value = foundElement.value() put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'" expect(actual_value).not_to eql value rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
verify_element_text(element,value)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 350 def verify_element_text(element,value) foundElement = find_object(element) if foundElement != nil begin actual_value = foundElement.text() put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'" expect(actual_value).to eq value rescue Exception => e puts "❌ ERROR: #{e} " exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
verify_element_value(element,value)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 385 def verify_element_value(element,value) foundElement = find_object(element) if foundElement != nil begin actual_value = foundElement.value() put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'" expect(actual_value).to eq value rescue Exception => e puts "❌ ERROR: #{e}" exit(1) end else puts "❌ Error: Not found object: #{element}" exit(1) end end
verify_title(expected_title)
click to toggle source
# File lib/Ifd_Automation/web_steps_helper.rb, line 121 def verify_title(expected_title) begin page_title = page.title puts "Actual Page Title : #{page_title}, Expected Page Title : #{expected_title}" expect(page_title).to eq expected_title rescue StandardError => e puts "❌ Error: #{e}" exit(1) end end