Ejemplo n.º 1
0
    def test_can_press_back(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        back_event = abstraction.create_back_event(precondition)

        # Act
        self.executor.execute(back_event)
Ejemplo n.º 2
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]")
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_create_state(self):
     expected_state = {
         "activityName": "contactsActivity",
         "stateId": "abcdef",
     }
     actual_state = abstraction.create_state("contactsActivity", "abcdef")
     self.assertEqual(actual_state, expected_state)
Ejemplo n.º 5
0
    def test_pair_text_entry_with_non_text_entry_actions(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.pair_text_entry_with_non_text_entry_actions(
            current_state, text_entry_action, non_text_entry_actions)

        # Assert
        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_events = [expected_event_1, expected_event_2]
        self.assertEqual(text_and_act_events, expected_events)
Ejemplo n.º 6
0
    def test_create_single_action_events(self):
        # Arrange
        current_state = abstraction.create_state("contactsActivity", "abcdef")

        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
        single_action_events = abstraction.create_single_action_events(
            current_state, non_text_entry_actions)

        # Assert
        expected_event_1 = {
            "precondition": current_state,
            "actions": [action_1]
        }
        expected_event_2 = {
            "precondition": current_state,
            "actions": [action_2]
        }
        expected_event_3 = {
            "precondition": current_state,
            "actions": [action_3]
        }
        expected_events = [
            expected_event_1, expected_event_2, expected_event_3
        ]
        self.assertEqual(expected_events, single_action_events)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def get_current_state(driver):
    try:
        page_source = driver.page_source
        possible_actions = get_possible_actions(page_source)
        current_activity = driver.current_activity
        state_id = generate_state_hash(possible_actions)
        current_state = abstraction.create_state(current_activity, state_id)
    except Exception as e:
        logger.error("Could not retrieve current state: %s".format(e))
        current_state = abstraction.create_crash_state()

    logger.debug("Current state: {}".format(current_state))
    return current_state
Ejemplo n.º 11
0
 def test_create_home_event(self):
     precondition = abstraction.create_state("contactsActivity", "abcdef")
     action_target = {
         "selector": "key_code",
         "selectorValue": KeyCode.HOME,
         "type": TargetType.NAV,
         "description": "home",
         "state": TargetState.ENABLED
     }
     action_type = GUIActionType.HOME_NAV
     action = actions.Home(action_target, action_type, None)
     expected_event = {"precondition": precondition, "actions": [action]}
     actual_event = abstraction.create_home_event(precondition)
     self.assertEqual(expected_event, actual_event)
Ejemplo n.º 12
0
 def test_create_back_event(self):
     precondition = abstraction.create_state("contactsActivity", "abcdef")
     action_target = {
         "selector": "key_code",
         "selectorValue": KeyCode.BACK,
         "type": TargetType.NAV,
         "description": "back",
         "state": "enabled"
     }
     action_type = GUIActionType.BACK_NAV
     action = actions.Back(action_target, action_type, None)
     expected_event = {"precondition": precondition, "actions": [action]}
     actual_event = abstraction.create_back_event(precondition)
     self.maxDiff = None
     self.assertEqual(expected_event, actual_event)
Ejemplo n.º 13
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]")
Ejemplo n.º 14
0
    def test_create_partial_event(self):
        # Arrange
        precondition = abstraction.create_state("contactsActivity", "abcdef")
        action_target = {
            "selector": "id",
            "selectorValue": "delete_btn",
            "type": TargetType.BUTTON,
            "description": "Delete",
            "state": TargetState.ENABLED
        }
        action_type = GUIActionType.CLICK
        action = actions.Click(action_target, action_type, None)
        gui_actions = [action]

        # Act
        partial_event = abstraction.create_partial_event(
            precondition, gui_actions)

        # Assert
        expected_event = {"precondition": precondition, "actions": gui_actions}
        self.assertEqual(partial_event, expected_event)
Ejemplo n.º 15
0
    def test_create_partial_text_events_with_multiple_text_fields(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_target_2 = {
            "selector": "id",
            "selectorValue": "txt_last_name",
            "type": "edittext",
            "description": "Last Name",
            "state": "enabled"
        }
        text_entry_action_2 = actions.TextEntry(text_entry_target_2,
                                                GUIActionType.TEXT_ENTRY, None)

        text_entry_actions = [text_entry_action_1, text_entry_action_2]

        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
        events = abstraction.create_partial_text_events(
            current_state, text_entry_actions, non_text_entry_actions)

        # Assert
        expected_event_1 = {
            "precondition": current_state,
            "actions": text_entry_actions + [non_text_entry_action_1]
        }
        expected_event_2 = {
            "precondition": current_state,
            "actions": text_entry_actions + [non_text_entry_action_2]
        }
        expected_event_3 = {
            "precondition": current_state,
            "actions": [non_text_entry_action_1]
        }
        expected_event_4 = {
            "precondition": current_state,
            "actions": [non_text_entry_action_2]
        }
        expected_event_5 = {
            "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
        ]
        self.assertEqual(expected_events, events)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
 def test_can_run_in_background(self):
     precondition = abstraction.create_state("contactsActivity", "abcdef")
     background_event = abstraction.create_background_event(precondition)
     self.driver.find_element_by_id("android:id/button3").click()
     self.executor.execute(background_event)