Ejemplo 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
Ejemplo n.º 2
0
    def __init__(self):
        self.path = Config.DEFAULT_CONFIG_DIR
        self.cp = ConfigParser()
        self.cp.read(self.path)
        L.i('初始化config...config path: ' + self.path)
        apk_name = self.get_config(Config.TITLE_NAME, Config.VALUE_APP)
        self.apk_path = Config.BASE_PATH_DIR + '/apk/' + apk_name
        self.xml_report_path = Config.BASE_PATH_DIR + '/report/xml'
        self.html_report_path = Config.BASE_PATH_DIR + '/report/html'
        self.pages_yaml_path = Config.BASE_PATH_DIR + '/page/yaml'
        self.env_yaml_path = Config.BASE_PATH_DIR + '/data/environment_info.yaml'
        self.app_activity = self.get_config(Config.TITLE_NAME,
                                            Config.VALUE_APP_ACTIVITY)
        self.app_package = self.get_config(Config.TITLE_NAME,
                                           Config.VALUE_APP_PACKAGE)

        self.smtpserver = self.get_config(Config.TITLE_MAIL,
                                          Config.VALUE_SMTPSERVER)
        self.sender = self.get_config(Config.TITLE_MAIL, Config.VALUE_SENDER)
        self.receiver = self.get_config(Config.TITLE_MAIL,
                                        Config.VALUE_RECEIVER)
        self.username = self.get_config(Config.TITLE_MAIL,
                                        Config.VALUE_USERNAME)
        self.password = self.get_config(Config.TITLE_MAIL,
                                        Config.VALUE_PASSWORD)
Ejemplo n.º 3
0
    def _get_element_by_type(driver, locator, element=True):
        """通过locator定位元素(默认定位单个元素)

        Args:
            driver:driver
            locator:定位器
            element:
                true:查找单个元素
                false:查找多个元素

        Returns:单个元素 或 元素list

        """
        value = locator['value']
        ltype = locator['type']
        L.i("[查找]元素 %s " % locator)
        if ltype == 'name':
            ui_value = 'new UiSelector().textContains' + '(\"' + value + '\")'
            return driver.find_element_by_android_uiautomator(
                ui_value
            ) if element else driver.find_elements_by_android_uiautomator(
                ui_value)
        else:
            return driver.find_element(
                ltype, value) if element else driver.find_elements(
                    ltype, value)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def on_created(self, event):
     L.i('监听到文件: yaml 发生了变化')
     try:
         gen_page_py()
     except Exception as e:
         L.e('\n!!!!!!!---pages.yaml---!!!!!!\n解析文件 pages.yaml 错误\n'
             '请到{}路径下检查修改后重新保存.'.format(self.watch_path))
Ejemplo n.º 6
0
def swip_up(self, count=1, method=None):
    """向上滑动,常用于上拉加载

    Args:
        count: 滑动次数
        method: 传入的方法 method(action) ,如果返回为True,则终止加载

    Examples:
        swip_down(self, count=100, method=is_text_displayed(self, "没有更多了"))
        上面代码意思:当页面不展示"暂无可配送的订单"时停止加载,即有单停止加载
    """
    if count == 1:
        self.driver.swipe(width / 2, height * 4 / 5, width / 2, height * 2 / 5,
                          2000)
        time.sleep(1)
    else:
        x = 0
        for x in range(count):
            self.driver.swipe(width / 2, height * 4 / 5, width / 2,
                              height * 2 / 5, 2000)
            time.sleep(1)
            try:
                if method(self):
                    break
            except:
                pass
        L.i('上拉加载的次数:' + str(x))
Ejemplo n.º 7
0
def parse():
    L.i('解析yaml, Path:' + pages_path)
    pages = {}
    for root, dirs, files in os.walk(pages_path):
        for name in files:
            watch_file_path = os.path.join(root, name)
            with open(watch_file_path, 'r') as f:
                page = yaml.safe_load(f)
            pages.update(page)
        return pages
Ejemplo n.º 8
0
    def get_text(self, locator):
        """获取元素中的text文本
        :param locator: 定位器
        """
        L.i("[获取]元素 %s " % locator.get('name'))

        if locator.get('index'):
            el = self._find_elements(locator)[locator['index']]
        else:
            el = self._find_element(locator)

        return el.text
Ejemplo n.º 9
0
    def _find_text_in_page(self, text):
        """检查页面中是否有文本关键字
        拿到页面全部source,暴力检查text是否在source中
        Args:
            text: 检查的文本

        Returns:
            True : 存在

        """
        L.i("[查找] 文本 %s " % text)
        return text in self.driver.page_source
Ejemplo n.º 10
0
 def swip_right(self, height=0.5, count=1, speed=1000):
     """向右滑动
     :param height: 高度满屏幕为1
     :param count: 滑动次数
     :param speed: 滑动速度 ms
     :return:
     """
     for x in range(count):
         self.sleep(1)
         self.driver.swipe(self.width / 8, self.height * height, self.width * 7 / 8, self.height * height, speed)
         self.sleep(2)
         L.i("[滑动]向右滑动 ")
