def start_for_task(plan: PlanModel): # 从测试计划中获取需要测试的页面 page_data = service.find_selected_pages_by_plan(plan) if len(page_data) == 0: return make_error_response('请先在`{0}`中选择要测试的页面'.format(plan.name)) # 获取页面的数据和测试方法的参数 for page_data_item in page_data: method_data_list = [] for d in page_data_item['method_data']: for method_data in d['data']: method_data_list.append(method_data) plan_data_cover_page_data(plan.data, page_data_item['data'], method_data_list) # 随机分配一个任务id task_id = random_id() device = Device(data.platform, data.ip, data.port, data.device_id) app_info = AppInfo(data.app_id) task = Task(session_id, group_id, task_id, plan.plan_id, plan.name, device, app_info, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), page_data) # 设置为等待测试状态 task.wait() groups.append(task)
def get_step_by_task(self, task: Task): """ 获取该任务的测试步骤 :param task: :return: """ log = self.__db.find(task_db_name, task.get_step_table_name(), None) return log
def append_step_by_task(self, task: Task, log): """ 追加该任务的测试步骤 :param task: :param log: :return: """ self.__db.append(task_db_name, task.get_step_table_name(), log + "\n")
def find_task_group_by_group_id(self, group_id) -> List[Task]: """ 查找任务组通过任务组id :param group_id: :return: """ group_task_obj = [] group_task = self.__db.find_from_db_and_cover_json( task_db_name, group_id, []) for item in group_task: group_task_obj.append(Task.parse(item)) return group_task_obj
def start_test_for_task(self, task: Task): """ 开始测试,并通知服务器 :param task: :return: """ try: pages = [] for page_info in task.page_data: pages.append( PageData( import_class(page_info['path'], page_info['name']), page_info['path'], page_info['data'], page_info['method_data'])) dev = task.device if dev.platform == 'Android': app = AndroidApp(task.app.app_id, task.app.version_name, task.app.version_code, task.app.app_url) else: app = IOSApp(task.app.app_id) task.report_url = app.set_client_task(self, task) t = TaskThread(task, app.start_test, pages, dev.ip, dev.port, dev.device_id) t.setName(task.device.platform + "/" + task.name + "/" + task.task_id) app.client_thread = t self.runningThreads.append(t) self.runningTask.append(task) self.http.report_run(task) t.start() except Exception as e: print(e) traceback.print_exc() self.stop_test_for_task(task)