def call_step str_step put_log "\n-=> call step: #{str_step}" step %{#{str_step}} end def put_log str puts str if $print_log end def find_object string_object string_object = string_object.gsub(/"/, "'") hash_object = $OBJECT[string_object] if hash_object.nil? expect(true).to eq(false) else hash_object.each { |key, value| $element_tag = key $element_value = value } end get_object_by_dynamic_selector($element_tag, $element_value) end def get_object_by_dynamic_selector(selector_type,value) foundElements = nil begin foundElements = @driver.find_element(selector_type, value) rescue StandardError => myStandardError p "\n>>> Error: #{myStandardError}" end foundElements end def execute_click element found_element = find_object element if found_element != nil startTime = Time.new.to_i begin sleep(1) found_element.click rescue StandardError => myStandardError put_log "\nERROR: *** #{myStandardError}" end else put_log "\nERROR: *** not found object: #{element}" end end def execute_settext element, text found_element = find_object element if found_element != nil begin sleep(1) # found_element.long_press_keycode(46) found_element.clear found_element.send_keys(text) rescue StandardError => myStandardError put_log "\nERROR: *** #{myStandardError}" end else put_log "\nERROR: *** not found object: #{element}" exit end end def execute_checkproperty element, property, negate, value found_element = find_object element check = false if found_element == nil and value == "" check = true expect(check).to eq true else put_log "\n*** Execute_CheckProperty: finish to found element" if found_element != nil if property.upcase == 'VALUE' actual_value = found_element.attribute("value") elsif property.upcase == 'NAME' actual_value = found_element.attribute("name") elsif property.upcase == 'LABEL' actual_value = found_element.attribute("label") elsif property.upcase == 'TYPE' actual_value = found_element.attribute("type") elsif property.upcase == 'ENABLE' actual_value = found_element.attribute("enable") else actual_value = found_element.attribute("#{property}") end if actual_value == nil actual_value = '' end else put_log "ERROR: *** Not found object: #{element}" end if IFD_Assertion.reg_compare(actual_value, value) 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 def click_by_coordinate x, y @driver.execute_script 'mobile: tap', :x => x, :y => y end # method to navigate back & forward def navigate(direction) if direction == 'back' @driver.navigate.back else @driver.navigate.forward end end # def swipe_direction(direction) # size = selenium.manage.window.size # height = size.height.to_i - 10 # width = size.width.to_i - 10 # # if direction == 'right' # start_x = (width/100) * 15 # 83 # start_y = height/2 # 695 # end_x = (width/100) * 90 # 900 # end_y = height/2 # 630 # elsif direction == 'left' # start_x = (width/100) * 90 # start_y = height/2 # end_x = (width/100) * 15 # end_y = height/2 # elsif direction == 'up' # start_x = width/2 # start_y = (height/100) * 90 # end_x = width/2 # end_y = (height/100) * 15 # elsif direction == 'down' # start_x = width/2 # start_y = (height/100) * 15 # end_x = width/2 # end_y = (height/100) * 90 # else # raise "invalid direction" # end # # swipe(start_x, start_y, end_x, end_y) # end # def swipe(start_x, start_y, end_x, end_y) # action = Appium::TouchAction.new.press(x: "#{start_x}", y: "#{start_y}").wait(1000).move_to(x: "#{end_x}", y: "#{end_y}").release() # action.perform # end def long_press_on_element_default_duration(element) begin ele_from = find_object element.location x = ele_from.x y = ele_from.y action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release() action.perform rescue Exception => e if e.to_s == 'The swipe did not complete successfully' print "" else raise e end end end def long_press_on_element_with_duration(element, duration) begin ele_from = find_object element.location x = ele_from.x y = ele_from.y duration = duration.to_i duration = duration * 1000 action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release() action.perform rescue Exception => e if e.to_s == 'The swipe did not complete successfully' print "" else raise e end end end def long_press_on_coordinates(x, y) action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release() action.perform end def long_press_on_coordinates_with_duration(x, y, duration) duration = duration.to_i duration = duration * 1000 puts duration action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release() action.perform end def close_app @driver.close_app end def launch_app @driver.launch end def reset_app @driver.reset end def delete_an_character_android system('adb shell input keyevent 67') end def take_photo_android system('adb shell input keyevent 27') end def move_home @driver.key_event 3 end def data(name) require 'yaml' begin return $globalData["#{name}"] rescue Exception return name end end