def __set_window_variables(self):
        if self.__config_data.get_var(
                AutomationConstants.SMALL_WINDOW_LIMIT) is not None:
            self.set_small_window_limit(
                int(
                    self.__config_data.get_var(
                        AutomationConstants.SMALL_WINDOW_LIMIT)))

        self.set_maximize(
            InitUtils.set_bool_variable(AutomationConstants.MAXIMIZE_ON_START,
                                        self.__config_data))

        if (self.__config_data.get_var(AutomationConstants.WINDOW_HEIGHT)
                is not None and self.__config_data.get_var(
                    AutomationConstants.WINDOW_WIDTH) is not None):
            self.set_window_size(
                self.__config_data.get_var(AutomationConstants.WINDOW_HEIGHT),
                self.__config_data.get_var(AutomationConstants.WINDOW_WIDTH))
        elif self.__config_data.get_var(
                AutomationConstants.WINDOW_HEIGHT) is not None:
            self.set_window_size(
                self.__default_window_width,
                self.__config_data.get_var(AutomationConstants.WINDOW_HEIGHT))
        elif self.__config_data.get_var(
                AutomationConstants.WINDOW_WIDTH) is not None:
            self.set_window_size(
                self.__config_data.get_var(AutomationConstants.WINDOW_WIDTH),
                self.__default_window_height)
    def __get_device_argument(self, test_data_m: TestDataManager):
        device_argument = InitUtils.get_argument(AutomationConstants.DEVICE)

        if device_argument is None or not device_argument and self.__main_driver\
                and (self.__main_driver == AutomationConstants.MOBILE_APP
                     or self.__main_driver == AutomationConstants.MOBILE_WEB):
            device_argument = test_data_m.get_config_var(AutomationConstants.DEVICE)

        return device_argument
    def __get_platform_argument(self, test_data_m: TestDataManager):
        platform_argument = InitUtils.get_argument(AutomationConstants.PLATFORM)

        if platform_argument is None or not platform_argument and self.__main_driver \
                and (self.__main_driver == AutomationConstants.MOBILE_APP
                     or self.__main_driver == AutomationConstants.MOBILE_WEB):
            platform_argument = test_data_m.get_config_var(AutomationConstants.PLATFORM)

        return platform_argument
 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 __get_browser_argument(self, test_data_m: TestDataManager):
        browser_argument = InitUtils.get_argument(AutomationConstants.BROWSER)

        if browser_argument is None or not browser_argument and self.__main_driver \
                and (self.__main_driver == AutomationConstants.WEB
                     or self.__main_driver == AutomationConstants.MOBILE_WEB):
            browser_argument = test_data_m.get_config_var(AutomationConstants.BROWSER)

        return browser_argument
    def set_main_driver(self, config_data: DataObject):
        if self.__main_driver is None:
            self.__main_driver = InitUtils.get_main_driver_from_properties()

            if (self.__main_driver is None or not self.__main_driver) and config_data is not None \
                    and config_data.get_var(AutomationConstants.MAIN_DRIVER) is not None \
                    and config_data.get_var(AutomationConstants.MAIN_DRIVER):
                self.__main_driver = config_data.get_var(AutomationConstants.MAIN_DRIVER)

            if self.__main_driver is None or not self.__main_driver:
                self.__main_driver = 'api'
    def get_csv_report(self, timestamp: str) -> list:
        result: list = None
        request = RequestHelper(self.__api_url + '/' + self.__project_id + '/csv/' + timestamp + '.csv')

        if request.get().status_code is 200:
            self.__logger.info('File was received correctly: ' + timestamp + '.csv')
            result = InitUtils.get_result_matrix_from_csv_string(
                request.get_response_as_string().replace('\r\n', '\n'))
        else:
            self.__logger.error("File wasn't received: " + timestamp + '.csv')

        return result
    def get_result_matrix_from_api(self, test_data_m: TestDataManager):
        __result_matrix: list = None
        __get_csv: bool = InitUtils.get_bool_variable(AutomationConstants.GET_CSV, test_data_m.get_config_data())

        if __get_csv and self.__project_id is not None and self.__api_url is not None:
            __result_matrix = self.get_csv_report(test_data_m.get_timestamp())

        if __get_csv and self.__project_id is None:
            self.__logger.info('Project ID not declared')
        if __get_csv and self.__project_id is None:
            self.__logger.info('API URL not declared')

        return __result_matrix
    def get_csv_file(self, file_name: str):
        result: list = None
        file_name = file_name if file_name.endswith('.csv') else file_name + '.csv'
        request = RequestHelper(self.__api_url + '/' + self.__project_id + '/csvfile/' + file_name)

        if request.get().status_code is 200:
            self.__logger.info('File was received correctly' + file_name)
            result = InitUtils.get_result_matrix_from_csv_string(
                request.get_response_as_string().replace('\r\n', '\n'))
        else:
            self.__logger.error("File wasn't received")

        return result
