def create_port_list(self, start_port): """ 创建可用的端口 :return: """ port = Port() port_list = port.get_ports(start_port, len(self.uuid_list)) return port_list
def create_port_list(self, start_port): """ 创建可用端口 :param start_port: :return: """ port = Port() port_list = [] port_list = port.create_port_list(start_port, self.device_list) return port_list
def andriod_driver(cls): cmd_result = DosCmd() port_check = Port() # write_file = WriteUserCommand() # deviceName = write_file.get_value('user_info_'+str(i), 'deviceName') # port = write_file.get_value('user_info_'+str(i), 'port') # Initialization = os.environ["Initialization"] caps = {} caps["platformName"] = "android" # caps["deviceName"] = "10.1.14.146:5555" # caps["deviceName"] = os.environ["UDID"] caps["deviceName"] = "37KNW18614022787" # caps["deviceName"] = deviceName caps["appPackage"] = "com.xiaomi.hm.health" caps["appActivity"] = "activity.StartUpActivity" caps["autoGrantPermissions"] = True caps["showChromedriverLog"] = True caps["noReset"] = True Initialization = False if Initialization == True: caps["skipServerInstallation"] = False caps["skipDeviceInitialization"] = False else: caps["skipServerInstallation"] = True caps["skipDeviceInitialization"] = True caps["automationName"] = "UiAutomator2" caps["newCommandTimeout"] = "600" if caps["deviceName"] == "37KNW18614022787": cls.start_docker_server = cmd_result.excute_cmd_result( "sudo docker run --privileged -d -p" + " 4723" + ":4723 --name" + " 37KNW18614022787" + " appium/appium") cls.driver = webdriver.Remote( "http://10.1.18.116:" + "4723" + "/wd/hub", caps) cls.connect_appium_server = cmd_result.excute_cmd_result( "sudo docker exec -i" + " 37KNW18614022787" + " adb connect" + " 37KNW18614022787") else: cls.start_docker_server = cmd_result.excute_cmd_result( "sudo docker run --privileged -d -p" + " 4724" + ":4723 --name" + " 4ad326fc" + " appium/appium") cls.driver = webdriver.Remote( "http://10.1.18.116:" + "4724" + "/wd/hub", caps) cls.connect_appium_server = cmd_result.excute_cmd_result( "sudo docker exec -i" + " 4ad326fc" + " adb connect" + " 4ad326fc") # i = 4723 # check_port = True # while check_port: # cls.check_port = port_check.port_is_used(i) # i=i+1 # port=i # cls.start_docker_server = cmd_result.excute_cmd_result("sudo docker run --privileged -d -p"+ str(port)+":4723 --name"+"37KNW18614022787" +"appium/appium") # else: # port=i # cls.start_docker_server = cmd_result.excute_cmd_result("sudo docker run --privileged -d -p"+ str(port)+":4723 --name"+"37KNW18614022787" +"appium/appium") #self.start_docker_server = cmd_result.excute_cmd_result("sudo docker run --privileged -d -p"+ port+":4723 --name $UDID appium/appium") #cls.driver = webdriver.Remote("http://10.1.18.116:"+str(port)+"/wd/hub",caps) #cls.connect_appium_server = cmd_result.excute_cmd_result("sudo docker exec -i"+"37KNW18614022787" +"adb connect"+"37KNW18614022787" ) # cls.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",caps) cls.driver.implicitly_wait(5) return MainPage(cls.driver)
def create_port_list(self, start_port): """获取port""" p = Port() port_list = p.create_port_list(start_port, self.get_devices()) return port_list
def __init__(self): self.cmd = DOScmd() self.port = Port() self.write_file = WriteUserCommand() self.device_list = self.get_devices()
class Server: def __init__(self): self.cmd = DOScmd() self.port = Port() self.write_file = WriteUserCommand() self.device_list = self.get_devices() def get_devices(self): # """ # 通过adb devices命令查询当前PC所连接的设备数量,并将查询的设备信息储存为一个list # """ devices_list = [] result_list = self.cmd.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]) else: print("找不到已连接设备") devices_list = None return devices_list def create_command_list(self, i, start_port, start_bootstrap_port): # """ # 拼接生成Appium的启动命令 # start_port:-p后接的起始端口值 # start_bootstrap_port:-bp后接的起始端口值 # """ command_list = [] if self.device_list != None: t = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.time())) port_list = self.port.create_port_list(start_port, self.device_list) # print(port_list) bootstrap_port_list = self.port.create_port_list( start_bootstrap_port, self.device_list) #拼接Appium启动命令 command = "appium -p {} -bp {} -U {} --no-reset --session-override --log ../log/{}_log_{}".format( port_list[i], bootstrap_port_list[i], self.device_list[i], self.device_list[i], t) command_list.append(command) self.write_file.Write_data(i, self.device_list[i], port_list[i], bootstrap_port_list[i]) print(command_list) return command_list else: print('生成Appium启动命令失败') return None def start_server(self, i): #封装一个启动Appium的方法 start_list = self.create_command_list(i, 4700, 4900) self.cmd.excute_cmd(start_list[0]) def kill_server(self, process): #封装一个杀掉Appium进程的方法 server_list = self.cmd.excute_cmd_result( 'tasklist | find "{}"'.format(process)) # print(server_list) if len(server_list) > 0: self.cmd.excute_cmd("taskkill -F -PID {}".format(process)) def main(self): self.kill_server('node.exe') #清除进程 self.write_file.clear_data() #清除历史数据 for i in range(len(self.device_list)): # 通过多线程方法,同时启动多个Appium appium_start = threading.Thread(target=self.start_server, args=(i, )) appium_start.start() time.sleep(20)