コード例 #1
0
 def test_get_text_entry_actions(self):
     page_source = """<?xml version="1.0" encoding="UTF-8"?><hierarchy rotation="0"><android.widget.EditText index="0" text="" class="android.widget.EditText" package="org.tomdroid" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="******" selected="false" bounds="[32,146][736,210]" resource-id="android:id/title1" instance="1"/>
                        <nest><android.widget.EditText index="0" text="" class="android.widget.EditText" package="org.tomdroid" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="******" selected="false" bounds="[32,146][736,210]" resource-id="android:id/title2" instance="1"/>
                        </nest><android.widget.TextView index="0" text="Display Preferences" class="android.widget.TextView" package="org.tomdroid" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="******" selected="false" bounds="[32,146][736,210]" resource-id="android:id/title3" instance="1"/>
                        </hierarchy>"""
     text_entry_widgets = [{
         "selector": "id",
         "selectorValue": "android:id/title1",
         "description": "",
         "type": "EditText",
         "state": "enabled"
     }, {
         "selector": "id",
         "selectorValue": "android:id/title2",
         "description": "",
         "type": "EditText",
         "state": "enabled"
     }]
     expected_actions = [
         actions.TextEntry(text_entry_widgets[0], GUIActionType.TEXT_ENTRY, None),
         actions.TextEntry(text_entry_widgets[1], GUIActionType.TEXT_ENTRY, None)
     ]
     actual_actions = ui_analysis.get_possible_actions(page_source)
     self.assertIn(expected_actions[0], actual_actions)
     self.assertIn(expected_actions[1], actual_actions)
コード例 #2
0
    def test_classify_actions(self):
        text_entry_widgets = [{
            "selector": "id",
            "selectorValue": "android:id/title1",
            "description": "",
            "type": "EditText",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/title2",
            "description": "",
            "type": "EditText",
            "state": "enabled"
        }]

        non_text_entry_widgets = [{
            "selector": "id",
            "selectorValue": "android:id/btn1",
            "description": "Display Preferences",
            "type": "Button",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/btn2",
            "description": "Login",
            "type": "Button",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/checkbox1",
            "description": "Show All",
            "type": "CheckBox",
            "state": "enabled"
        }]

        possible_actions = [
            actions.TextEntry(text_entry_widgets[0], GUIActionType.TEXT_ENTRY, None),
            actions.TextEntry(text_entry_widgets[1], GUIActionType.TEXT_ENTRY, None),
            actions.Click(non_text_entry_widgets[0], GUIActionType.CLICK, None),
            actions.Click(non_text_entry_widgets[1], GUIActionType.CLICK, None),
            actions.Click(non_text_entry_widgets[2], GUIActionType.CHECK, None),
            actions.Click(non_text_entry_widgets[2], GUIActionType.UNCHECK, None)
        ]

        expected_text_entry_actions = [
            actions.TextEntry(text_entry_widgets[0], GUIActionType.TEXT_ENTRY, None),
            actions.TextEntry(text_entry_widgets[1], GUIActionType.TEXT_ENTRY, None)
        ]

        expected_non_text_entry_actions = [
            actions.Click(non_text_entry_widgets[0], GUIActionType.CLICK, None),
            actions.Click(non_text_entry_widgets[1], GUIActionType.CLICK, None),
            actions.Click(non_text_entry_widgets[2], GUIActionType.CHECK, None),
            actions.Click(non_text_entry_widgets[2], GUIActionType.UNCHECK, None)
        ]
        text_entry_actions, non_text_entry_actions = ui_analysis.classify_actions(possible_actions)
        self.assertEqual(text_entry_actions, expected_text_entry_actions)
        self.assertEqual(non_text_entry_actions, expected_non_text_entry_actions)
コード例 #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)
コード例 #4
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)
コード例 #5
0
    def test_state_hash_ignores_order(self):
        widgets = [{
            "selector": "id",
            "selectorValue": "android:id/title1",
            "description": "",
            "type": "EditText",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/title2",
            "description": "",
            "type": "EditText",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/btn2",
            "description": "Login",
            "type": "TextView",
            "state": "enabled"
        }, {
            "selector": "id",
            "selectorValue": "android:id/checkbox1",
            "description": "Show All",
            "type": "CheckBox",
            "state": "enabled"
        }]

        possible_actions = [
            actions.TextEntry(widgets[0], GUIActionType.TEXT_ENTRY,
                              "Hello World!"),
            actions.TextEntry(widgets[1], GUIActionType.TEXT_ENTRY, None),
            actions.Click(widgets[2], GUIActionType.CLICK, None),
            actions.Click(widgets[3], GUIActionType.CHECK, None),
            actions.Click(widgets[3], GUIActionType.UNCHECK, None)
        ]

        hashes = []
        for i in range(10):
            random.shuffle(possible_actions)
            state_id = hashing.generate_state_hash(possible_actions)
            hashes.append(state_id)

        self.assertEqual(len(set(hashes)), 1)
コード例 #6
0
    def test_action_pairs_with_text_entry(self):
        # Arrange
        target = {
            "selector": "id",
            "selectorValue": "delete_btn",
            "type": "button",
            "description": "Delete",
            "state": "enabled"
        }
        non_text_entry_action = actions.TextEntry(target, GUIActionType.CLICK,
                                                  None)

        # Act
        action_pairs_with_text_entry = abstraction.does_action_pair_with_text_entry(
            non_text_entry_action)

        # Assert
        self.assertTrue(action_pairs_with_text_entry)
コード例 #7
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)
コード例 #8
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)