示例#10
0
    def get_timestamp_driver(self, test_data_m: TestDataManager):
        timestamp_driver = ''

        if self.__main_driver == AutomationConstants.WEB or self.__main_driver == AutomationConstants.MOBILE_WEB:
            timestamp_driver = self.__get_browser_argument(test_data_m)

        if self.__main_driver == AutomationConstants.MOBILE_APP or self.__main_driver == AutomationConstants.MOBILE_WEB:
            device = InitUtils.get_str_variable(AutomationConstants.DEVICE, test_data_m.get_config_data())
            timestamp_driver = device if timestamp_driver is not None and timestamp_driver \
                else device + '.' + timestamp_driver

        if timestamp_driver is None or not timestamp_driver:
            timestamp_driver = 'api'

        return timestamp_driver
示例#11
0
    def update_test_finished(self, test_case: str):
        for i in range(len(self.__test_cases)):
            if test_case is self.__test_cases[i][0]:
                self.__test_cases[i][1][1] = self.__test_cases[i][1][1] + 1

        if self.get_tests_finished(test_case) is self.get_test_to_run(test_case):
            self.__logger.info('Last test execution from ' + str(self.get_test_to_run(test_case)))

            if InitUtils.get_bool_variable(AutomationConstants.SEND_CSV,
                                           self.get_test_data_manager(test_case).get_config_data()):
                self.send_all_csv_report()
        else:
            self.__logger.info(
                'Remaining executions ' + str(self.get_test_to_run(test_case) - self.get_tests_finished(
                    test_case)) + ' from ' + str(self.get_test_to_run(test_case)))
示例#12
0
    def apply_execution_filter(self, result_matrix: list, cases_matrix: list):
        execution_filter = InitUtils.get_argument(AutomationConstants.EXECUTION_FILTER)

        if execution_filter is not None and execution_filter:
            self.__logger.info('Applying execution filter (' + execution_filter + ')')
            remove_indexes = ArrayUtils.get_filters_indexes(execution_filter, result_matrix)

            for i in range(len(remove_indexes)):
                new_index = remove_indexes[i] - 1
                remove_indexes.pop(i)
                remove_indexes.insert(i, new_index)

            cases_matrix = ArrayUtils.remove_rows_containing(cases_matrix,
                                                             ArrayUtils.integer_array_to_string_array(remove_indexes),
                                                             1)
        return cases_matrix
示例#13
0
    def send_img_to_database(self, main_driver: str, file_name: str, image):

        send_img = InitUtils.get_argument(AutomationConstants.SEND_IMG)

        if image is not None and send_img is not None and send_img and strtobool(send_img):
            try:
                build_id = self.__project_id + self.__suite_name + (
                    '' if not main_driver else '.' + main_driver) + self.__initial_timestamp
                request = RequestHelper(
                    self.__api_url + '/' + self.__project_id + '/images/upload' + build_id + '/' + file_name + '.png')\
                    .add_param('Encoding', 'base64').set_send_file(name='imagefile', file_name=file_name + '.png',
                                                                   file_type='image/png', encode=True)
                if request.post().status_code is 201:
                    self.__logger.info('Image send correctly: ' + file_name)
                else:
                    self.__logger.info('Error sending image: ' + file_name)
            except Exception as e:
                self.__logger.error('Error sending image: ' + file_name)
