def test_parallel_actions(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() # simulate a swipe/scroll el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') action.press(el).move_to(x=100, y=-1000).release().perform() el = self.driver.find_element_by_accessibility_id('Layouts') action.press(el).move_to(x=100, y=-1000).release().perform() el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views') action.tap(el).perform() wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView') els = self.driver.find_elements_by_class_name('android.widget.ListView') a1 = TouchAction() a1.press(els[0]) \ .move_to(x=10, y=0).move_to(x=10, y=-75).move_to(x=10, y=-600).release() a2 = TouchAction() a2.press(els[1]) \ .move_to(x=10, y=10).move_to(x=10, y=-300).move_to(x=10, y=-600).release() ma = MultiAction(self.driver, els[0]) ma.add(a1, a2) ma.perform()
def test_press_and_wait(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("People Names")') action.press(el).wait(2000).perform() # 'Sample menu' only comes up with a long press, not a press el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)
def test_send_keys(self): for text in ['App', 'Activity', 'Custom Title']: wait_for_element(self.driver, MobileBy.XPATH, "//android.widget.TextView[@text='{}']".format(text)).click() el = self.driver.find_element(MobileBy.ID, 'com.example.android.apis:id/left_text_edit') el.send_keys(' text') self.assertEqual('Left is best text', el.text)
def test_send_keys(self): for text in ['App', 'Activity', 'Custom Title']: wait_for_element( self.driver, MobileBy.XPATH, "//android.widget.TextView[@text='{}']".format(text)).click() el = self.driver.find_element( MobileBy.ID, 'com.example.android.apis:id/left_text_edit') el.send_keys(' text') self.assertEqual('Left is best text', el.text)
def test_set_text(self): self.driver.find_element_by_android_uiautomator( 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));').click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Controls').click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Light Theme').click() el = wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.EditText') el.send_keys('original text') el.set_text('new text') self.assertEqual('new text', el.text)
def test_tap_twice(self): el = self.driver.find_element_by_accessibility_id('Text') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'LogTextBox') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Add') action.tap(el, count=2).perform() els = self.driver.find_elements_by_class_name('android.widget.TextView') self.assertEqual('This is a test\nThis is a test\n', els[1].get_attribute("text"))
def test_tap_twice(self): el = self.driver.find_element_by_accessibility_id('Text') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'LogTextBox') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Add') action.tap(el, count=2).perform() els = self.driver.find_elements_by_class_name( 'android.widget.TextView') self.assertEqual('This is a test\nThis is a test\n', els[1].get_attribute("text"))
def test_tap(self): el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') self.assertIsNotNone(el)
def test_set_text(self): self.driver.find_element_by_android_uiautomator( 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));' ).click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Controls').click() wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Light Theme').click() el = wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.EditText') el.send_keys('original text') el.set_text('new text') self.assertEqual('new text', el.text)
def test_press_and_immediately_release_x_y(self): el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el, 100, 10).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') self.assertIsNotNone(el)
def test_drag_and_drop(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2') # dnd is stimulated by longpress-move_to-release action.long_press(dd3).move_to(dd2).release().perform() el = self.driver.find_element_by_id('com.example.android.apis:id/drag_text') self.assertTrue('drag_dot_3' in el.text)
def test_driver_multi_tap(self): el = self.driver.find_element_by_accessibility_id('Graphics') action = TouchAction(self.driver) action.tap(el).perform() wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.TextView') els = self.driver.find_elements_by_class_name('android.widget.TextView') self.driver.scroll(els[len(els) - 1], els[0]) els = self.driver.find_elements_by_class_name('android.widget.TextView') if els[len(els) - 1].get_attribute('name') != 'Xfermodes': self.driver.scroll(els[len(els) - 1], els[0]) el = self.driver.find_element_by_accessibility_id('Touch Paint') action.tap(el).perform() positions = [(100, 200), (100, 400)] # makes two dots in the paint program # THE TEST MUST BE WATCHED TO CHECK IF IT WORKS self.driver.tap(positions) sleep(10)
def test_drag_and_drop(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id( 'com.example.android.apis:id/drag_dot_2') # dnd is stimulated by longpress-move_to-release action.long_press(dd3).move_to(dd2).release().perform() el = self.driver.find_element_by_id( 'com.example.android.apis:id/drag_text') self.assertTrue('drag_dot_3' in el.text)
def test_driver_drag_and_drop(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() dd3 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2') self.driver.drag_and_drop(dd3, dd2) el = self.driver.find_element_by_id('com.example.android.apis:id/drag_text') self.assertTrue('drag_dot_3' in el.text)
def test_driver_drag_and_drop(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() dd3 = self.driver.find_element_by_id( 'com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id( 'com.example.android.apis:id/drag_dot_2') self.driver.drag_and_drop(dd3, dd2) el = self.driver.find_element_by_id( 'com.example.android.apis:id/drag_text') self.assertTrue('drag_dot_3' in el.text)
def test_long_press_x_y(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('Expandable Lists') action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('1. Custom Adapter') action.tap(el).perform() # the element "People Names" is located at 430:310 (top left corner) # location can be changed by phone resolusion, OS version action.long_press(x=430, y=310).perform() # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)