Ejemplo n.º 1
0
    def tearDown(self):
        """
        pytest-specific code
        Be careful if a subclass of BaseCase overrides setUp()
        You'll need to add the following line to the subclass's tearDown():
        super(SubClassOfBaseCase, self).tearDown()
        """
        if self.is_pytest:
            if self.with_selenium:
                # Save a screenshot if logging is on when an exception occurs
                if self.with_testing_base and (sys.exc_info()[1] is not None):
                    test_id = "%s.%s.%s" % (self.__class__.__module__,
                                            self.__class__.__name__,
                                            self._testMethodName)
                    test_logpath = self.log_path + "/" + test_id
                    if not os.path.exists(test_logpath):
                        os.makedirs(test_logpath)
                    # Handle screenshot logging
                    log_helper.log_screenshot(test_logpath, self.driver)
                    # Handle basic test info logging
                    log_helper.log_test_failure_data(
                        test_logpath, self.driver, self.browser)
                    # Handle page source logging
                    log_helper.log_page_source(test_logpath, self.driver)

                # Finally close the browser
                self.driver.quit()
Ejemplo n.º 2
0
    def tearDown(self):
        """
        pytest-specific code
        Be careful if a subclass of BaseCase overrides setUp()
        You'll need to add the following line to the subclass's tearDown():
        super(SubClassOfBaseCase, self).tearDown()
        """
        if self.is_pytest:
            if self.with_selenium:
                # Save a screenshot if logging is on when an exception occurs
                if self.with_testing_base and (sys.exc_info()[1] is not None):
                    test_id = "%s.%s.%s" % (self.__class__.__module__,
                                            self.__class__.__name__,
                                            self._testMethodName)
                    test_logpath = self.log_path + "/" + test_id
                    if not os.path.exists(test_logpath):
                        os.makedirs(test_logpath)
                    # Handle screenshot logging
                    log_helper.log_screenshot(test_logpath, self.driver)
                    # Handle basic test info logging
                    log_helper.log_test_failure_data(
                        test_logpath, self.driver, self.browser)
                    # Handle page source logging
                    log_helper.log_page_source(test_logpath, self.driver)

                # Finally close the browser
                self.driver.quit()
Ejemplo n.º 3
0
 def __log_all_options_if_none_specified(self, test):
     """
     When testing_base is specified, but none of the log options to save are
     specified (basic_test_info, screen_shots, page_source), then save them
     all by default. Otherwise, save only selected ones from their plugins.
     """
     if ((not self.options.enable_plugin_basic_test_info)
             and (not self.options.enable_plugin_screen_shots)
             and (not self.options.enable_plugin_page_source)):
         test_logpath = self.options.log_path + "/" + test.id()
         log_helper.log_screenshot(test_logpath, test.driver)
         log_helper.log_test_failure_data(test_logpath, test.driver,
                                          test.browser)
         log_helper.log_page_source(test_logpath, test.driver)
Ejemplo n.º 4
0
 def __log_all_options_if_none_specified(self, test):
     """
     When testing_base is specified, but none of the log options to save are
     specified (basic_test_info, screen_shots, page_source), then save them
     all by default. Otherwise, save only selected ones from their plugins.
     """
     if ((not self.options.enable_plugin_basic_test_info) and
             (not self.options.enable_plugin_screen_shots) and
             (not self.options.enable_plugin_page_source)):
         test_logpath = self.options.log_path + "/" + test.id()
         log_helper.log_screenshot(test_logpath, test.driver)
         log_helper.log_test_failure_data(
             test_logpath, test.driver, test.browser)
         log_helper.log_page_source(test_logpath, test.driver)