示例#14
0
 def __assign_browser(self):
     if self.__suite_m.get_main_driver() == AutomationConstants.WEB:
         self.__browser = self.__assign_if_null(
             self.__browser, self.get_test_var(AutomationConstants.BROWSER))
         self.__browser = self.__assign_if_null(
             self.__browser,
             self.get_config_var(AutomationConstants.BROWSER))
         self.__browser = self.__assign_if_null(self.__browser,
                                                BrowserType.CHROME)
     elif self.__suite_m.get_main_driver() == AutomationConstants.MOBILE_APP \
             or self.__suite_m.get_main_driver() == AutomationConstants.MOBILE_WEB:
         self.__browser = self.__assign_if_null(
             self.__browser,
             InitUtils.get_argument(AutomationConstants.DEVICE))
         self.__browser = self.__assign_if_null(
             self.__browser, self.get_test_var(AutomationConstants.DEVICE))
         self.__browser = self.__assign_if_null(
             self.__browser,
             self.get_config_var(AutomationConstants.DEVICE))
示例#15
0
    def remove_mobile_emulation_cases(self, test_case: str, cases_matrix: list):
        result: list = None
        result_matrix: list = self.get_result_matrix(test_case)

        if cases_matrix is not None:
            result_matrix = ArrayUtils.remove_rows_containing(result_matrix,
                                                              BrowserType.MOBILE_EMULATION_BROWERS, 2)
            result = InitUtils.get_cases_matrix_from_result_matrix(result_matrix, test_case)
            result = self.apply_execution_filter(result_matrix, result)

            if len(cases_matrix) is 0:
                for i in range(len(self.__test_cases)):
                    if test_case is list(self.__test_cases[i].keys())[0]:
                        self.__test_cases.remove(i)
                        break
                self.__test_suite_object.pop(test_case)
            else:
                self.__test_suite_object[test_case] = {
                    list(self.__test_suite_object.get(test_case).keys())[0]: result_matrix}

        return result
示例#16
0
    def __set_driver_waits(self):
        if (not self.__config_data.get_var(AutomationConstants.WAIT_FOR_PAGE)
                or
            (InitUtils.get_argument(AutomationConstants.WAIT_FOR_PAGE) is None
             and InitUtils.get_argument(
                 AutomationConstants.WAIT_FOR_PAGE is not ''))):
            self.set_wait_for_page(
                InitUtils.set_bool_variable(AutomationConstants.WAIT_FOR_PAGE,
                                            self.__config_data))

        self.set_wait_for_angular(
            InitUtils.set_bool_variable(AutomationConstants.WAIT_FOR_ANGULAR,
                                        self.__config_data))
        self.set_wait_for_angular(
            InitUtils.set_bool_variable(AutomationConstants.WAIT_FOR_JQUERY,
                                        self.__config_data))

        timeout = InitUtils.get_argument(AutomationConstants.TIMEOUT)

        if timeout is not None and timeout is not '':
            self.__config_data.set_value(AutomationConstants.TIMEOUT, timeout)

        if self.__config_data.get_var(AutomationConstants.TIMEOUT) is not None:
            self.set_implicit_wait(
                int(self.__config_data.get_var(AutomationConstants.TIMEOUT)))
            self.set_script_wait(
                int(self.__config_data.get_var(AutomationConstants.TIMEOUT)))
            self.set_page_load_wait(
                int(self.__config_data.get_var(AutomationConstants.TIMEOUT)))
        else:
            if self.__config_data.get_var(AutomationConstants.IMPLICIT_WAIT):
                self.set_implicit_wait(
                    int(
                        self.__config_data.get_var(
                            AutomationConstants.IMPLICIT_WAIT)))

            if self.__config_data.get_var(AutomationConstants.SCRIPT_WAIT):
                self.set_script_wait(
                    int(
                        self.__config_data.get_var(
                            AutomationConstants.SCRIPT_WAIT)))

            if self.__config_data.get_var(AutomationConstants.PAGE_LOAD_WAIT):
                self.set_page_load_wait(
                    int(
                        self.__config_data.get_var(
                            AutomationConstants.PAGE_LOAD_WAIT)))
