Exemple #1
0
 def test_deploy(self):
     device = Device("emulator-5554")
     self.assertTrue(self.call_log_env.deploy(device))
     self.assertTrue(self.contact_env.deploy(device))
     self.assertTrue(self.gps_env.deploy(device))
     self.assertTrue(self.settings_env.deploy(device))
     self.assertTrue(self.sms_log_env.deploy(device))
     device.disconnect()
 def test_send(self):
     device = Device("emulator-5554")
     self.assertTrue(self.touch_event.send(device))
     self.assertTrue(self.intent_event.send(device))
     self.assertTrue(self.long_touch_event.send(device))
     self.assertTrue(self.key_event.send(device))
     self.assertTrue(self.emulator_event.send(device))
     self.assertTrue(self.drag_event.send(device))
     self.assertTrue(self.context_event1.send(device))
     device.disconnect()
    def test_context(self):
        device = Device("emulator-5554")
        self.assertFalse(self.activity_context.assert_in_device(device))
        self.assertFalse(self.window_context.assert_in_device(device))

        settings_activity_context = ActivityNameContext("com.android.settings/.Settings")
        settings_window_context = WindowNameContext("com.android.settings/com.android.settings.Settings")
        device.start_app("com.android.settings")
        time.sleep(2)
        self.assertTrue(settings_activity_context.assert_in_device(device))
        self.assertTrue(settings_window_context.assert_in_device(device))

        device.disconnect()
class TestADB(unittest.TestCase):
    def setUp(self):
        self.device=Device("emulator-5554")
        self.adb = ADB(self.device)

    def test_connect(self):
        self.assertTrue(self.adb.check_connectivity())

    def test_run_cmd(self):
        r = self.adb.run_cmd(['get-state'])
        self.assertTrue(r.startswith('device'))
        r = self.adb.run_cmd("get-state")
        self.assertTrue(r.startswith('device'))

    def tearDown(self):
        self.adb.disconnect()
        self.device.disconnect()
class TestTelnet(unittest.TestCase):
    def setUp(self):
        self.device=Device("emulator-5554")
        self.telnet = TelnetConsole(self.device)

    def test_connect(self):
        self.assertTrue(self.telnet.check_connectivity())
        self.telnet.disconnect()

    def test_run_cmd(self):
        self.assertTrue(self.telnet.run_cmd("help"))
        self.assertTrue(self.telnet.run_cmd(['help']))
        self.assertFalse(self.telnet.run_cmd("unknown"))

    def tearDown(self):
        self.telnet.disconnect()
        self.device.disconnect()
class TestADB(unittest.TestCase):
    def setUp(self):
        self.device = Device("emulator-5554")
        self.adb = ADB(self.device)

    def test_connect(self):
        self.assertTrue(self.adb.check_connectivity())

    def test_run_cmd(self):
        r = self.adb.run_cmd(['get-state'])
        self.assertTrue(r.startswith('device'))
        r = self.adb.run_cmd("get-state")
        self.assertTrue(r.startswith('device'))

    def tearDown(self):
        self.adb.disconnect()
        self.device.disconnect()
class TestTelnet(unittest.TestCase):
    def setUp(self):
        self.device = Device("emulator-5554")
        self.telnet = TelnetConsole(self.device)

    def test_connect(self):
        self.assertTrue(self.telnet.check_connectivity())
        self.telnet.disconnect()

    def test_run_cmd(self):
        self.assertTrue(self.telnet.run_cmd("help"))
        self.assertTrue(self.telnet.run_cmd(['help']))
        self.assertFalse(self.telnet.run_cmd("unknown"))

    def tearDown(self):
        self.telnet.disconnect()
        self.device.disconnect()
