Exemple #1
0
class Config(object):
    
    def __init__(self,config=CONFIG_FILE):
        self.config = YamlReader(config).data
    
    def get(self,key):
        return self.config.get(key)
Exemple #2
0
 def __init__(self, path='public', jsonpath='public_config.json'):
     """
     :param jsonpath: 配置文件的路径
     """
     JSONCONFIG_FILE = os.path.join(BASE_PATH, 'data', path, jsonpath)
     self._j = JMESPathExtractor()
     self._jsonConfig = YamlReader(JSONCONFIG_FILE).data
     self._content = open(JSONCONFIG_FILE, encoding='utf-8')
Exemple #3
0
 def get(self,
         element,
         index=0
         ):  # 读取yml文件   Config().get('元素'),直接查出结果,可以多次多用get方法查找更深层级的路径元素
     config = YamlReader(self.CONFIG_FILE).data
     """
     yaml是可以通过'---'分节的。用YamlReader读取返回的是一个list,第一项是默认的节,如果有多个节,可以传入index来获取。
     这样我们其实可以把框架相关的配置放在默认节,其他的关于项目的配置放在其他节中。可以在框架中实现多个项目的测试。
     """
     return config[index].get(element)
Exemple #4
0
 def get(self, element, index=0):
     """
     get config element
     :param element: yaml element
     :param index: yaml is separated to lists by '---'
     :return:
     """
     self.config = YamlReader(self.file).data
     elem = self.config[index].get(element)
     return elem
 def __init__(self, data_f='data.yaml'):
     path = os.path.join(DATA_DIR, data_f)
     self.data = YamlReader(path).data
Exemple #6
0
 def __init__(self, config):
     self.config = YamlReader(config).data
Exemple #7
0
 def __init__(self,config = CONFIG_FILE,locator = LOCATOR_FILE):
     self.config = YamlReader(config).data
     self.locator = YamlReader(locator).data
 def __init__(self, config_path=CONFIG_FILE_PATH):
     print('文件路径', config_path)
     self.config_list = YamlReader(config_path).data
Exemple #9
0
    def __init__(self, config=CONFIG_FILE):

        from utils.file_reader import YamlReader
        self.config = YamlReader(config).data
Exemple #10
0
 def __init__(self, config=CONFIG_PATH):
     # 将YamlReader获得的list数据传给config
     self.config = YamlReader(config).data
Exemple #11
0
 def __init__(self, config=new_all_cfgs):
     self.configs = YamlReader(config).data
Exemple #12
0
 def __init__(self, config=CONFIG_FILE):
     print('配置文件地址:', config)
     self.config = YamlReader(config).data
 def __init__(self, config='desired_capablities_config.yaml'):
     path = os.path.join(CONFIG_DIR, config)
     self.config = YamlReader(path).data
Exemple #14
0
    def __init__(self, path='public', config='url_config.yml'):
        CONFIG_FILE = os.path.join(BASE_PATH, 'data', path, config)

        self.config = YamlReader(CONFIG_FILE).data
Exemple #15
0
 def __init__(self, config=CONFIG_FILE):  #默认传入config配置文件的路径
     self.config = YamlReader(config).data
Exemple #16
0
 def set(self, param, value, index_name='PARAM'):
     config = YamlReader(self.CONFIG_FILE).set_data(param, value,
                                                    index_name)
Exemple #17
0
 def __init__(self):
     self.data = YamlReader(os.path.join(CONFIG_PATH, 'config.yml')).data
