예제 #1
0
    def test_can_type_text_in_multiple_text_fields_and_click_button(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        text_field_target_1 = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/title", "", "EditText",
                                                        TargetState.ENABLED)
        text_field_target_2 = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/content", "", "EditText",
                                                        TargetState.ENABLED)
        non_text_target = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/edit_note_save", "Save",
                                                    "TextView", TargetState.ENABLED)

        text_entry_action_1 = abstraction.create_action(GUIActionType.TEXT_ENTRY, text_field_target_1)
        text_entry_action_1.value = "[random string]"

        text_entry_action_2 = abstraction.create_action(GUIActionType.TEXT_ENTRY, text_field_target_2)
        text_entry_action_2.value = "[random string]"

        non_text_action = abstraction.create_action(GUIActionType.CLICK, non_text_target)

        multiple_text_entry_event = {
            "precondition": precondition,
            "actions": [text_entry_action_1, text_entry_action_2, non_text_action]
        }
        self.navigate_to_note_creation()

        # Act
        self.executor.execute(multiple_text_entry_event)

        # Assert
        self.assertNotEqual(text_entry_action_1.value, "[random string]")
        self.assertNotEqual(text_entry_action_2.value, "[random string]")
예제 #2
0
    def test_pair_text_entry_with_enter_key(self):
        # Arrange
        current_state = abstraction.create_state("contactsActivity", "abcdef")
        target = {
            "selector": "id",
            "selectorValue": "txt_first_name",
            "type": "edittext",
            "description": "First Name",
            "state": "enabled"
        }
        text_entry_action = actions.TextEntry(target, GUIActionType.TEXT_ENTRY,
                                              None)

        # Act
        text_entry_enter_key_event = abstraction.pair_text_entry_with_enter_key(
            current_state, text_entry_action)

        # Assert
        enter_target = abstraction.create_enter_target()
        enter_key_action = abstraction.create_action("enter", enter_target)
        expected_event = {
            "precondition": current_state,
            "actions": [text_entry_action, enter_key_action]
        }
        # self.assertEqual(text_entry_enter_key_event["actions"][0]["value"], "[random string]")
        self.assertEqual(text_entry_enter_key_event, expected_event)
예제 #3
0
def get_possible_actions(page_source):
    possible_actions = []
    actionable_widgets = _get_actionable_widgets(page_source)
    for action_type, widgets in actionable_widgets.items():
        for widget in widgets:
            action = abstraction.create_action(action_type, widget)
            possible_actions.append(action)

    logger.debug("Found {} possible actions.".format(len(possible_actions)))
    return possible_actions
예제 #4
0
    def test_can_type_text_in_single_field(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        text_field_target = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/title", "", "EditText",
                                                      TargetState.ENABLED)
        text_entry_action = abstraction.create_action(GUIActionType.TEXT_ENTRY, text_field_target)
        text_entry_action.value = "[random string]"

        enter_key_action = abstraction.create_action(GUIActionType.ENTER_KEY, abstraction.create_enter_target())
        text_entry_event = {
            "precondition": precondition,
            "actions": [text_entry_action, enter_key_action]
        }
        self.navigate_to_note_creation()

        # Act
        self.executor.execute(text_entry_event)

        # Assert
        self.assertNotEqual(text_entry_action.value, "[random string]")
예제 #5
0
 def test_create_action(self):
     action_type = GUIActionType.CLICK
     widget = {
         "selector": "id",
         "selectorValue": "widget_id",
         "description": "Login",
         "type": "Button",
         "state": "enabled"
     }
     created_action = abstraction.create_action(action_type, widget)
     expected_action = actions.Click(widget, action_type, None)
     self.assertEqual(created_action, expected_action)
예제 #6
0
    def test_can_swipe_down(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        swipe_down_target = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/note_title", "", "RelativeLayout",
                                                    TargetState.ENABLED)
        swipe_down_event = {
            "precondition": precondition,
            "actions": [abstraction.create_action(GUIActionType.SWIPE_DOWN, swipe_down_target)]
        }
        self.driver.find_element_by_id("android:id/button3").click()

        # Act
        self.executor.execute(swipe_down_event)
예제 #7
0
    def test_can_long_click(self):
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        self.driver.find_element_by_id("android:id/button3").click()

        long_click_target = abstraction.create_target(SelectorType.ID, "org.tomdroid:id/note_title",
                                                      "Tomdroid's First Note", "TextView", TargetState.ENABLED)
        long_click_event = {
            "precondition": precondition,
            "actions": [abstraction.create_action(GUIActionType.LONG_CLICK, long_click_target)]
        }

        # Act
        self.executor.execute(long_click_event)
