class BbStudentCommonApi def element_exists_by_id?(my_id, my_timeout=nil) $driver.set_wait timeout=0 if my_timeout.nil? my_timeout=5 end wait = Selenium::WebDriver::Wait.new :timeout => my_timeout begin wait.until {$driver.find_element(my_id).displayed? } return true rescue return false end end #This one is less common by element_exists_by_id, but could be useful. def element_exists_by_text?(my_text, my_timeout) if my_timeout.nil? my_timeout=5 end $driver.set_wait timeout=0 wait = Selenium::WebDriver::Wait.new :timeout => my_timeout begin wait.until { text(my_text) } return true rescue return false end end #Examples: # $bb.find_element(@my_id,5,"click") # $bb.find_element(@my_id,2,"send_keys","hello there") # $bb.find_element(@my_id,3) def find_element(my_id,my_timeout,action=nil,input=nil) #Doing some type checking first. if (!my_id.is_a?(Hash)) raise Exception, "find_element ID of #{my_id} is not a hash!" end if (!my_timeout.is_a?(Integer)) raise Exception, "find_element TIMEOUT of #{my_timeout} is not an integer!" end if (!action.nil?) if action!="click" and action!="send_keys" raise Exception, "find_element ACTION of #{action} not recognized! Use either click or send_keys" end end if (!input.nil?) if (!input.is_a?(String)) raise Exception, "find_element INPUT of #{input} is not a string!" end end $driver.set_wait timeout=0 wait = Selenium::WebDriver::Wait.new :timeout => my_timeout case action when "click" begin wait.until {$driver.find_element(my_id).click} rescue raise Exception, "#{my_id} was not found after #{my_timeout} seconds!" end when "send_keys" begin wait.until {$driver.find_element(my_id).send_keys input } rescue raise Exception, "#{my_id} was not found after #{my_timeout} seconds!" end else begin wait.until {$driver.find_element(my_id).displayed?} rescue raise Exception, "#{my_id} was not found after #{my_timeout} seconds!" end end end def find_elements(my_id,my_timeout) $driver.set_wait timeout=my_timeout wait = Selenium::WebDriver::Wait.new :timeout => my_timeout begin wait.until {$driver.find_element(my_id)} rescue raise Exception, "#{my_id} was not found after #{my_timeout} seconds!" end end #Low level swipe method. Takes in percentages. gets the height and width of devices and gets pixels def bb_swipe(start_x_percentage, start_y_percentage, end_x_percentage, end_y_percentage,duration) width = $driver.window_size[:width] height = $driver.window_size[:height] start_x_pixel = start_x_percentage * width start_y_pixel = start_y_percentage * height end_x_pixel = end_y_percentage * width end_y_pixel = end_y_percentage * height action = Appium::TouchAction.new.press(x: start_x_pixel, y: start_y_pixel).wait(duration).move_to(x: end_x_pixel, y: end_y_pixel).release() action.perform end #Swipe Commands. Notes: #1. We have variant methods for swiping right and left due to the duration field being different for android (250ms) vs iOS (500ms) #1a. Reason: iOS has a minimum of 500ms duration. Android we change here to 250 to make the FTUE swipes work optimally. #2. For the iOS simulator, generic swiping is broken so we cannot use the above bb_swipe method. #2b. Workaround: we use open-source https://github.com/vicwomg/swipeInWindow.py def swipe_right if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.5 0.2 0.5') elsif ENV['ANDROID_LOCAL_SIM'] == "TRUE" or ENV['ANDROID_LOCAL_DEVICE'] == "TRUE" bb_swipe(0.95, 0.2, 0.1, 0.2, 250) else bb_swipe(0.95, 0.2, 0.1, 0.2, 500) end end def swipe_left if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.2 0.5 0.9 0.5') elsif ENV['ANDROID_LOCAL_SIM'] == "TRUE" or ENV['ANDROID_LOCAL_DEVICE'] == "TRUE" #modified on android for longer pause to lift finger at end (800ms) #should work with slide to tests/attempts and slide to continue tests/attempts bb_swipe(0.05, 0.9, 0.95, 0.9, 700) else bb_swipe(0.05, 0.95, 0.95, 0.9, 500) end end def swipe_to_start_assignment if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.1 0.95 0.9 0.95') elsif ENV['ANDROID_LOCAL_SIM'] == "TRUE" or ENV['ANDROID_LOCAL_DEVICE'] == "TRUE" bb_swipe(0.2, 0.9, 0.9, 0.9, 250) else bb_swipe(0.2, 0.9, 0.9, 0.9, 500) end end def swipe_down_small if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.7 0.9 0.4') else bb_swipe(0.9, 0.7, 0.9, 0.4, 500) end end def swipe_down_very_small if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.57 0.9 0.55') else bb_swipe(0.9, 0.7, 0.9, 0.5, 500) end end def swipe_down_medium if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.9 0.9 0.5') else bb_swipe(0.9, 0.9, 0.9, 0.5, 500) end end def swipe_down_large if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.9 0.9 0.2') else bb_swipe(0.9, 0.9, 0.9, 0.2, 500) end end def swipe_up_small if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.4 0.9 0.7') else bb_swipe(0.9, 0.5, 0.9, 0.7, 500) end end def swipe_up_large if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.3 0.9 0.9') else bb_swipe(0.9, 0.3, 0.9, 0.9, 500) end end def swipe_up_very_large if ENV['IOS_LOCAL_SIM']=="TRUE" system('python ./bin/swipeInWindow.py "iOS Simulator" 0.9 0.1 0.9 0.95') else bb_swipe(0.9, 0.1, 0.9, 0.95, 500) end end end