def port_is_used(self, port): self.dos = DosCmd() result = self.dos.excute_cmd('netstat -an | grep %s' % port) if len(result) > 0: flag = True else: flag = False return flag
def port_is_used(self, port_num): """ 判断端口是否被占用 """ flag = None self.dos = DosCmd() command = "netstat -ano | findstr " + str(port_num) result = self.dos.excute_cmd_result(command) if len(result) > 0: flag = True else: flag = False return flag
def prot_is_used(self, port_num): ''' 判断端口是否被占用 ''' flag = None self.dos = DosCmd() command = 'netstat -ano | findstr ' + port_num result = self.dos.excute_cmd_get_result(command) if len(result) > 0: flag = True else: flag = False return flag
def port_is_used(self, port_num): ''' 判断端口是否被占用 :return: ''' flag = True self.dos_cmd = DosCmd() result = self.dos_cmd.excute_cmd_result('netstat -ano | findstr ' + str(port_num)) if len(result) > 0: flag = True else: flag = False return flag
def port_is_used(self, port_num): """ :param port_num: 断开 :return: 端口是非被占用,True被占用 False未被占用 """ self.dos = DosCmd() self.port_num = str(port_num) result = self.dos.execute_cmd_result("netstat -ano|findstr " + self.port_num) if len(result) > 0: return True else: return False
class Port: def __init__(self): self.dos = DosCmd() def port_is_usrd(self, port_num): ''' 判断端口是否被占用 ''' flag = None command = 'netstat -ano|findstr ' + str(port_num) result = self.dos.excute_cmd_result(command) if len(result) > 0: flag = True else: flag = False return flag def create_port_list(self, start_port, count): ''' 生成可用端口,参数起始端口号和端口个数 ''' port_list = [] if count > 0: while len(port_list) < count: if self.port_is_usrd(start_port) != True: port_list.append(start_port) start_port = start_port + 1 return port_list else: print u"生成可用端口失败" return None
class Port(object): def port_is_used(self, port_num): """ 判断端口是否被占用 """ flag = None self.dos = DosCmd() command = "netstat -ano | findstr " + str(port_num) result = self.dos.excute_cmd_result(command) if len(result) > 0: flag = True else: flag = False return flag def creat_port_list(self, start_port, device_list): """ 生成可用端口 :param start_port: :param device_list: """ port_list = [] if device_list != None: while len(port_list) != len(device_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
class Port: def port_is_used(self, port_num): ''' 判断端口是否被占用 :return: ''' flag = True self.dos_cmd = DosCmd() result = self.dos_cmd.excute_cmd_result('netstat -ano | findstr ' + str(port_num)) if len(result) > 0: flag = True else: flag = False return flag def create_port_list(self, start_port, device_list): ''' 生成可用端口 :param start_port: :param device_list: :return: ''' port_list = [] if device_list != None: while len(port_list) != len(device_list): if self.port_is_used(start_port) != True: port_list.append(start_port) start_port = start_port + 1 return port_list else: print('端口生成失败')
class Port: def __init__(self): self.dos = DosCmd() def port_is_used(self, port_num): """ 判断端口是否被占用 """ command = 'netstat -ano | findstr ' + str(port_num) result = self.dos.execute_cmd_result(command) if len(result) > 0: flag = True else: flag = False return flag def create_port_list(self, start_port, device_list): """start_port 4701 生成可用端口 @parameter start_port @parameter device_list """ port_list = [] if device_list is not None: while len(port_list) != len(device_list): if not self.port_is_used(start_port): port_list.append(start_port) start_port = start_port + 1 return port_list else: print "生成可用端口失败" return None
class Server: def __init__(self): #执行控制台的命令使用 self.dos = DosCmd() #获取设备devices的集合 self.device_list = self.get_devices() def get_devices(self): ''' 获取设备devices的集合 ''' devices_list = [] #执行adb devices命令来获取 devices list result_list = self.dos.excute_cmd_result('adb devices') #取出devicees存入devices_list中 if len(result_list) >= 2: for i in result_list: if 'List' in i: continue devices_info = i.split('\t') if devices_info[1] == 'device': devices_list.append(devices_info[0]) return devices_list else: return None
class Port: def prot_is_used(self, port_num): ''' 判断端口是否被占用 ''' flag = None self.dos = DosCmd() command = 'netstat -ano | findstr ' + port_num result = self.dos.excute_cmd_get_result(command) if len(result) > 0: flag = True else: flag = False return flag def create_port_list(self, start_prot, device_list): ''' 生成可以端口 @parameter start_prot #parameter device_list ''' port_list = [] print(device_list) if device_list != None: while len(port_list) != len(device_list): if self.prot_is_used(str(start_prot)) != True: port_list.append(start_prot) start_prot = start_prot + 1 return port_list else: print('生成可用端口失败') return None
class Port: def port_is_used(self,port_mun): ''' 判断端口是否被占用 ''' flag = None self.dos = DosCmd() command = "netstat -ano | findstr "+str(port_mun) result = self.dos.excute_cmd_result(command) if len(result)>0: flag = True else: flag = False return flag def create_post_list(self,start_post,device_list): ''' 生成可用端口 @parameter start_pos @parameter device_list ''' port_list = [] if device_list != None: while len(port_list) != len(device_list): if self.port_is_used(start_post) != True: port_list.append(start_post) start_post = start_post + 1 return port_list else: print "生成端口失败" return None
def get_devices(self): ''' 获取设备信息 ''' self.dos = DosCmd() devices_list = [] result_list = self.dos.excute_cmd_get_result('adb devices') if len(result_list) >= 2: for i in result_list: if 'List' in i: continue devices_info = i.split('\t') if devices_info[1] == 'device': devices_list.append(devices_info[0]) return devices_list else: return None
class Port: def port_is_used(self, port): self.dos = DosCmd() result = self.dos.excute_cmd('netstat -an | grep %s' % port) if len(result) > 0: flag = True else: flag = False return flag def create_port(self, start_port=4700, device_list=None): port_list = [] if len(device_list) > 0: while len(device_list) != len(port_list): if self.port_is_used(start_port) != True: port_list.append(start_port) start_port += 1 return port_list else: return '不存在可用的设备信息,无法生成appium端口'
class Port(object): def port_is_used(self, port_num): """ :param port_num: 断开 :return: 端口是非被占用,True被占用 False未被占用 """ self.dos = DosCmd() self.port_num = str(port_num) result = self.dos.execute_cmd_result("netstat -ano|findstr " + self.port_num) if len(result) > 0: return True else: return False def creat_port_list(self, start_port, device_list): """ 生成可用端口 :param start_port:开始端口 :param device_list:设备列表 :return: """ self.start_port = int(start_port) port_list = [] # if device_list is not None: if len(device_list) >= 0: while len(port_list) != len(device_list): if self.port_is_used(self.start_port) is not True: port_list.append(self.start_port) self.start_port += 1 return port_list else: print("生成可用端口失败") return None
class CreatePort: def __init__(self): self.dos = DosCmd() def port_is_used(self, port_num): """ 判断端口号是否被占用 :param port_num: 端口号 :return: """ flag = None command = 'netstat -ano | findstr ' + str(port_num) result = self.dos.excute_cmd_result(command) if len(result) > 0: flag = True else: flag = False return flag def create_port_list(self, start_port, device_list): """ 生成可用的端口号列表 :param start_port: 开始端口号 :param device_list: 设备列表 :return: """ if device_list == None: print('设备列表为空,无法生成端口号') return None else: port_list = [] while len(port_list) != len(device_list): if not self.port_is_used(start_port): port_list.append(start_port) start_port = int(start_port) + 1 return port_list
def __init__(self): self.dos = DosCmd() self.device_list = self.get_device() # self.command_list = self.create_command_list() self.write_file = WriteUserCommand()
def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.write_file = WriteUserCommand()
class Server(object): def __init__(self): self.dos = DosCmd() self.device_list = self.get_device() # self.command_list = self.create_command_list() self.write_file = WriteUserCommand() def get_device(self): """ :return: 设备信息 """ device_list = [] result_list = self.dos.execute_cmd_result("adb devices") if len(result_list) > 1: for i in result_list: if 'List' in i: continue else: device_info = i.split("\t") if device_info[1] == 'device': device_list.append(device_info[0]) return device_list else: return None def create_port_list(self, start_port): """ 创建可用端口 :return: """ port = Port() port_list = port.creat_port_list(start_port, self.device_list) return port_list def create_command_list(self, i): # appium -p 4700 -bp 4701 -U 127.0.0.1:21503 command_list = [] appium_post_list = self.create_port_list(4700) bootstrap_post_list = self.create_port_list(5700) device_list = self.device_list # for i in range(len(device_list)): command = "appium -p " + str(appium_post_list[i]) + " -bp " + str( bootstrap_post_list[i]) + " -U " + str( device_list[i]) + " --no-reset --session-override" # 带日志 # command = "appium -p " + str(appium_post_list[i]) + " -bp " + str(bootstrap_post_list[i]) + " -U " + str( # device_list[i]) + " --no-reset --session-override --log D:/test02.log" command_list.append(command) self.write_file.write_data(i, appium_post_list[i], bootstrap_post_list[i], device_list[i]) return command_list def start_server(self, i): self.start_list = self.create_command_list(i) self.dos.execute_cmd(self.start_list[0]) def main(self): thread_list = [] self.kill_server() self.write_file.clear_data() for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_server, args=(i, )) thread_list.append(appium_start) print("Appium Server: %d start ok!" % i) # appium_start.start() for t in thread_list: t.start() # 时间太短会导致已经开始运行测试套件,但是Appium未完全启动 time.sleep(25) def kill_server(self): server_list = self.dos.execute_cmd_result( "tasklist | findstr node.exe") if len(server_list) > 0: self.dos.execute_cmd("taskkill -F node.exe")
class Server: def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.write_file = WriteUserCommand() def get_devices(self): ''' 获取设备信息 ''' devices_list = [] result_list = self.dos.excute_cmd_result('adb devices') if len(result_list) >= 2: for i in result_list: if 'list' in i: continue devices_info = i.split('\t') if devices_info[1] == 'device': # list index out of range devices_list.append(devices_info[0]) return devices_list else: return None def create_port_list(self, start_post): ''' 创建可用端口 ''' port = Port() port_list = [] port_list = port.create_post_list(start_post, self.device_list) return port_list def create_command_list(self, i): ''' 生成命令 ''' #appium -p 4700 -bp 4701 -U 127.0.0.1:21503 command_list = [] appium_post_list = self.create_port_list(4700) bootstrap_port_list = self.create_port_list(4900) device_list = self.device_list command = "appium -p " + str(appium_post_list[i]) + " -bp " + str( bootstrap_port_list[i] ) + " -U " + device_list[i] + " --no-reset --session-override" command_list.append(command) self.write_file.write_data(i, device_list[i], str(bootstrap_port_list[i]), str(appium_post_list[i])) return command_list def start_server(self, i): #启动服务 self.start_list = self.create_command_list(i) print self.start_list self.dos.excute_cmd(self.start_list[0]) def kill_server(self): server_list = self.dos.excute_cmd_result('tasklist | find "node.exe"') if len(server_list) > 0: self.dos.excute_cmd('tasklist -f -PID node.exe') def main(self): self.kill_server() self.write_file.clear_data() for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_server, args=(i, )) appium_start.start()
class Server: def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.write_file = WriteUserCommand() def get_devices(self): ''' 获取设备信息 ''' devices_list = [] result_list = self.dos.excute_cmd_result('adb devices') if len(result_list) >= 2: for i in result_list: if 'List' in i: continue devices_info = i.split('\t') if devices_info[1] == 'device': devices_list.append(devices_info[0]) return devices_list else: return None def create_port_list(self, start_port): ''' 创建可用端口 ''' port = Port() port_list = [] port_list = port.create_port_list(start_port, self.device_list) return port_list def create_command_list(self, i): ''' 生成命令 ''' #appium -p 4700 -bp 4701 -U 127.0.0.1:21503 command_list = [] appium_port_list = self.create_port_list(4700) bootstrap_port_list = self.create_port_list(4900) device_list = self.device_list command = "appium -p " + str(appium_port_list[i]) + " -bp " + str( bootstrap_port_list[i] ) + " -U " + device_list[ i] + " --no-reset --session-override --log E:/Teacher/Imooc/AppiumPython/log/test02.log" #appium -p 4723 -bp 4726 -U 127.0.0.1:62001 --no-reset --session-override --log E:/Teacher/Imooc/AppiumPython/log/test01.log command_list.append(command) self.write_file.write_data(i, device_list[i], str(bootstrap_port_list[i]), str(appium_port_list[i])) return command_list def start_server(self, i): ''' 启动服务 ''' self.start_list = self.create_command_list(i) print self.start_list self.dos.excute_cmd(self.start_list[0]) def kill_server(self): server_list = self.dos.excute_cmd_result('tasklist | find "node.exe"') if len(server_list) > 0: self.dos.excute_cmd('taskkill -F -PID node.exe') def main(self): thread_list = [] self.kill_server() self.write_file.clear_data() for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_server, args=(i, )) thread_list.append(appium_start) for j in thread_list: j.start() time.sleep(25)
class Server: def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.appium_port_list = self.create_port(4700, self.device_list) self.bootstrap_port_list = self.create_port(5700, self.device_list) def get_devices(self): ''' 获取设备信息 :return: ''' devices_list = [] result_list = self.dos.excute_cmd('adb devices') if len(result_list) > 2: for i in result_list: if 'List' in i or 'device' not in i: continue devices_info = i.split('\t') if 'device' in devices_info[1]: devices_list.append(devices_info[0]) return devices_list else: return None def port_is_used(self, port): self.dos = DosCmd() result = self.dos.excute_cmd('netstat -an | grep %s' % port) if len(result) > 0: flag = True else: flag = False return flag def create_port(self, start_port=4700, device_list=None): port_list = [] if len(device_list) > 0: while len(device_list) != len(port_list): if self.port_is_used(start_port) != True: port_list.append(start_port) start_port += 1 return port_list else: return '不存在可用的设备信息,无法生成appium端口' def create_command(self): ''' android 启动appium服务 appium -p 4700 -bp 4701 -u 168.98.34.12:1234 :return: ''' command_list = [] for i in range(len(self.appium_port_list)): command_list.append( 'appium -p %s -bp %s -U %s' % (self.appium_port_list[i], self.bootstrap_port_list[i], self.device_list[i])) return command_list def start_server(self, i): command_list = self.create_command() self.dos.excute_cmd(command_list[i]) def start1(self): for i in range(len(self.create_command())): appium_start = threading.Thread(target=self.start_server, args=(i, )) appium_start.start()
def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.appium_port_list = self.create_port(4700, self.device_list) self.bootstrap_port_list = self.create_port(5700, self.device_list)
class Server: ''' 获取设备信息 ''' def __init__(self): self.write_file = WriteUserCommand() self.dos = DosCmd() self.device_list = self.get_devices() def get_devices(self): device_list = [] result_list = self.dos.excute_cmd_result('adb devices') if len(result_list) > 1: for i in result_list: if 'List' in i: continue device_info = i.split('\t') if device_info[1] == 'device': device_list.append(device_info[0]) return device_list else: return None def create_port_list(self, start_port): port = Port() port_list = [] port_list = port.create_port_list(start_port, self.device_list) return port_list def create_command_list(self,i): ''' appium -p 4700 -bp 4701 -U 127.0.0.1:62001 :return: ''' command_list = [] appium_port_list = self.create_port_list(4700) bootstrap_port_list = self.create_port_list(4800) deivce_list = self.device_list self.write_file.post_value(i,bootstrap_port_list[i],deivce_list[i],appium_port_list[i]) command = 'appium -p ' + str(appium_port_list[i]) + ' -bp ' + str(bootstrap_port_list[i]) + ' -U ' + \ deivce_list[i] + ' --no-reset --session-override' command_list.append(command) if len(command_list) == 0: print('当前无可用设备') else: print(command_list) return command_list # 启动程序服务 def start_server(self, i): self.start_list = self.create_command_list(i) self.dos.excute_cmd(self.start_list[0]) # 杀掉进程 def kill_server(self): server_list = self.dos.excute_cmd_result('tasklist | find "node.exe"') if len(server_list) > 0: self.dos.excute_cmd('taskkill -F -PID node.exe') else: print('没有找到相关进程') # 主函数使用多线程去调用start_server def main_server(self): self.kill_server() self.write_file.clear_data() for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_server, args=(i,)) appium_start.start() time.sleep(5)
class Server: def __init__(self): self.dos = DosCmd() self.device_list = self.get_devices() self.write_file = WriteUserCommand() def get_devices(self): """ 获取设备信息 """ devices_list = [] result_list = self.dos.execute_cmd_result('adb devices') if len(result_list) >= 2: for i in result_list: if 'List' in i: continue devices_info = i.split('\t') if devices_info[1] == 'device': devices_list.append(devices_info[0]) return devices_list else: return None def create_port_list(self, start_port): """ 创建可用端口 """ port = Port() port_list = port.create_port_list(start_port, self.device_list) return port_list def create_command_list(self, i): """ 生成命令 """ command_list = [] appium_port_list = self.create_port_list(4700) bootstrap_port_list = self.create_port_list(4900) device_list = self.device_list # noinspection PyTypeChecker command = "appium -p " + str(appium_port_list[i]) + " -bp " + str(bootstrap_port_list[i]) + " -U " + \ device_list[i] + " --no-reset --session-override --log " + PATH("../../build/logs/appium-") + "" + str(i + 1) + ".log" command_list.append(command) self.write_file.write_data(i, device_list[i], str(bootstrap_port_list[i]), str(appium_port_list[i])) return command_list def start_server(self, i): """ 启动服务 """ self.start_list = self.create_command_list(i) print self.start_list self.dos.execute_cmd(self.start_list[0]) def kill_server(self): server_list = self.dos.execute_cmd_result('tasklist | find "node.exe"') if len(server_list) > 0: self.dos.execute_cmd('taskkill -F -PID node.exe') def main(self): thread_list = [] self.kill_server() self.write_file.clear_data() for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_server, args=(i, )) thread_list.append(appium_start) for j in thread_list: j.start() time.sleep(25)
class Server: def __init__(self): self.dos = DosCmd() self.port = CreatePort() self.write_yaml = WriteUserconfigCommand() self.device_list = self.get_devices() self.start_list = self.start_appium_command_list() def get_devices(self): """ 获取设备信息 :return: """ command = 'adb devices' result_list = self.dos.excute_cmd_result(command) # print(result_list) devices_list = [] if len(result_list) > 1: for i in result_list: if '\tdevice' in i: devices_info = i.split('\tdevice') devices_list.append(devices_info[0]) return devices_list else: return None def create_port(self, start_port): """ 生成端口号列表 :param start_port: :return: """ port = CreatePort() port_list = port.create_port_list(start_port, self.device_list) return port_list def start_appium_command_list(self): # appium -p 4700 -bp 4701 -U 4f368950 """ 生成启动appium服务的命令列表集合 :return: """ # 先清空掉yaml文件 然后再写入 self.write_yaml.clear_data() command_list = [] appium_port_list = self.create_port(4700) bootstrap_port_list = self.create_port(4900) if self.device_list is not None: for i in range(len(self.device_list)): command = 'appium -p ' + str(appium_port_list[i]) + ' -bp ' + str( bootstrap_port_list[i]) + ' -U ' + str(self.device_list[i]) + ' --no-reset --session-override --log D:/code/log/test01.log --local-timezone ' command_list.append(command) self.write_yaml.write_data_to_yaml(i, self.device_list[i], bootstrap_port_list[i], appium_port_list[i]) return command_list def start_appium_server(self, i): """ 通过启动命令集合 执行单个启动服务命令 :param i: :return: """ self.dos.excute_cmd(self.start_list[i]) def kill_appium_server(self): find_command = 'tasklist | find "node.exe"' server_list = self.dos.excute_cmd_result(find_command) if len(server_list) > 1 : kill_command = 'taskkill -F -PID node.exe' self.dos.excute_cmd(kill_command) def main(self): """ 使用多线程运行启动设备服务 :return: """ # 先把当前的进程全部kill掉 self.kill_appium_server() # 多线程开始启动服务 for i in range(len(self.device_list)): appium_start = threading.Thread(target=self.start_appium_server, args=(i,)) appium_start.start() time.sleep(10)
def __init__(self): #执行控制台的命令使用 self.dos = DosCmd() #获取设备devices的集合 self.device_list = self.get_devices()
def __init__(self): self.dos = DosCmd() self.port = CreatePort() self.write_yaml = WriteUserconfigCommand() self.device_list = self.get_devices() self.start_list = self.start_appium_command_list()
def __init__(self): self.dos = DosCmd()
def __init__(self): self.dos = DosCmd() self.device_list = self.get_device_list() self.opera_yaml = OperaYaml()