Esempio n. 1
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', encoding='utf-8') as f:
                page = yaml.safe_load(f)
            pages.update(page)
        return pages
Esempio n. 2
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
Esempio n. 3
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)
Esempio n. 4
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
     xml_report_path = self.config.xml_report_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)
     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)
Esempio n. 5
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)
Esempio n. 6
0
 def check_environment(self):
     L.i('检查环境...')
     # 检查appium版本
     if '1.17.1' 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)
Esempio n. 7
0
# -*- coding: utf-8 -*-
# @Pjname ; AppGuiTesting
# @Time   : 2020/05/21/17:46
# @Author : Yuye
# @File   : Tools.py

from Utils.Shell import Shell
from Utils import L


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


if __name__ == '__main__':
    devices = Device.get_android_devices()
    L.i("devices: ", devices)