def _write_to_file(self, html_node: HtmlElement, path):
        if html_node:
            try:
                FileUtils.write_file(path + ".html", html_node.to_string())

                self._debug_info("HTML created")
            except Exception as e:
                self._print_stack_trace(e)
 def handle_no_cases_to_run_with_api(self, file_from_api: bool, test_data_m: TestDataManager, result_matrix: list,
                                     cases_matrix: list):
     if not file_from_api and len(cases_matrix) is 0 and InitUtils.get_bool_variable(
             AutomationConstants.SEND_CSV, test_data_m.get_config_data()):
         self.send_all_csv_report()
     elif file_from_api and len(cases_matrix) is 0:
         os.makedirs(test_data_m.get_report_path(), exist_ok=True)
         FileUtils.write_matrix_to_csv_file(test_data_m.get_report_path() + test_data_m.get_timestamp() + '.cvs',
                                            result_matrix)
    def create_log_report(self):
        result: str = str()
        path: str = self.__report_path + '/' + self.__suite_name + 'ConsoleLogReport.txt'

        if os.path.exists(self.__report_path + '/' + self.__suite_name + 'ConsoleLogReport.txt'):
            file_text = FileUtils.read_file(path)
            result += '' if file_text is None else file_text

        for test_case_info in self.__test_cases:
            result += self.get_logs_from_all_threads(test_case_info)

        if result:
            FileUtils.write_file(path, result)
    def __save_exception_into_file(self, exception: str, __id: str):
        self.__logger.begin()

        try:
            os.makedirs(self.get_report_path() + '/' +
                        AutomationConstants.EXCEPTIONS_FOLDER,
                        exist_ok=True)

            FileUtils.write_file(
                self.get_report_path() + '/' +
                AutomationConstants.EXCEPTIONS_FOLDER + self.get_timestamp() +
                '.e' + __id + '.txt', exception)
        except IOError:
            self.__logger.error('Saving Exception into file')

        self.__logger.end()
    def __update_result_matrix(self):
        if self.__get_result_matrix() is not None:
            try:
                self.__logger.begin()

                info_string: str = self.get_test_data_manager(
                ).case_variables_to_string(self.__test_id)
                if info_string is not None:
                    info_string += ', '

                add_browser_to_matrix: bool = AutomationConstants.BROWSER in self.__get_result_matrix(
                )[0]

                browser_string = ("browser: " + self.__browser +
                                  ", " if self.__browser
                                  and add_browser_to_matrix else '')

                self.__logger.info(info_string + browser_string + "time: " +
                                   str(self.__duration) +
                                   (", report: " +
                                    str(self.__last_exception) if self.
                                    __last_exception and not self.__result ==
                                    AutomationConstants.TEST_SUCCESS else ''))

                self.__get_result_matrix()[int(self.__test_id) + 1] = \
                    self.__get_execution_result_array(add_browser_to_matrix)

                print(self.__get_result_matrix())

                self.__logger.info(
                    'Saving result as ' +
                    self.get_test_data_manager().get_timestamp() + '.csv')
                os.makedirs(self.get_report_path(), exist_ok=True)
                FileUtils.write_matrix_to_csv_file(
                    self.get_report_path() +
                    self.get_test_data_manager().get_timestamp() + '.csv',
                    self.__get_result_matrix())

                self.__suite_m.update_test_finished(self.__test_case)

                self.__logger.end()

            except IOError as e:
                self.__logger.print_stack_trace(e)
                self.__logger.end()
                raise IOError
    def join_dm_data(self, file_path):
        from main.automation.model.utils.FileUtils import FileUtils

        if file_path is not None and not os.path.isabs(file_path):
            file_path = AutomationConstants.RESOURCES_FOLDER + file_path
        __data_object: DataObject = DataObject(FileUtils.file_to_dm_data(file_path))

        return __data_object
    def _create_test_case_wrapper(self, timestamp: str, test_case: str, relevant_column: int) -> HtmlElement:
        wrapper = None
        final_path = self._report_path + timestamp + ".csv"

        if os.path.exists(final_path):
            wrapper = (HtmlElement("div")
                       .add_attr("id", test_case))

            self._data_matrix = FileUtils.csv_file_to_matrix(final_path)
            self._data_matrix = ArrayUtils.remove_rows_containing(self._data_matrix,
                                                                  AutomationConstants.TEST_UNDONE, -3)

            if len(self._data_matrix) > 1:
                try:
                    self._test_stats = self._initialize_dictionary(self._data_matrix)
                    self._column_cases_order: dict = self._get_column_order(self._data_matrix)

                    self._copy_images_folder(self._report_path, self._test_stats)

                    relevant_column = self._update_relevant_column(relevant_column)

                    results_dict = self._test_stats[self._data_matrix[0][-3]]

                    n_success = results_dict[AutomationConstants.TEST_SUCCESS][0]\
                        if AutomationConstants.TEST_SUCCESS in results_dict else 0
                    n_failures = results_dict[AutomationConstants.TEST_FAILURE][1]\
                        if AutomationConstants.TEST_FAILURE in results_dict else 0

                    wrapper_color = CsvToHtml._get_wrapper_color(n_success, n_failures)

                    wrapper.add_attr("class", "wrapper column accordion bg-light-" + wrapper_color)

                    wrapper.add_child(self._create_header(test_case, n_success, n_failures, wrapper_color))

                    accordion_content = (HtmlElement("section")
                                         .add_attr("class", "columns ac-content"))

                    self._add_relevant_tables(accordion_content, relevant_column)

                    if self._column_cases_order[AutomationConstants.RESULT]\
                            .__contains__(AutomationConstants.TEST_FAILURE):
                        accordion_content.add_child(
                            self._get_error_report_node(self._data_matrix, self._report_path, timestamp))

                    self._modify_accordion_content(accordion_content, timestamp, test_case, relevant_column)

                    wrapper.add_child(accordion_content)
                except Exception as e:
                    self._print_stack_trace(e)

            self._modify_wrapper_content(wrapper, timestamp, test_case, relevant_column)

        return wrapper
    def _translate_or_format(self, text):
        if self._translation_file:
            translation_object: DataObject = DataObject(
                FileUtils.file_to_m_data(AutomationConstants.RESOURCES_FOLDER + self._translation_file))

            if translation_object.get_var(text):
                result = translation_object.get_var(text)
            else:
                result = self._snake_case_to_natural(text)
        else:
            result = self._snake_case_to_natural(text)

        return result
