def call_step str_step put_log "\n-=> call step: #{str_step}" step %{#{str_step}} end def put_log str puts str if $_CONFIG['Print Log'] == true end def find_object string_object object = YAML.load_file("#{File.expand_path(File.dirname(__FILE__) + '/..')}/step_definitions/repositories/project_object.yml") string_object = string_object.gsub(/"/, "'") # puts string_object locator_matching = /(.*?)(\{.*?\})/.match(string_object) # puts "locator_matching : #{locator_matching}" 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] puts hash_object if hash_object == nil put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!" true.should eq false else hash_object.each { |key, value| $element_tag = key $element_value = value } end return selenium.find_element($element_tag, $element_value) end def execute_click element found_element = find_object element if found_element != nil startTime = Time.new.to_i begin sleep(1) currentTime= Time.new.to_i end while (currentTime - startTime) < $_CONFIG['Wait Time'] # selenium.execute_script('mobile: scroll', found_element) found_element.click 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.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" expect(check).not_to eql true elsif expect(check).to eq true end end end def click_by_coordinate x, y selenium.execute_script 'mobile: tap', :x => x, :y => y end # method to navigate back & forward def navigate(direction) if direction == 'back' selenium.navigate.back else selenium.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 selenium.close_app end def launch_app selenium.launch end def reset_app selenium.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 selenium.key_event 3 end