Exemple #18
0
class Server:
    def __init__(self):
        self.dos = Doc_cmd()
        self.devices_list = self.get_devices()
        evpath = DRIVER_PATH + '/Android_environment.yml'
        self.yaml = YamlReader(evpath)

    #设备list
    def get_devices(self):
        '''
        获取设备信息
        :return: 
        '''
        devices_list = []
        result_list = self.dos.excute_cmd_result('adb devices')
        #执行结果['List of devices attached', '2ed0d2f3\tdevice', 'c824d603\tdevice', '']
        #['List of devices attached', '']
        #默认为空是就是2,所以要写成3
        if len(result_list) >= 3:
            for i in result_list:
                if i != "":
                    if 'List' in i:
                        continue
                    else:
                        devices_info = i.split('\t')  #\t分割设备名和设备类型
                        if i.split('\t')[1]:
                            devices_list.append(i.split('\t')[0])
            return devices_list
        else:
            return None

    #检测端口是否可用,可用直接创建端口list
    def port_is_used(self, number):
        '''
        判断端口number是否被占用
        :return: 
        '''
        self.dos = Doc_cmd()
        #result=self.dos.excute_cmd_result('netstat -ano | findstr '+str(number))  #windows下端口占用
        result = self.dos.excute_cmd_result('lsof -i:' +
                                            str(number))  #mac/linux下检查端口占用

        if len(result) > 0:
            flag = False
        else:
            flag = True
        return flag

    def create_port_list(self, start_port):
        '''
        生成可用端口list前,需检查port是否可用
        :param start_port:  
        :return: port_list
        '''
        port_list = []  #端口个数由设备个数决定
        devices_list = self.get_devices()
        if devices_list:
            while len(port_list) != len(devices_list):
                if self.port_is_used(start_port) == True:
                    port_list.append(start_port)
                start_port = start_port + 1
            return port_list
        else:
            print("生成可用端口失败")
            return None

    #命令appium
    def crete_command_list(self, i):
        '''
        生成命令行list,多个设备多个命令行
        #appium -p 4700 -bp 4701 -U 设备devicesName
        :return: command_list 根据设备数量决定
        '''
        port = Config().get('EVIORMENT').get('port')
        b_port = Config().get('EVIORMENT').get('bp')
        command_list = []
        appium_port_list = self.create_port_list(int(port))  #监听端口list
        bootstrap_port_list = self.create_port_list(int(b_port))  #链接安卓端口list

        # for i in  range(len(self.devices_list)):
        #命令
        command = "appium -p " + str(appium_port_list[i]) + " -bp " + str(
            bootstrap_port_list[i]
        ) + " -U " + self.devices_list[i] + "  --session-override" + '\n'
        #-p  监听端口
        #-bp  是连接Android设备bootstrap的端口号,默认是4724
        #-U 链接设备名称
        #--session-override是指覆盖之前的session
        #--no-reset   每次启动不重启
        command_list.append(command)
        #写入yaml
        deviceInfo = {
            "device" + str(i): {
                'port': str(appium_port_list[i]),
                'deviceName': str(self.devices_list[i]),
                'bp': str(bootstrap_port_list[i])
            }
        }

        self.yaml.write_data(data=deviceInfo)

        return command_list

    def kill_server(self):
        '''
        杀掉appium进程
        :return: 
        '''
        #获取进程列表
        #server_list = self.dos.excute_cmd_result('tasklist | find "node.exe"') #windows查看进程
        server_list = self.dos.excute_cmd_result(
            'ps aux | grep node')  #mac/linux查看进程
        if len(server_list) > 0:
            #self.dos.excute_cmd('taskkill -F -PID node.exe') #windows杀掉进程
            self.dos.excute_cmd_mac('killall node')  #mac 杀进程
            print('node进程清理完毕')
        else:
            pass

    # 执行 创建好的命令list
    def start_server(self, i):
        self.start_list = self.crete_command_list(i)
        print("执行命令: " + self.start_list[0])
        self.dos.excute_cmd_mac(self.start_list[0])

    #主要函数 多进程调用启动方法
    def main(self):
        '''
        多线程启动appium
        :return: 
        '''
        #清理yaml里创建成功的设备信息
        self.yaml.clear_yaml()
        #先杀掉进程,清理环境
        self.kill_server()
        time.sleep(2)
        try:
            thread_list = []
            for i in range(len(self.devices_list)):

                appium = threading.Thread(target=self.start_server, args=(i, ))
                thread_list.append(appium)

            for t in thread_list:
                t.start()
                time.sleep(10)
                print("该进程启动成功")

        except Exception as ex:
            print('请检查设备列表是否为空')
Exemple #19
0
 def __init__(self, config=CONFIG_FILE):
     self.config = YamlReader(config).data
Exemple #20
0
 def __init__(self):
     self.dos = Doc_cmd()
     self.devices_list = self.get_devices()
     evpath = DRIVER_PATH + '/Android_environment.yml'
     self.yaml = YamlReader(evpath)