Exemple #9
0
 def get_result_matrix_from_csv_string(csv_string: str):
     return FileUtils.csv_string_to_matrix(csv_string, True)
Exemple #10
0
    def get_result_matrix_from_csv_file(file_path):
        file_path = file_path if file_path.endswith(".csv") else file_path + ".csv"

        return FileUtils.csv_file_to_matrix(file_path)
 def variables_file_to_array(file_path):
     return FileUtils.variables_file_to_array(InteractionObject.get_path_with_resources(file_path))
 def json_file_to_d_m_data(file_path):
     return FileUtils.json_file_to_dm_data(InteractionObject.get_path_with_resources(file_path))
 def csv_file_to_d_m_data(file_path: str):
     return FileUtils.csv_file_to_dm_data(InteractionObject.get_path_with_resources(file_path))
    def add_suite_data_file(self, file_path: str, data_key: str):
        if file_path is not None and not os.path.isabs(file_path):
            file_path = AutomationConstants.RESOURCES_FOLDER + file_path

        data_object: DataObject = DataObject(FileUtils.file_to_dm_data(file_path))
        self.add_suite_data(data_object, data_key)
 def read_file(file_path: str):
     return FileUtils.read_file(InteractionObject.get_path_with_resources(file_path))
 def csv_file_to_matrix(file_path: str):
     return FileUtils.csv_file_to_matrix(InteractionObject.get_path_with_resources(file_path))
 def write_matrix_to_csv_file(file_path: str, matrix: list):
     FileUtils.write_matrix_to_csv_file(InteractionObject.get_path_with_resources(file_path), matrix)
    def matrix_to_d_m_data(matrix: list) -> DataObject:
        from main.automation.model.utils.FileUtils import FileUtils

        return DataObject(
            FileUtils.csv_string_to_m_data(
                ArrayUtils.matrix_to_string(matrix, '\n', ';')))
    def delete_file_from_report_folder(self, file_path: str):
        if not os.path.exists(file_path) and os.path.exists(self._user_s.get_report_path() + file_path):
            file_path = self._user_s.get_report_path() + file_path

        FileUtils.delete_file(file_path)
 def write_file(file_path: str, text: str):
     FileUtils.write_file(InteractionObject.get_path_with_resources(file_path), text)
 def set_case_variables(self, test_data_path: str, test_data_m: TestDataManager):
     if test_data_path is not None:
         test_data_m.set_case_variables(FileUtils.csv_file_to_matrix(test_data_path, True)[0])
     else:
         test_data_m.set_case_variables(['id'])
Exemple #22
0
    def add_dm_data_from_file(self, key: str, file_name: str):
        from main.automation.model.utils.FileUtils import FileUtils

        self.add_data(key, DataObject(FileUtils.csv_file_to_dm_data(file_name)))
        pass
 def append_to_file(file_path: str, text: str):
     FileUtils.append_to_file(InteractionObject.get_path_with_resources(file_path), text)