Esempio n. 1
0
    def open_danm(self):
        # 开启弹幕

        try:
            bottom_control = get_id(self, 'tv.yunxi.app:id/rl_bottom_control')
            danm = get_id(self, 'tv.yunxi.app:id/img_danmaku_control')
            result02 = lambda action: action.is_element_displayed(danm)
            if result02:
                print(result02)
                bottom_control.click()
                L.i('点击屏幕')
                if result02:
                    danm.click()
                    print('点击opdanm按钮01')

            else:
                danm.click()
                print('点击opdanm按钮02')
            od = 1

        except:
            L.w("open_danm failed")
            od = 2
        print(od)

        return od
Esempio n. 2
0
    def close_fullScreen(self):
        # 关闭全屏

        a = 0
        try:
            fusc = get_id(self, 'tv.yunxi.app:id/img_full_Screen')
            giftLl = get_id(self, 'tv.yunxi.app:id/giftLl')
            result01 = lambda action: action.is_element_displayed(fusc)
            if not result01:
                sleep(5)
                giftLl.click()
                if result01:
                    fusc.click()
                    L.i('点击cl全屏按钮01')
                a = 1
            else:
                if result01:
                    fusc.click()
                fusc.click()
                L.i('点击cl全屏按钮02')
                a = 1

        except:

            L.w("竖屏failed")
            a = 2
        print(a)
        return a
Esempio n. 3
0
    def is_text_displayed(self, text, is_retry=True, retry_time=5, is_raise=False):
        """检查页面中是否有文本关键字

        如果希望检查失败的话,不再继续执行case,使用 is_raise = True

        Args:
            text: 关键字(请确保想要的检查的关键字唯一)
            is_retry: 是否重试,默认为true
            retry_time: 重试次数,默认为5
            is_raise: 是否抛异常
        Returns:
            True: 存在关键字
        Raises:
            如果is_raise = true,可能会抛NotFoundElementError

        """

        try:
            if is_retry:
                return WebDriverWait(self.driver, retry_time).until(
                    lambda driver: self._find_text_in_page(text))
            else:
                return self._find_text_in_page(text)
        except TimeoutException:
            L.w("[Text]页面中未找到 %s 文本" % text)
            if is_raise:
                raise NotFoundTextError
            else:
                return False
Esempio n. 4
0
    def open_fullScreen(self):
        # 开启全屏
        sleep(5)
        fusc = get_id(self, 'tv.yunxi.app:id/img_full_Screen')
        # fusc = get_id(self,'tv.yunxi.app:id/img_full_Screen')
        giftLl = get_id(self, 'tv.yunxi.app:id/giftLl')
        # result01 = self.assertIsNotNone(fusc)
        result01 = lambda action: action.is_element_displayed(fusc)
        try:
            if result01:
                fusc.click()
                L.i('点击op全屏按钮02')
                print(result01)
                a = 1

            else:
                giftLl.click()
                L.i('点击屏幕')
                if result01:
                    fusc.click()
                    L.i('点击op全屏按钮01')
                a = 1

        except:
            a = 2

            L.w("横屏播放failed")
        print(a)
        return a
Esempio n. 5
0
 def _find_elements(self, locator):
     """ 查找多元素
     :param locator: 定位器
     :return:  []
     """
     with allure.step("检查:'{0}'".format(locator.get('name'))):
         try:
             return WebDriverWait(self.driver, locator['time']).until(
                 lambda driver: self._get_element_by_type(driver, locator, False))
         except:
             L.w("[elements] 页面中未能找到 %s 元素" % locator)
             return []
Esempio n. 6
0
    def is_toast_show(self, message, wait=20):
        """Android检查是否有对应Toast显示,常用于断言

        Args:
            message: Toast信息
            wait:  等待时间,默认20秒

        Returns:
            True 显示Toast

        """
        locator = {'name': '[Toast] %s' % message, 'timeOutInSeconds': wait, 'type': 'xpath',
                   'value': '//*[contains(@text,\'%s\')]' % message}
        try:
            el = self._find_element(locator, is_need_displayed=False)
            return el is not None
        except NotFoundElementError:
            L.w("[Toast] 页面中未能找到 %s toast" % locator)
            return False
Esempio n. 7
0
    def setting(self):

        try:

            sleep(2)
            get_id(self, 'tv.yunxi.app:id/rl_wipe_cache').click()
            L.i('--点击清空缓存按钮--')
            sleep(2)
            get_id(self, 'tv.yunxi.app:id/dialog_ok').click()
            sleep(2)
            L.i('--点击清空缓存dialog--')
            sleep(2)
            get_id(self, 'tv.yunxi.app:id/ll_back').click()
            sleep(2)
            self.driver.keyevent(4)  # 硬件返回
        except:
            L.w('--操作失败--')

        sleep(2)
Esempio n. 8
0
    def _find_elements(self, locator):
        """查找多元素(不会抛异常)

        Args:
            locator: 定位器

        Returns:元素列表 或 []

        """
        if 'timeOutInSeconds' in locator:
            wait = locator['timeOutInSeconds']
        else:
            wait = 20

        try:
            WebDriverWait(self.driver, wait).until(
                lambda driver: self._get_element_by_type(driver, locator, False).__len__() > 0)
            return self._get_element_by_type(self.driver, locator, False)
        except:
            L.w("[elements] 页面中未能找到 %s 元素" % locator)
            return []
Esempio n. 9
0
    def test_videoSetting(self):
        """测试登录-发现页面-播放界面设置"""
        b = 0
        self.goto_faxian()
        self.search()
        a = self.open_fullScreen()
        if a == 1:
            b = self.open_danm()
            L.i('open_danm success')
        else:
            L.w('open_danm failed')
            pass

        if b == 1:
            self.close_danm()
            L.i("close_danm success")
        else:
            L.w("close_danm failed")
            pass
        if a == 1:
            self.close_fullScreen()
            L.i('open_danm success')
        else:
            L.w('open_danm failed')
            pass
Esempio n. 10
0
    def close_danm(self):
        # 关闭弹幕

        try:
            bottom_control = get_id(self, 'tv.yunxi.app:id/rl_bottom_control')
            danm = get_id(self, 'tv.yunxi.app:id/img_danmaku_control')
            result02 = lambda action: action.is_element_displayed(danm)
            if not result02:
                print(result02)
                bottom_control.click()
                L.i('点击屏幕')
                if result02:
                    danm.click()
                    L.i('点击danm按钮01')
            else:
                if result02:
                    danm.click()
                    L.i('点击danm按钮02')

        except:
            L.w("close_danm  failed")
        sleep(5)
Esempio n. 11
0
    def is_element_displayed(self, locator, is_raise=False, element=True):
        """ :控件是否显示e
        :param locator: 定位器
        :param is_raise: 是否抛异常
        :param element:
        :returns:
            true:  显示
            false: 不显示
        """
        try:
            return WebDriverWait(self.driver, 2).until(
                lambda driver: self._get_element_by_type(driver, locator),
                '查找元素{0}失败'.format(locator.get('name'))) if element else WebDriverWait(self.driver, 2).until(
                lambda driver: self._get_element_by_type(driver, locator, element_type=False),
                '查找元素{0}失败'.format(locator.get('name')))

        except Exception as E:
            L.w("页面中未找到 %s " % locator)
            if is_raise:
                raise E
            else:
                return False