def run_tests(self, tests_mapping): """ run testcases/testsuites data """ capture_message("start to run tests") self.test_path = tests_mapping.get("project_mapping", {}).get("test_path", "") if self.save_tests: utils.dump_json_file( tests_mapping, utils.prepare_log_file_abs_path(self.test_path, "loaded.json")) # parse tests self.exception_stage = "parse tests" parsed_testcases = parser.parse_tests(tests_mapping) parse_failed_testfiles = parser.get_parse_failed_testfiles() if parse_failed_testfiles: logger.warning("parse failures occurred ...") utils.dump_json_file( parse_failed_testfiles, utils.prepare_log_file_abs_path(self.test_path, "parse_failed.json")) if len(parsed_testcases) == 0: logger.error("failed to parse all cases, abort.") raise exceptions.ParseTestsFailure if self.save_tests: utils.dump_json_file( parsed_testcases, utils.prepare_log_file_abs_path(self.test_path, "parsed.json")) # add tests to test suite self.exception_stage = "add tests to test suite" test_suite = self._add_tests(parsed_testcases) # run test suite self.exception_stage = "run test suite" results = self._run_suite(test_suite) # aggregate results self.exception_stage = "aggregate results" self._summary = self._aggregate(results) # generate html report self.exception_stage = "generate html report" report.stringify_summary(self._summary) if self.save_tests: utils.dump_json_file( self._summary, utils.prepare_log_file_abs_path(self.test_path, "summary.json")) # save variables and export data vars_out = self.get_vars_out() utils.dump_json_file( vars_out, utils.prepare_log_file_abs_path(self.test_path, "io.json")) return self._summary
def run_tests(self, tests_mapping): """ run testcase/testsuite data """ capture_message("start to run tests") project_mapping = tests_mapping.get("project_mapping", {}) self.project_working_directory = project_mapping.get( "PWD", os.getcwd()) if self.save_tests: utils.dump_logs(tests_mapping, project_mapping, "loaded") # parse tests self.exception_stage = "parse tests" parsed_testcases = parser.parse_tests(tests_mapping) parse_failed_testfiles = parser.get_parse_failed_testfiles() if parse_failed_testfiles: logger.log_warning("parse failures occurred ...") utils.dump_logs(parse_failed_testfiles, project_mapping, "parse_failed") if len(parsed_testcases) == 0: logger.log_error("failed to parse all cases, abort.") raise exceptions.ParseTestsFailure if self.save_tests: utils.dump_logs(parsed_testcases, project_mapping, "parsed") # add tests to test suite self.exception_stage = "add tests to test suite" test_suite = self._add_tests(parsed_testcases) # run test suite self.exception_stage = "run test suite" results = self._run_suite(test_suite) # aggregate results self.exception_stage = "aggregate results" self._summary = self._aggregate(results) # generate html report self.exception_stage = "generate html report" report.stringify_summary(self._summary) if self.save_tests: utils.dump_logs(self._summary, project_mapping, "summary") # save variables and export data vars_out = self.get_vars_out() utils.dump_logs(vars_out, project_mapping, "io") return self._summary
def run_tests(self, tests_mapping): """ run testcase/testsuite data """ capture_message("start to run tests") project_mapping = tests_mapping.get("project_mapping", {}) self.project_working_directory = project_mapping.get( "PWD", os.getcwd()) if self.save_tests: utils.dump_logs(tests_mapping, project_mapping, "loaded") # parse tests self.exception_stage = "parse tests" parsed_testcases = parser.parse_tests(tests_mapping) print("解析后的测试用例数据集合{}".format(parsed_testcases)) parse_failed_testfiles = parser.get_parse_failed_testfiles() if parse_failed_testfiles: logger.log_warning("parse failures occurred ...") utils.dump_logs(parse_failed_testfiles, project_mapping, "parse_failed") if self.save_tests: utils.dump_logs(parsed_testcases, project_mapping, "parsed") # add tests to test suite self.exception_stage = "add tests to test suite" test_suite = self._add_tests(parsed_testcases) # run test suite self.exception_stage = "run test suite" results = self._run_suite(test_suite) # aggregate results self.exception_stage = "aggregate results" self._summary = self._aggregate(results) # generate html report self.exception_stage = "generate html report" report.stringify_summary(self._summary) if self.save_tests: utils.dump_logs(self._summary, project_mapping, "summary") return self._summary
def run_tests(self, tests_mapping): """ run testcase/testsuite data project_mapping = { "env": {"username": "******","password": "******"}, "PWD": "D:\\git_ligeit\\test_ucong", "functions": {}, "test_path": "D:\\git_ligeit\\test_ucong\\api\\财务管理\\服务中心银行流水\\汇款.yml" } parsed_testcases = [ { "config":{ "name":"/mgmt/store/checkBusinessAddressIsExist" }, "teststeps":[ { "name":"/mgmt/store/checkBusinessAddressIsExist", "request":{ "headers":{ "Authorization":"LazyString(${token_type} ${access_token})" }, "method":"GET", "params":{ "provinceName":"LazyString(${provinceName})", "cityName":"LazyString(${cityName})", "areaName":"LazyString(${areaName})", "streetName":"LazyString(${streetName})", "detailAddress":"LazyString(${detailAddress})" }, "url":"LazyString(${base_url}/mgmt/store/checkBusinessAddressIsExist)", "verify":true }, "variables":{ "provinceName":"广东省", "cityName":"广州市", "areaName":"海珠区", "streetName":"南州街道", "detailAddress":"广州市海珠区南洲街道新滘中路88号唯品同创汇6区东三街17号自编23号", "access_token":"LazyString(${ENV(access_token)})", "token_type":"LazyString(${ENV(token_type)})", "base_url":"LazyString(${ENV(base_url)})" }, "validate":[ "LazyFunction(equals(status_code, 200))" ] } ] } ] """ capture_message("start to run tests") project_mapping = tests_mapping.get("project_mapping", {}) self.project_working_directory = project_mapping.get( "PWD", os.getcwd()) #项目工作目录 if self.save_tests: utils.dump_logs(tests_mapping, project_mapping, "loaded") #转储日志 # parse tests self.exception_stage = "parse tests" # 用测试用例抽出来(变量已经按优先级处理正确),剩下LazyString(${token_type} ${access_token})未解析 parsed_testcases = parser.parse_tests(tests_mapping) parse_failed_testfiles = parser.get_parse_failed_testfiles() if parse_failed_testfiles: logger.log_warning("parse failures occurred ...") utils.dump_logs(parse_failed_testfiles, project_mapping, "parse_failed") if len(parsed_testcases) == 0: logger.log_error("failed to parse all cases, abort.") raise exceptions.ParseTestsFailure if self.save_tests: utils.dump_logs(parsed_testcases, project_mapping, "parsed") # add tests to test suite self.exception_stage = "add tests to test suite" # <unittest.suite.TestSuite tests= # [<unittest.suite.TestSuite tests=[<httprunner.api.TestSequense testMethod=test_0000_000>]>]> test_suite = self._add_tests(parsed_testcases) # run test suite self.exception_stage = "run test suite" results = self._run_suite(test_suite) # aggregate results总结果 self.exception_stage = "aggregate results" self._summary = self._aggregate(results) # generate html report self.exception_stage = "generate html report" report.stringify_summary(self._summary) if self.save_tests: utils.dump_logs(self._summary, project_mapping, "summary") # save variables and export data保存变量和导出数据 vars_out = self.get_vars_out() utils.dump_logs(vars_out, project_mapping, "io") return self._summary