예제 #8
0
    def test_can_press_return(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        enter_key_target = abstraction.create_enter_target()
        enter_event = {
            "precondition": precondition,
            "actions": [abstraction.create_action(GUIActionType.ENTER_KEY, enter_key_target)]
        }
        self.navigate_to_note_creation()

        # Act

        self.executor.execute(enter_event)
예제 #9
0
    def test_create_partial_text_events_with_single_text_field(self):
        # Arrange
        current_state = abstraction.create_state("contactsActivity", "abcdef")

        text_entry_target_1 = {
            "selector": "id",
            "selectorValue": "txt_first_name",
            "type": "edittext",
            "description": "First Name",
            "state": "enabled"
        }
        text_entry_action_1 = actions.TextEntry(text_entry_target_1,
                                                GUIActionType.TEXT_ENTRY, None)
        text_entry_actions = [text_entry_action_1]

        non_text_entry_target_1 = {
            "selector": "id",
            "selectorValue": "ok_btn",
            "type": "button",
            "description": "OK",
            "state": "enabled"
        }
        non_text_entry_action_1 = actions.Click(non_text_entry_target_1,
                                                GUIActionType.CLICK, None)

        non_text_entry_target_2 = {
            "selector": "id",
            "selectorValue": "cancel_btn",
            "type": "button",
            "description": "Cancel",
            "state": "enabled"
        }
        non_text_entry_action_2 = actions.Click(non_text_entry_target_2,
                                                GUIActionType.CLICK, None)

        non_text_entry_target_3 = {
            "selector": "id",
            "selectorValue": "gender_radio_btn",
            "type": "radiobutton",
            "description": "Gender",
            "state": "enabled"
        }
        non_text_entry_action_3 = actions.Click(non_text_entry_target_3,
                                                GUIActionType.CLICK, None)
        non_text_entry_actions = [
            non_text_entry_action_1, non_text_entry_action_2,
            non_text_entry_action_3
        ]

        # Act
        partial_text_events = abstraction.create_partial_text_events(
            current_state, text_entry_actions, non_text_entry_actions)

        # Assert - potentially improve tests to not assert on lists but use membership assert
        text_entry_action = text_entry_actions[0]
        text_entry_action.value = "[random string]"
        enter_action = abstraction.create_action(
            "enter", abstraction.create_enter_target())
        expected_event_1 = {
            "precondition": current_state,
            "actions": [text_entry_action, non_text_entry_action_1]
        }
        expected_event_2 = {
            "precondition": current_state,
            "actions": [text_entry_action, non_text_entry_action_2]
        }
        expected_event_3 = {
            "precondition": current_state,
            "actions": [text_entry_action, enter_action]
        }
        expected_event_4 = {
            "precondition": current_state,
            "actions": [non_text_entry_action_1]
        }
        expected_event_5 = {
            "precondition": current_state,
            "actions": [non_text_entry_action_2]
        }
        expected_event_6 = {
            "precondition": current_state,
            "actions": [non_text_entry_action_3]
        }
        expected_events = [
            expected_event_1, expected_event_2, expected_event_3,
            expected_event_4, expected_event_5, expected_event_6
        ]

        self.assertEqual(partial_text_events, expected_events)
예제 #10
0
    def test_create_events_for_single_text_field(self):
        # Arrange
        current_state = abstraction.create_state("contactsActivity", "abcdef")
        target = {
            "selector": "id",
            "selectorValue": "txt_first_name",
            "type": "edittext",
            "description": "First Name",
            "state": "enabled"
        }
        text_entry_action = actions.TextEntry(target, GUIActionType.TEXT_ENTRY,
                                              None)

        target_1 = {
            "selector": "id",
            "selectorValue": "ok_btn",
            "type": "button",
            "description": "OK",
            "state": "enabled"
        }
        action_1 = actions.Click(target_1, GUIActionType.CLICK, None)

        target_2 = {
            "selector": "id",
            "selectorValue": "cancel_btn",
            "type": "button",
            "description": "Cancel",
            "state": "enabled"
        }
        action_2 = actions.Click(target_2, GUIActionType.CLICK, None)

        target_3 = {
            "selector": "id",
            "selectorValue": "gender_radio_btn",
            "type": "radiobutton",
            "description": "Gender",
            "state": "enabled"
        }
        action_3 = actions.Click(target_3, GUIActionType.CLICK, None)

        non_text_entry_actions = [action_1, action_2, action_3]

        # Act
        text_and_act_events = abstraction.create_events_for_single_text_field(
            current_state, text_entry_action, non_text_entry_actions)

        # Assert
        text_entry_action.value = "[random string]"
        expected_event_1 = {
            "precondition": current_state,
            "actions": [text_entry_action, action_1]
        }
        expected_event_2 = {
            "precondition": current_state,
            "actions": [text_entry_action, action_2]
        }
        expected_event_3 = {
            "precondition":
            current_state,
            "actions": [
                text_entry_action,
                abstraction.create_action("enter",
                                          abstraction.create_enter_target())
            ]
        }
        expected_events = [
            expected_event_1, expected_event_2, expected_event_3
        ]
        self.assertEqual(expected_events, text_and_act_events)
        self.assertEqual(text_and_act_events[0]["actions"][0].value,
                         "[random string]")