예제 #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_create_target(self):
     expected_target = {
         "selector": "selector_type",
         "selectorValue": "selector_value",
         "description": "description",
         "type": "type",
         "state": "enabled"
     }
     actual_target = abstraction.create_target("selector_type",
                                               "selector_value",
                                               "description", "type",
                                               "enabled")
     self.assertEqual(expected_target, actual_target)
예제 #3
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)
예제 #4
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)
예제 #5
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]")
예제 #6
0
    def test_can_make_event_serializable_when_single_action(self):
        # Arrange
        target = abstraction.create_target("id", "element_id", "description",
                                           "button", "enabled")
        action_1 = actions.Click(target, GUIActionType.CLICK, None)
        precondition = {"activityName": "activity_1", "stateId": "state_id_1"}
        postcondition = {"activityName": "activity_2", "stateId": "state_id_1"}
        event = {
            "actions": [action_1],
            "precondition": precondition,
            "postcondition": postcondition
        }

        # Act
        event_with_actions_as_dict = abstraction.make_event_serializable(event)

        # Assert
        action_as_dict = event_with_actions_as_dict["actions"][0]
        self.assertIsInstance(action_as_dict, dict)
        self.assertEqual(action_as_dict["target"], action_1.target)
        self.assertEqual(action_as_dict["type"], action_1.action_type)
        self.assertEqual(action_as_dict["value"], action_1.value)
예제 #7
0
    def test_can_get_available_events_with_one_click_event(self):
        # Arrange
        webdriver_mock = MagicMock(name="webdriver")
        webdriver_mock.page_source = """<?xml version="1.0" encoding="UTF-8"?><hierarchy rotation="0"><android.widget.Button index="0" text="Display Preferences" class="android.widget.Button" package="org.tomdroid" content-desc="" checkable="false" checked="false" clickable="true" 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.TextView index="0" text="Login" class="android.widget.TextView" package="org.tomdroid" content-desc="" checkable="false" checked="false" clickable="false" enabled="false" 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>"""
        webdriver_mock.current_activity = "contactsActivity"
        current_state = ui_analysis.get_current_state(webdriver_mock)

        # Act
        available_events = ui_analysis.get_available_events(webdriver_mock)

        # Assert
        expected_target = abstraction.create_target("id", "android:id/title1", "Display Preferences", TargetType.BUTTON, TargetState.ENABLED)
        expected_available_events = [
            {
                "precondition": current_state,
                "actions": [actions.Click(expected_target, GUIActionType.CLICK, None)]
            },
            abstraction.create_back_event(current_state),
            abstraction.create_background_event(current_state)
        ]
        self.assertEqual(available_events, expected_available_events)