Exemple #8
0
class DeviceTest(unittest.TestCase):
    """
    test the Device class,
    before testing, please make sure a emulator is started
    """
    def setUp(self):
        self.device = Device("emulator-5554")

    def tearDown(self):
        self.device.disconnect()
        self.device = None

    def test_init(self):
        self.assertTrue(self.device.is_connected)
        self.assertIsNotNone(self.device.get_display_info())

        device_real = Device("emulator-5554", is_emulator=False)
        self.assertTrue(device_real.is_connected)

    def test_connect(self):
        if self.device.is_emulator:
            self.assertIsNotNone(self.device.get_adb())
            self.assertIsNotNone(self.device.get_telnet())
            self.assertIsNotNone(self.device.get_view_client())
        else:
            self.assertIsNotNone(self.device.get_adb())
            self.assertIsNotNone(self.device.get_telnet())
        self.device.check_connectivity()
        self.device.disconnect()
        self.device.connect()
        self.assertTrue(self.device.is_connected)

    def test_is_foreground(self):
        settings_app = App(package_name="com.android.settings")
        no_app = App()
        self.device.get_adb().press('HOME')
        time.sleep(2)
        self.assertTrue(self.device.is_foreground(no_app))
        self.assertFalse(self.device.is_foreground(settings_app))

        self.device.start_app(settings_app)
        time.sleep(2)
        self.assertTrue(settings_app)
        self.assertFalse(self.device.is_foreground("com.android.unknown"))

    def test_add_contact(self):
        contact_data = {
            'name': 'Lynn',
            'phone': '1234567890'
        }
        r = self.device.add_contact(contact_data)
        self.assertTrue(r)

    def test_call(self):
        phone_num = "1234567890"

        r = self.device.call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.cancel_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.receive_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.accept_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.cancel_call(phone_num)
        self.assertTrue(r)

    def test_sms(self):
        r = self.device.send_sms()
        self.assertTrue(r)

        r = self.device.receive_sms()
        self.assertTrue(r)

    def test_set_gps(self):
        r = self.device.set_gps(10, 10)
        self.assertTrue(r)

    def test_settings(self):
        self.device.change_settings(table_name='system', name='volume_system', value='10')
        self.assertEqual(self.device.get_settings()['system']['volume_system'], '10')
        self.device.change_settings(table_name='system', name='volume_system', value='20')
        self.assertEqual(self.device.get_settings()['system']['volume_system'], '20')
Exemple #9
0
class DeviceTest(unittest.TestCase):
    """
    test the Device class,
    before testing, please make sure a emulator is started
    """
    def setUp(self):
        self.device = Device("emulator-5554")

    def tearDown(self):
        self.device.disconnect()
        self.device = None

    def test_init(self):
        self.assertTrue(self.device.is_connected)
        self.assertIsNotNone(self.device.get_display_info())

        device_real = Device("emulator-5554", is_emulator=False)
        self.assertTrue(device_real.is_connected)

    def test_connect(self):
        if self.device.is_emulator:
            self.assertIsNotNone(self.device.get_adb())
            self.assertIsNotNone(self.device.get_telnet())
            self.assertIsNotNone(self.device.get_view_client())
        else:
            self.assertIsNotNone(self.device.get_adb())
            self.assertIsNotNone(self.device.get_telnet())
        self.device.check_connectivity()
        self.device.disconnect()
        self.device.connect()
        self.assertTrue(self.device.is_connected)

    def test_is_foreground(self):
        settings_app = App(package_name="com.android.settings")
        no_app = App()
        self.device.get_adb().press('HOME')
        time.sleep(2)
        self.assertTrue(self.device.is_foreground(no_app))
        self.assertFalse(self.device.is_foreground(settings_app))

        self.device.start_app(settings_app)
        time.sleep(2)
        self.assertTrue(settings_app)
        self.assertFalse(self.device.is_foreground("com.android.unknown"))

    def test_add_contact(self):
        contact_data = {'name': 'Lynn', 'phone': '1234567890'}
        r = self.device.add_contact(contact_data)
        self.assertTrue(r)

    def test_call(self):
        phone_num = "1234567890"

        r = self.device.call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.cancel_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.receive_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.accept_call(phone_num)
        self.assertTrue(r)
        time.sleep(2)

        r = self.device.cancel_call(phone_num)
        self.assertTrue(r)

    def test_sms(self):
        r = self.device.send_sms()
        self.assertTrue(r)

        r = self.device.receive_sms()
        self.assertTrue(r)

    def test_set_gps(self):
        r = self.device.set_gps(10, 10)
        self.assertTrue(r)

    def test_settings(self):
        self.device.change_settings(table_name='system',
                                    name='volume_system',
                                    value='10')
        self.assertEqual(self.device.get_settings()['system']['volume_system'],
                         '10')
        self.device.change_settings(table_name='system',
                                    name='volume_system',
                                    value='20')
        self.assertEqual(self.device.get_settings()['system']['volume_system'],
                         '20')