def close(self): # 使用关闭node来关闭appium try: os.system('taskkill /F /IM node.exe') self.writer.write(self.writer.row, self.writer.clo, 'PASS') return True except Exception as e: self.writer.write(self.writer.row, self.writer.clo, 'FAIL') self.writer.write(self.writer.row, self.writer.clo + 1, '关闭appium失败') logger.error("关闭appium失败!") return False
def clear(self, locat): ''' 清空指定位置控件的内容 :param locat: 定位 :return: ''' try: self.__find_element(locat).click() self.writer.write(self.writer.row, self.writer.clo, 'PASS') except Exception as e: self.writer.write(self.writer.row, self.writer.clo, 'FAIL') logger.error('无法定位到该元素!') logger.exception(e)
def runappium(self, appiumPath, port, t): ''' 多线程启动appium :param appiumPath: appium安装路径 :param port: appium启动的端口号 :param time: 等待时间 :return: ''' # 执行cmd命令 def run(cmd): res = os.system(cmd) print('运行子线程') return res if port == '': self.port = '4723' self.port = port # 多线程执行 cmd = 'netstat -aon | findstr ' + port + ' | findstr LISTENING' result = run(cmd) self.writer.write(self.writer.row, self.writer.clo, 'FAIL') self.writer.write(self.writer.row, self.writer.clo + 1, '端口被占用') # 执行命令的结果0是端口被占用,1是端口未被占用 if result == 0: logger.error('端口被占用') return else: # 启动appium cmd = 'node ' + appiumPath + '\\resources\\app\\node_modules\\appium\\build\\lib\\main.js -p ' + port # cmd = 'ipconfig' th = threading.Thread(target=run, args=(cmd, )) print('运行主线程') th.start() self.writer.write(self.writer.row, self.writer.clo, 'PASS') try: t = int(t) except Exception as e: print(e) t = 5 time.sleep(t)
def save_close(self): if self.f is None: logger.error('error:txt文件打开时失败!') return self.f.close()
def write(self, connet): # 如果打开失败 if self.f is None: logger.error('error:txt文件打开时失败!') return self.f.write(str(connet))