Ejemplo n.º 5
0
 def tearDown(self):
     """
     pytest-specific code
     Be careful if a subclass of BaseCase overrides setUp()
     You'll need to add the following line to the subclass's tearDown():
     super(SubClassOfBaseCase, self).tearDown()
     """
     if self.page_check_failures:
         # self.process_checks() was not called after checks were made.
         # We will log those now here, but without raising an exception.
         exception_output = ''
         exception_output += "\n*** FAILED CHECKS FOR: %s\n" % self.id()
         for tb in self.page_check_failures:
             exception_output += "%s\n" % tb
         logging.exception(exception_output)
     if self.is_pytest:
         test_id = "%s.%s.%s" % (self.__class__.__module__,
                                 self.__class__.__name__,
                                 self._testMethodName)
         if self.with_selenium:
             # Save a screenshot if logging is on when an exception occurs
             if self.with_testing_base and (sys.exc_info()[1] is not None):
                 test_logpath = self.log_path + "/" + test_id
                 if not os.path.exists(test_logpath):
                     os.makedirs(test_logpath)
                 if ((not self.with_screen_shots) and
                         (not self.with_basic_test_info) and
                         (not self.with_page_source)):
                     # Log everything if nothing specified (if testing_base)
                     log_helper.log_screenshot(test_logpath, self.driver)
                     log_helper.log_test_failure_data(
                         test_logpath, self.driver, self.browser)
                     log_helper.log_page_source(test_logpath, self.driver)
                 else:
                     if self.with_screen_shots:
                         log_helper.log_screenshot(
                             test_logpath, self.driver)
                     if self.with_basic_test_info:
                         log_helper.log_test_failure_data(
                             test_logpath, self.driver, self.browser)
                     if self.with_page_source:
                         log_helper.log_page_source(
                             test_logpath, self.driver)
             # Finally close the browser
             self.driver.quit()
         if self.headless:
             if self.headless_active:
                 self.display.stop()
         if self.with_db_reporting:
             if sys.exc_info()[1] is not None:
                 self.__insert_test_result(constants.State.ERROR, True)
             else:
                 self.__insert_test_result(constants.State.PASS, False)
             runtime = int(time.time() * 1000) - self.execution_start_time
             self.testcase_manager.update_execution_data(
                 self.execution_guid, runtime)
         if self.with_s3_logging and (sys.exc_info()[1] is not None):
             """ After each testcase, upload logs to the S3 bucket. """
             s3_bucket = S3LoggingBucket()
             guid = str(uuid.uuid4().hex)
             path = "%s/%s" % (self.log_path, test_id)
             uploaded_files = []
             for logfile in os.listdir(path):
                 logfile_name = "%s/%s/%s" % (guid,
                                              test_id,
                                              logfile.split(path)[-1])
                 s3_bucket.upload_file(logfile_name,
                                       "%s/%s" % (path, logfile))
                 uploaded_files.append(logfile_name)
             s3_bucket.save_uploaded_file_names(uploaded_files)
             index_file = s3_bucket.upload_index_file(test_id, guid)
             print("\n\n*** Log files uploaded: ***\n%s\n" % index_file)
             logging.error(
                 "\n\n*** Log files uploaded: ***\n%s\n" % index_file)
             if self.with_db_reporting:
                 self.testcase_manager = TestcaseManager(self.database_env)
                 data_payload = TestcaseDataPayload()
                 data_payload.guid = self.testcase_guid
                 data_payload.logURL = index_file
                 self.testcase_manager.update_testcase_log_url(data_payload)
Ejemplo n.º 6
0
 def tearDown(self):
     """
     pytest-specific code
     Be careful if a subclass of BaseCase overrides setUp()
     You'll need to add the following line to the subclass's tearDown():
     super(SubClassOfBaseCase, self).tearDown()
     """
     if self.page_check_failures:
         # self.process_checks() was not called after checks were made.
         # We will log those now here, but without raising an exception.
         exception_output = ''
         exception_output += "\n*** FAILED CHECKS FOR: %s\n" % self.id()
         for tb in self.page_check_failures:
             exception_output += "%s\n" % tb
         logging.exception(exception_output)
     if self.is_pytest:
         test_id = "%s.%s.%s" % (self.__class__.__module__,
                                 self.__class__.__name__,
                                 self._testMethodName)
         if self.with_selenium:
             # Save a screenshot if logging is on when an exception occurs
             if self.with_testing_base and (sys.exc_info()[1] is not None):
                 test_logpath = self.log_path + "/" + test_id
                 if not os.path.exists(test_logpath):
                     os.makedirs(test_logpath)
                 if ((not self.with_screen_shots)
                         and (not self.with_basic_test_info)
                         and (not self.with_page_source)):
                     # Log everything if nothing specified (if testing_base)
                     log_helper.log_screenshot(test_logpath, self.driver)
                     log_helper.log_test_failure_data(
                         test_logpath, self.driver, self.browser)
                     log_helper.log_page_source(test_logpath, self.driver)
                 else:
                     if self.with_screen_shots:
                         log_helper.log_screenshot(test_logpath,
                                                   self.driver)
                     if self.with_basic_test_info:
                         log_helper.log_test_failure_data(
                             test_logpath, self.driver, self.browser)
                     if self.with_page_source:
                         log_helper.log_page_source(test_logpath,
                                                    self.driver)
             # Finally close the browser
             self.driver.quit()
         if self.headless:
             if self.headless_active:
                 self.display.stop()
         if self.with_db_reporting:
             if sys.exc_info()[1] is not None:
                 self.__insert_test_result(constants.State.ERROR, True)
             else:
                 self.__insert_test_result(constants.State.PASS, False)
             runtime = int(time.time() * 1000) - self.execution_start_time
             self.testcase_manager.update_execution_data(
                 self.execution_guid, runtime)
         if self.with_s3_logging and (sys.exc_info()[1] is not None):
             """ After each testcase, upload logs to the S3 bucket. """
             s3_bucket = S3LoggingBucket()
             guid = str(uuid.uuid4().hex)
             path = "%s/%s" % (self.log_path, test_id)
             uploaded_files = []
             for logfile in os.listdir(path):
                 logfile_name = "%s/%s/%s" % (guid, test_id,
                                              logfile.split(path)[-1])
                 s3_bucket.upload_file(logfile_name,
                                       "%s/%s" % (path, logfile))
                 uploaded_files.append(logfile_name)
             s3_bucket.save_uploaded_file_names(uploaded_files)
             index_file = s3_bucket.upload_index_file(test_id, guid)
             print "\n\n*** Log files uploaded: ***\n%s\n" % index_file
             logging.error("\n\n*** Log files uploaded: ***\n%s\n" %
                           index_file)
             if self.with_db_reporting:
                 self.testcase_manager = TestcaseManager(self.database_env)
                 data_payload = TestcaseDataPayload()
                 data_payload.guid = self.testcase_guid
                 data_payload.logURL = index_file
                 self.testcase_manager.update_testcase_log_url(data_payload)