Ejemplo n.º 11
0
 def set_text(self, locator, clear_first=False, click_first=True):
     """ 输入文本
     :param locator: 定位器
     :param clear_first: 是否先清空原来文本
     :param click_first: 是否先点击选中
     """
     value = locator.get('text')
     if click_first:
         self._find_element(locator).click()
     if clear_first:
         self._find_element(locator).clear()
     L.i("[输入]元素 %s " % value)
     with allure.step("输入元素:{0}".format(value)):
         self._find_element(locator).send_keys(value)
Ejemplo n.º 12
0
 def check_environment(self):
     L.i('检查环境...')
     # 检查appium版本
     #if '1.6' not in self.appium_v:
     #   L.e('appium 版本有问题')
     #    exit()
     #else:
     #L.i('appium version {}'.format(self.appium_v))
     # 检查设备
     if not self.devices:
         L.e('没有设备连接')
         exit()
     else:
         L.i('已连接设备:', self.devices)
Ejemplo n.º 13
0
 def test_login_empty_password(self, action: ElementActions):
     account = Steps.get_account()
     time.sleep(20)
     action.swip_left(3)
     time.sleep(5)
     L.d('test_login_empty_password')
     L.i('账户{0},密码为空'.format(account[0]))
     action.click(HomePage.登录)
     login(account[0], "", action)
     action.sleep(5)
     try:
         assert action.is_text_displayed('密码能为空1')
     except Exception as e:
         action.save_failure_pic(sys._getframe().f_code.co_name)
Ejemplo n.º 14
0
 def save_environment(self):
     infos = []
     env_path = self.config.env_yaml_path
     apk_path = self.config.apk_path
     html_report_path = self.config.html_report_path
     app_activity = self.config.app_activity
     app_package = self.config.app_package
     for deviceName in self.devices:
         info = DeviceInfo(deviceName, "Android", ADB(deviceName).get_android_version())
         infos.append(info)
         L.i('已连接的设备版本:' + ADB(deviceName).get_android_version())
     env_info = EnvironmentInfo(self.appium_v, infos, apk_path, html_report_path, app_activity, app_package)
     with open(env_path, 'w') as f:
         yaml.dump(env_info, f, default_flow_style=False)
     L.i('保存环境配置 Path:' + env_path)
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
 def swip_down(self, count=1, method=None, speed=1000):
     """ 向下滑动,常用于下拉刷新
     :param count: 滑动次数
     :param method: 传入的方法 method(action) ,如果返回为True,则终止刷新
     :param speed: 滑动速度 ms
     """
     if count == 1:
         self.driver.swipe(self.width / 2, self.height * 2 / 5, self.width / 2, self.height * 4 / 5, speed)
         self.sleep(1)
     else:
         for x in range(count):
             self.driver.swipe(self.width / 2, self.height * 2 / 5, self.width / 2, self.height * 4 / 5, speed)
             self.sleep(1)
             try:
                 if method(self):
                     break
             except:
                 pass
     L.i("[滑动]向下刷新 ")
Ejemplo n.º 17
0
 def __init__(self):
     self.path = Config.DEFAULT_CONFIG_DIR
     self.cp = ConfigParser()
     self.cp.read(self.path)
     L.i('初始化config...config path: ' + self.path)
     apk_name = self.get_config(Config.TITLE_NAME, Config.VALUE_APP)
     self.apk_path = Config.BASE_PATH_DIR + '/apk/' + apk_name
     self.xml_report_path = Config.BASE_PATH_DIR + '/report/xml'
     self.html_report_path = Config.BASE_PATH_DIR + '/report/html'
     self.pages_yaml_path = Config.BASE_PATH_DIR + '/page/yaml'
     self.env_yaml_path = Config.BASE_PATH_DIR + '/data/environment_info.yaml'
     self.app_activity = self.get_config(Config.TITLE_NAME,
                                         Config.VALUE_APP_ACTIVITY)
     self.app_package = self.get_config(Config.TITLE_NAME,
                                        Config.VALUE_APP_PACKAGE)
     self.account_success = self.get_config(Config.TITLE_ACCOUNT,
                                            Config.VALUE_ACCOUNT_SUCCESS)
     self.password_success = self.get_config(Config.TITLE_ACCOUNT,
                                             Config.VALUE_PASSWORD_SUCCESS)
Ejemplo n.º 18
0
 def save_environment(self):
     infos = []
     env_path = self.config.env_yaml_path
     apk_path = self.config.apk_path
     pages_yaml_path = self.config.pages_yaml_path
     strTime = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
     xml_report_path = self.config.xml_report_path + "_" + strTime
     html_report_path = self.config.html_report_path + "_" + strTime
     app_activity = self.config.app_activity
     app_package = self.config.app_package
     for deviceName in self.devices:
         info = DeviceInfo(deviceName, "Android",
                           ADB(deviceName).get_android_version())
         infos.append(info)
     env_info = EnvironmentInfo(self.appium_v, infos, apk_path,
                                pages_yaml_path, xml_report_path,
                                html_report_path, app_activity, app_package)
     with open(env_path, 'w') as f:
         yaml.dump(env_info, f, default_flow_style=False)
     L.i('保存环境配置 Path:' + env_path)
