Ejemplo n.º 1
0
class ChromeCastImpl:
    '''
    classdocs
    '''
    pkg_name = "com.android.settings"
    activity_name = "com.android.settings.Settings"

    def __init__(self):
        self._device = g_common_obj.get_device()
        self._locator = Locator(self._device)

    def set_environment(self):
        """ init the test environment
        """
        self.systemui = SystemUiExtendImpl()
        self.camera = CameraExtendImpl()
        config = TestConfig()
        cfg_file = 'tests.tablet.chromecast.conf'
        cfg_cast = config.read(cfg_file, 'chromecast_device')
        self.nexus_device = cfg_cast.get("device")
        self.nexus_name = cfg_cast.get("name")
        cmd = "-s %s logcat -d -c" % self.nexus_device
        g_common_obj.adb_cmd_common(cmd)
        print "[clear log]"

    def launch_app_am(self):
        """ Launch Settings via adb am command
        """
        print "Launch Settings by adb am"
        g_common_obj.launch_app_am(\
            ChromeCastImpl.pkg_name, ChromeCastImpl.activity_name)
        self._locator.wait_exist(self._locator.performance_tests)
        time.sleep(5)

    @staticmethod
    def stop_app_am():
        """ Stop Settings via adb am command
        """
        print "Stop Settings by adb am"
        g_common_obj.stop_app_am(ChromeCastImpl.pkg_name)

    def goto_castscreen(self):
        """ go to the castscreen interface
        """
        self._device(text="Display").click()
        time.sleep(1)
        self._device(text="Cast").click()
        time.sleep(5)

    def scan_adapter(self):
        """ scan the ChromeCast adapter
        """
        time.sleep(5)
        if self._device(text="No nearby devices were found.").exists:
            time.sleep(30)
        assert self._device(className="android.widget.RelativeLayout"
                            ).exists, "No nearby chromecast adapter"
        assert self._device(
            text=self.nexus_name).exists, "No target chromecaset exists."

    def connect_chromecast(self):
        """ connect to the chromecast
        """
        self._device(text=self.nexus_name).click()
        time.sleep(5)
        cmd = "-s %s logcat -d > /tmp/connect.log" % self.nexus_device
        g_common_obj.adb_cmd_common(cmd)
        assert not os.system(
            "cat /tmp/connect.log|grep 'onCastMirroringConnected'"\
            ), "The chromecast didn't connect "

    def disconnect_chromecast(self):
        """ disconnect the chromecast
        """
        self._device(text=self.nexus_name).click()
        time.sleep(2)
        self._device(text="Disconnect").click()
        time.sleep(2)
        cmd = "-s %s logcat -d > /tmp/disconnect.log" % self.nexus_device
        g_common_obj.adb_cmd_common(cmd)
        assert not os.system(
            "cat /tmp/disconnect.log|grep 'onCastMirroringConnected'"\
            ), "The chromecast didn't disconnect "

    def reconnect_chromecastx10(self):
        """ replay connect to chromecast 10 times
        """
        for i in range(1, 11):
            self.scan_adapter()
            self.connect_chromecast()
            time.sleep(15)
            self.swith_to_camera_and_return()
            self.disconnect_chromecast()
            print "[reconnect to chromecast %s times]" % i
            time.sleep(2)

    @staticmethod
    def reboot_device():
        """ reboot the device
        """
        g_common_obj.reboot_device()
        time.sleep(40)

    def reboot_chromecast_adapter(self):
        """ reboot the chromecast adapter
        """
        cmd = "-s %s reboot" % self.nexus_device
        g_common_obj.adb_cmd_common(cmd)
        print "[Wait adapter reboot]"
        time.sleep(100)

    def swith_to_camera_and_return(self):
        """ Launch camera via adb am command
        """
        print "Launch camera by adb am"
        self.camera.launch_camera_am()
        self._locator.wait_exist(self._locator.performance_tests)
        if self._device(text="NEXT").exists:
            self._device(text="NEXT").click()
        self.systemui.switch_recent_app("Settings")

    def disconnect_cast_if_failed(self):
        """ disconnect chromecast if failed
        """
        self.launch_app_am()
        self.goto_castscreen()
        if self._device(text="Connected").exists:
            self.disconnect_chromecast()
        self.stop_app_am()
Ejemplo n.º 2
0
class CardviewRecentsTest(UIATestBase):
    @classmethod
    def setUpClass(cls):
        print "[setUpClass]: %s" % cls.__name__
        super(CardviewRecentsTest, cls).setUpClass()
        cls.d = g_common_obj.get_device()
        cls.config_file = 'tests.ComposeUI.CardviewRecentsTest.conf'
        cls.test_conf = cls.config.read(cls.config_file, "CardviewRecentsTest")

    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(CardviewRecentsTest, self).setUp()
        self.actor_apps = self.test_conf.get('actor_apps')
        self.calendar_path = get_resource_from_atifactory(
            self.config_file, "apps", "calendar")
        self.clock_path = get_resource_from_atifactory(self.config_file,
                                                       "apps", "clock")
        pkgmgr.apk_install(self.calendar_path)
        pkgmgr.apk_install(self.clock_path)
        self.systemui = SystemUiExtendImpl()
        self.photos = get_photo_implement()
        self.photos.rm_delete_photos()
        self.systemui.unlock_screen()
        self.d.screen.on()
        self.d.press.menu()
        self.mark_time = logcat.get_device_time_mark()

    def tearDown(self):
        print "[tearDown]:%s" % self.__class__.__name__
        #         fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F')
        #         assert len(fatal_msg) == 0, \
        #             "occurred Fatal error during testing:\n%s" % (fatal_msg)
        super(CardviewRecentsTest, self).tearDown()
        self.photos.rm_delete_photos()
        remove_aosp_launcher()

    @classmethod
    def tearDownClass(cls):
        print "[tearDownClass]: %s" % cls.__name__
        super(CardviewRecentsTest, cls).tearDownClass()

    def test_Cardview_Recents(self):
        """
        test_Cardview_Recents

        Steps:
        1. launch 5 apps 
        # change to 5 apps due to some of apps in step are not preinstalled.
            all launch successfully
        2. launch Recents to swtich between different app
            Check CardView in Recents are working correctly
        """
        print "[RunTest]: %s" % self.__str__()

        print "[Init APP]"
        print "Init Photos"
        g_common_obj.launch_app_am(
            " com.google.android.apps.photos",
            "com.google.android.apps.photos.home.HomeActivity")
        time.sleep(2)
        self.photos.stop_photos_am()
        time.sleep(1)
        print "Init Calendar"
        g_common_obj.launch_app_am("com.google.android.calendar",
                                   "com.android.calendar.AllInOneActivity")
        if not self.d(description="Create new event and more").exists:
            for _ in range(0, 3):
                if self.d(description="next page").exists:
                    self.d(description="next page").click.wait()
            if self.d(text="Got it").exists:
                self.d(text="Got it").click.wait()
        g_common_obj.stop_app_am("com.google.android.calendar")
        time.sleep(2)
        print """[Step] 1. launch 5 apps
            all launch successfully"""
        for each in self.actor_apps.split(','):
            if "com.android.launcher3" not in pkgmgr.get_packages():
                launch_aosp_home()
            self.systemui.launch_desk_app(each)
            time.sleep(2)

        print """[Step] 2. launch Recents to swtich between different app
            Check CardView in Recents are working correctly"""
        for each in self.actor_apps.split(','):
            self.systemui.switch_recent_app(each)
            time.sleep(2)