示例#17
0
    def __set_config_data_variables(self):
        self.set_report_path(
            self.__config_data.get_var(AutomationConstants.REPORT_PATH))

        self.__set_driver_waits()

        self.set_language(
            InitUtils.set_str_variable(AutomationConstants.DRIVER_LANGUAGE,
                                       self.__config_data))

        self.set_download_drivers(
            InitUtils.set_bool_variable(AutomationConstants.DRIVER_DOWNLOAD,
                                        self.__config_data))

        aux_port = InitUtils.get_str_variable(AutomationConstants.PORT,
                                              self.__config_data)

        if (not aux_port
                and (self.__driver_type == AutomationConstants.MOBILE_APP
                     or self.__driver_type == AutomationConstants.MOBILE_WEB)):
            aux_port = InitUtils.set_str_variable(
                AutomationConstants.MOBILE_PORT, self.__config_data)
        elif not aux_port:
            aux_port = InitUtils.set_str_variable(AutomationConstants.PORT,
                                                  self.__config_data)

        self.__config_data.set_value(AutomationConstants.PORT, aux_port)

        self.set_hub(
            InitUtils.set_str_variable(AutomationConstants.IP,
                                       self.__config_data), aux_port)
        self.set_remote(
            InitUtils.set_bool_variable(AutomationConstants.REMOTE_MODE,
                                        self.__config_data))

        self.__set_window_variables()
示例#18
0
    def initialize_test_objects(self, test_case: str, scenario_data_path: str=None, test_data_path: str=None,
                                global_data_path: str=None):
        self.__logger.info('Case: ' + test_case)
        cases_matrix = None
        result_matrix = None

        test_data_path = InitUtils.get_test_data_path(test_data_path)

        test_data_m: TestDataManager = InitUtils.initialize_test_data(test_data_path, scenario_data_path,
                                                                      global_data_path,
                                                                      AutomationConstants.CONFIGURATION_DATA)

        self.set_main_driver(test_data_m.get_config_data())
        self.add_browser_to_test_data(test_data_m)

        test_data_m.generate_timestamp(test_case, self.get_timestamp_driver(test_data_m))

        self.__report_path = test_data_m.get_report_path()
        test_data_m.set_config_var(AutomationConstants.REPORT_PATH, self.__report_path)

        self.set_case_variables(test_data_path, test_data_m)
        self.set_project_id(test_data_m.get_config_data())
        self.set_max_tries(test_data_m.get_config_data())
        self.set_api_url(test_data_m.get_config_data())

        self.__retry_on_fail = InitUtils.set_bool_variable(AutomationConstants.RETRY_ON_FAIL,
                                                           test_data_m.get_config_data())

        file_from_api: bool = False

        self.__special_case = test_data_m.get_daily_case()

        if 'continue' in test_data_m.get_daily_case():
            self.__logger.info('Continue daily')

            result_matrix = self.get_result_matrix_from_api(test_data_m)

            if result_matrix is not None:
                file_from_api = True

            if result_matrix is None and os.path.exists(
                    test_data_m.get_report_path() + test_data_m.get_timestamp() + '.csv'):
                self.__logger.info("Getting test data from report file '" + test_data_m.get_timestamp() + ".csv'")
                result_matrix = InitUtils.get_result_matrix_from_csv_file(
                    test_data_m.get_report_path() + test_data_m.get_timestamp() + '.csv')

            if result_matrix is not None:
                cases_matrix = InitUtils.get_cases_matrix_from_result_matrix(result_matrix, test_case)

        if cases_matrix is None:
            self.__logger.info('Creating ' + (
                'base test data' if test_data_path is None else "test data from '" + test_data_path + "'"))
            cases_matrix = InitUtils.get_cases_matrix_from_test_data(test_case, test_data_m.get_test_data().size())
            result_matrix = InitUtils.get_result_matrix_from_test_data(test_data_m.get_test_data(),
                                                                       test_data_m.get_case_variables())

        cases_matrix = self.apply_execution_filter(result_matrix, cases_matrix)

        self.add_test_objects(test_case, test_data_m, result_matrix, len(cases_matrix))

        self.__logger.info('Cases to run on this execution: ' + str(len(cases_matrix)) + (
            ' from ' + str(len(result_matrix) - 1) if len(cases_matrix) is not len(result_matrix) - 1 else ''))

        self.handle_no_cases_to_run_with_api(file_from_api, test_data_m, result_matrix, cases_matrix)

        return cases_matrix
示例#19
0
 def set_project_id(self, config: DataObject):
     if self.__project_id is None:
         self.__project_id = InitUtils.get_str_variable(AutomationConstants.PROJECT_ID, config)
示例#20
0
 def set_max_tries(self, config_data: DataObject):
     if StringUtils.is_number(InitUtils.set_str_variable(AutomationConstants.MAX_TRIES, config_data)):
         self.__max_tries = config_data.get_var(AutomationConstants.MAX_TRIES)
     else:
         config_data.set_value(AutomationConstants.MAX_TRIES, str(self.__max_tries))