Ejemplo n.º 19
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
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    def swip_up(self, count=1, method=None, speed=1000):
        """ 向上刷新
        :param count: 滑动次数
        :param method: 传入的方法 method(action) ,如果返回为True,则终止刷新
        :param speed: 滑动速度 ms
        :return:

        """
        if count == 1:
            self.sleep(1)
            self.driver.swipe(self.width / 2, self.height * 3 / 4, self.width / 2, self.height / 4, speed)
            self.sleep(2)
        else:
            for x in range(count):
                self.driver.swipe(self.width / 2, self.height * 3 / 4, self.width / 2, self.height / 4, speed)
                self.sleep(2)
                try:
                    if method(self):
                        break
                except:
                    pass
        L.i("[滑动]向上刷新 ")
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by zhouyuyan on 2017/5/19 14:35
import unittest

from Common import InitDriver
from Common.yunxiCommon import *
from Common.Element import *
from appium import webdriver as appdriver
from utils import L

L.i('-------开始运行test_my-------')


class My(unittest.TestCase):
    def setUp(self):

        self.driver = InitDriver.start_driver()

        self.driver.implicitly_wait(5)

        print("----------------setup-------------")

    def tearDown(self):
        print("-------------teardown------------------")
        self.driver.close_app()
        self.driver.quit()

    def test_e(self):
        """测试登录-设置(清除缓存)"""
        goto_login(self)
Ejemplo n.º 24
0
 def goto_setting(self):
     get_id(self, 'tv.yunxi.app:id/rl_setting').click()
     L.i('--点击设置按钮--')
Ejemplo n.º 25
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by zhouyuyan on 2017/5/19 14:35
import unittest

from Common import InitDriver
from Common.action import ElementActions
from Common.yunxiCommon import *
from Common.Element import *
from appium import webdriver as appdriver
from utils import L

L.i('-------开始运行test_attention-------')


class Attention(unittest.TestCase):
    def setUp(self):
        self.driver = InitDriver.start_driver()
        self.driver.implicitly_wait(5)
        global action
        action = ElementActions(driver=self.driver)
        print("----------------setup-------------")

    def tearDown(self):
        print("-------------teardown------------------")
        self.driver.close_app()
        self.driver.quit()

    def test_d(self):
        """测试登录-关注页面"""
        goto_login(self)
Ejemplo n.º 26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by zhouyuyan on 2017/5/19 14:34
import unittest
from random import choice
from Common import InitDriver
from Common.yunxiCommon import *
from utils import L

L.i('-------开始运行test_home-------')


class Home(unittest.TestCase):
    def setUp(self):

        self.driver = InitDriver.start_driver()

        self.driver.implicitly_wait(5)
        global action
        action = ElementActions(driver=self.driver)

        print("----------------setup-------------")

    def tearDown(self):
        print("-------------teardown------------------")
        self.driver.close_app()
        self.driver.quit()

    def test_a(self):
        """测试登录-发现-搜索-评论"""
        goto_login(self)
Ejemplo n.º 27
0
# -*- coding: utf-8 -*-
__author__ = 'Mio4kon'
from utils.shell import Shell
from utils import L
import datetime


class Device:
    @staticmethod
    def get_android_devices():
        android_devices_list = []
        for device in Shell.invoke('adb devices').splitlines():
            if 'device' in device and 'devices' not in device:
                device = device.split('\t')[0]
                android_devices_list.append(device)
        return android_devices_list


class UUID:
    @staticmethod
    def get_uuid():
        return datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')


if __name__ == '__main__':
    devices = Device.get_android_devices()
    L.i("devices: ", devices)
Ejemplo n.º 28
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by zhouyuyan on 2017/5/19 14:35
import unittest

from Common import InitDriver
from Common.yunxiCommon import *
from utils import L

L.i('-------开始运行test_login-------')


class Login(unittest.TestCase):
    def setUp(self):
        self.driver = InitDriver.start_driver()
        self.driver.implicitly_wait(5)
        global action
        action = ElementActions(driver=self.driver)
        self.driver.update_settings({"ignoreUnimportantViews": True})
        # 判断是否出现权限弹窗
        sleep(3)
        print("----------------setup-------------")

    def tearDown(self):
        print("-------------teardown------------------")
        self.driver.close_app()
        self.driver.quit()

    def test_login01(self):
        u"""用户名为空,密码为空----登录失败"""
        goto_login(self)
Ejemplo n.º 29
0
 def back_press(self):
     L.i("系统按键返回上一页")
     self.sleep(1)
     self._send_key_event('KEYCODE_BACK')