Example #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)
 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)
Example #3
0
def get_available_events(driver):
    current_state = get_current_state(driver)
    page_source = driver.page_source
    possible_actions = get_possible_actions(page_source)
    text_entry_actions, non_text_entry_actions = classify_actions(
        possible_actions)
    if text_entry_actions:
        available_events = abstraction.create_partial_text_events(
            current_state, text_entry_actions, non_text_entry_actions)
    else:
        available_events = abstraction.create_partial_events(
            current_state, possible_actions)

    available_events.append(abstraction.create_back_event(current_state))
    available_events.append(abstraction.create_background_event(current_state))

    return available_events
    def test_can_get_available_events_when_only_nav_and_background(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="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.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_available_events = [
            abstraction.create_back_event(current_state),
            abstraction.create_background_event(current_state)
        ]
        self.assertEqual(available_events, expected_available_events)