Exemple #1
0
    def add_test_results(self, test_run_list: list, suite_runs: list):
        """
        :param test_run_list: a list of runs that were generated in the test plan creation
        :param suite_runs: a list of suite objects
        :return: None

        status_id = 1 for Passed
        status_id = 5 for Failed
        status_id = 2 for Blocked
        """
        for run in test_run_list:
            if isinstance(run, dict):
                run_id = run.get("id")
            else:
                logger.error("Invalid API response.")
                break
            for suite in suite_runs:
                object_list = []
                results = {}
                if isinstance(suite, TestSuiteMap):
                    if suite.suite_name in run.get("name"):
                        suite_id_tests = suite.test_results_list
                        for test in suite_id_tests:
                            payload = {}
                            test_results = test.get_test_status()

                            if (test.blocked_by) is not None:
                                payload["status_id"] = 2
                                payload["defects"] = str(test.blocked_by)
                            elif test_results.__contains__(
                                    "FAILED") or test_results.__contains__(
                                        "ERROR"):
                                payload["status_id"] = 5
                            else:
                                payload["status_id"] = 1
                            # payload['comment'] = complete_test_assert
                            payload["case_id"] = test.test_case_id
                            object_list.append(payload)
                            results["results"] = object_list

                        if run_id is not None:
                            try:
                                self.client.send_post(
                                    "add_results_for_cases/%s" % run_id,
                                    results)
                            except Exception:
                                raise TestRailError(
                                    "Failed to Update Test_Rail run %s",
                                    run.get("name"))

                            else:
                                logger.info(
                                    "Successfully added test results in test run name: %s"
                                    % run.get("name"))
                        else:
                            raise TestRailError("Invalid run_id")
                    else:
                        continue
                else:
                    raise TestRailError("Invalid API Response")
Exemple #2
0
def report_test_results(app_test):
    """
           :param app_test: Target object that contains test runned
           :return: none

    """

    logger.info(
        " --------------------------------------------------------- " +
        Color.BLUE + "Starting Test Rail report:" + Color.END +
        " ----------------------------------------------------------\n")
    test_rail_tests = create_testrail_test_map(app_test.completed_tests)
    test_rail_report = TestRail()
    test_rail_report.create_test_plan(app_test.values["fx_build_id"],
                                      app_test.values["fx_version"],
                                      test_rail_tests)
Exemple #3
0
    def create_test_plan(self, build_id: str, firefox_version: str,
                         test_case_object_list: list):
        """Creates a Test Plan and Test Run for all suites that are mapped in a project.

        :param build_id:  firefox_build (Ex 20180704003137)
        :param firefox_version: actual version of Firefox (Ex 61.03)
        :param test_case_object_list: a list of TestRailTests objects
        :return: None
        """
        self.run_name = self.generate_test_plan_name(firefox_version)
        data_array = []
        payload = {}
        suite_runs = self.generate_test_suite_collection_objects(
            test_case_object_list)
        for suite in suite_runs:
            data = {}
            test_case_ids = []
            data["suite_id"] = suite.suite_id
            data["name"] = suite.suite_name
            data["include_all"] = False
            for test_case in suite.test_results_list:
                if isinstance(suite, TestSuiteMap):
                    if isinstance(test_case, TestRailTests):
                        case_id = test_case.test_case_id
                        test_case_ids.append(case_id)
            data["case_ids"] = test_case_ids
            data_array.append(data)

        payload["name"] = self.run_name
        payload["entries"] = data_array
        payload["description"] = self.generate_run_description(
            build_id, firefox_version)

        project_id = self.get_project_id(self.project_name)

        try:
            test_plan_api_response = self.client.send_post(
                "add_plan/%s" % project_id, payload)
        except Exception:
            raise TestRailError("Failed to create Test Rail Test Plan")

        else:
            logger.info("Test plan %s was successfully created" %
                        self.run_name)
            entries_list = test_plan_api_response.get("entries")
            test_run_list = []
            if isinstance(entries_list, list):
                for test_run_entry in entries_list:
                    run = test_run_entry
                    if isinstance(run, dict):
                        run_object_list = run.get("runs")
                        if isinstance(run_object_list, list):
                            for run_object in run_object_list:
                                test_run = run_object
                                test_run_list.append(test_run)
                        else:
                            raise TestRailError("Invalid object format")
                    else:
                        raise TestRailError("Invalid object format")
            else:
                raise TestRailError("Invalid API Response format")

            self.add_test_results(test_run_list, suite_runs)
Exemple #4
0
 def __init__(self):
     logger.info("Starting TestRail reporting.")
     self.test_rail_url = get_config_property("Test_rail", "test_rail_url")
     self.client = api_client.APIClient(self.test_rail_url)
     self.client.user = get_config_property("Test_rail", "username")
     self.client.password = get_config_property("Test_rail", "password")
 def __init__(self):
     logger.info('Starting TestRail reporting.')
     self.test_rail_url = get_config_property('Test_rail', 'test_rail_url')
     self.client = api_client.APIClient(self.test_rail_url)
     self.client.user = get_config_property('Test_rail', 'username')
     self.client.password = get_config_property('Test_rail', 'password')