Esempio n. 1
0
 def test_config_ini_file(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     config_file.initialize(log_folder=ea_log_path)
     removeall(ea_log_path)
     tps_step = '1-5'
     ts_auto.ts_start(delay=5)
     ea_start(delay=15)
     passed = browser_auto.run_normal_test()
     time_sleep(20)
     ea_close()
     ts_closed = ts_auto.ts_close()
     try:
         self.assertTrue(passed, 'Browser Automation Failed!')
         self.assertTrue(ts_closed, 'TestStand close Failed!')
         self.assertTrue(os.path.exists(ea_log_file),
                         'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(
             lookup_keyword_in_ea_log(active_kwd_list, ea_log_file),
             'Not all the keywords were found in EA log!')
         self.assertTrue(
             lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file),
             'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(
             tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
Esempio n. 2
0
    def config_test(self,
                    opt,
                    inp_str,
                    veri_keywords=active_kwd_list,
                    expect_result=True):
        ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
        config_file.initialize(log_folder=ea_log_path)
        removeall(ea_log_path)
        logger = logging.getLogger("COSMO.config.login")
        tps_step = opt + ' = ' + inp_str
        logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN'))

        if opt != None:
            config_file.change_option('Server', opt, '"{}"'.format(inp_str))
        ea_start(delay=15)
        ea_close()
        try:
            self.assertTrue(os.path.exists(ea_log_file),
                            'EA log: {} not found!'.format(ea_log_file))
            self.assertTrue(
                expect_result == lookup_keyword_in_ea_log(
                    active_kwd_list, ea_log_file),
                'Expected result is {}, not satisfied!'.format(expect_result))
        except AssertionError as e:
            logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
            logger.critical(str(e))
        except Exception as e:
            logger.critical(
                tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
            logger.critical(str(e))
        else:
            logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
Esempio n. 3
0
 def test_config_ini_file(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     config_file.initialize(log_folder = ea_log_path)
     removeall(ea_log_path)
     tps_step = '1-5'
     ts_auto.ts_start(delay=5)
     ea_start(delay=15)
     passed = browser_auto.run_normal_test()
     time_sleep(20)
     ea_close()
     ts_closed = ts_auto.ts_close()
     try:
         self.assertTrue(passed, 'Browser Automation Failed!')
         self.assertTrue(ts_closed, 'TestStand close Failed!')
         self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
         self.assertTrue(lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
 def restart_time_test(self, opt, inp_str, veri_keywords=active_kwd_list, expect_result=True):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     config_file.initialize(log_folder = ea_log_path)
     removeall(ea_log_path)
     logger = logging.getLogger("COSMO.config.login")
     tps_step = opt + ' = ' + inp_str
     logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN'))
     if opt != None:
         config_file.change_option('Server', opt, '"{}"'.format(inp_str))
     ea_start(delay=15)
     time_gui_closed = time.time()
     logger.info('gui closed now.')
     ea_close()
     time_process_ended = time.time()
     logger.info('process is ended now.')
     time_result = time_process_ended - time_gui_closed
     try:
         self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(expect_result == lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Expected result is {}, not satisfied!'.format(expect_result))
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     finally:
         logger.critical('Seconds to restart EA is {}'.format(time_result))
Esempio n. 5
0
def stress_test(repeat_times = 10):
    ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
    logger.critical("Initialize Stress Test.")

    #ea_initialize_test(log_folder=ea_log_path)
    config_file.initialize(log_folder=ea_log_path)
    '''shutil.copy('ea/Configuration.ini', config_file)
    ea_start(delay=15)
    ea_click(item='file_name')
    ea_config('folder', ea_log_path)
    ea_close()'''

    logger.critical("Initialize Stress Test Finished.")

    cnt = 0
    passed_number = 0
    while cnt < repeat_times:
        cnt += 1

        logger.critical("Stress Test No.{} BEGIN.".format(cnt))
        removeall(ea_log_path)
        ea_start(delay=0)
        passed = browser_auto.run_normal_test()
        ea_close()

        try:
            assert passed, 'Browser Automation FAILED!'
            assert os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)
            assert lookup_keyword_in_ea_log(active_kwd_list + task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!'
        except AssertionError as e:
            logger.critical("Stress Test No.{} FAILED.".format(cnt))
            logger.critical(str(e))
        except Exception as e:
            logger.critical("Stress Test No.{} UNKOWN ERROR.".format(cnt))
            logger.critical(str(e))
        else:
            logger.critical("Stress Test No.{} PASSED.".format(cnt))
            passed_number += 1
        logger.critical('Pass rate till now is {}'.format(passed_number/cnt))

        if cnt%100 == 0:
            time_sleep(2)  #delete temp file too hurry might prevent firefox from closing
            removeall(r'C:\Users\msun\AppData\Local\temp')  #the files here could be too large, if running for hours
Esempio n. 6
0
 def test_config_ini_file(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     config_file.initialize(log_folder = ea_log_path)
     removeall(ea_log_path)
     tps_step = '1-5'
     ea_start(delay=5)
     if not ts_auto.ts_close():# todo: ts_close is not stable enough
         logger.critical('Close TestStand FAILED!')
     ea_close()
     try:
         self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(lookup_keyword_in_ea_log(shutdown_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
Esempio n. 7
0
 def test_config_ini_file(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     tps_step = '1-2'
     removeall(config_file)
     ea_start(handle_ts=False)
     try:
         with open(config_file, 'r') as f:
             self.assertTrue(len(f.read()) == 0, 'config file is not empty')
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     tps_step = '3'
     # test_items = ['server', 'username', 'password', 'project_area', 'adapter_name']
     # todo: cann't test password; encrypt make the file a mess, python could not read that file
     test_items = ['server', 'username', 'project_area', 'adapter_name']
     for i in test_items:
         t_i = 'test_' + i
         print(t_i)
         ea_config(i, t_i)
     ea_close()
     try:
         with open(config_file, 'r') as f:
             config_content = f.read()
         for i in test_items:
             t_i = 'test_' + i
             if i != 'password':
                 self.assertTrue(
                     t_i in config_content,
                     'content: {} could not be found'.format(t_i))
             else:
                 self.assertTrue(t_i not in config_content,
                                 'password is read directly')
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
Esempio n. 8
0
def initialize(server=default_server,
               username=default_username,
               password=default_password,
               project_area=default_project_area,
               adapter_name=default_adapter_name,
               resource_folder=default_resource_folder,
               log_folder=default_log_folder,
               remove_original_file=False):

    if not os.path.exists(config_path):
        os.makedirs(config_path)
    if not os.path.exists(config_file):
        f = open(config_file, 'w')
        f.close()
    shutil.copy('Configuration.ini', config_file)
    os.chmod(config_file, stat.S_IREAD | stat.S_IWRITE)
    if remove_original_file:
        removeall(config_file)
        with open(config_file, 'w') as f:
            pass

    change_option('Server', 'server address', '"{}"'.format(server))
    change_option('Server', 'username', '"{}"'.format(username))
    change_option(
        'Server', 'password',
        '"{}"'.format(password))  # this is the 'test' with encryption
    change_option('Server', 'projectarea', '"{}"'.format(project_area))

    change_option('Client', 'name', '"{}"'.format(adapter_name))
    change_option('Client', 'rootresourcefolder',
                  '"{}"'.format(resource_folder))
    change_option('Client', 'systemlogfolder', '"{}"'.format(log_folder))
    change_option('Client', 'systemlognamestyle', '"StaticName"')
    change_option('Client', 'connectatstartup', 'TRUE')
    # use the same adapter id to avoid adapter choose in webpage
    change_option('Do not touch items in this section', 'adapterid',
                  '"_hYzYFDFYEeOfmKniIK943w"')
Esempio n. 9
0
 def test_config_ini_file(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     config_file.initialize(log_folder=ea_log_path)
     removeall(ea_log_path)
     tps_step = '1-5'
     ea_start(delay=5)
     if not ts_auto.ts_close():  # todo: ts_close is not stable enough
         logger.critical('Close TestStand FAILED!')
     ea_close()
     try:
         self.assertTrue(os.path.exists(ea_log_file),
                         'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(
             lookup_keyword_in_ea_log(shutdown_kwd_list, ea_log_file),
             'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(
             tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
Esempio n. 10
0
def initialize(
        server = default_server,
        username = default_username,
        password = default_password,
        project_area = default_project_area,
        adapter_name = default_adapter_name,
        resource_folder = default_resource_folder,
        log_folder = default_log_folder,
        remove_original_file = False
        ):

    if not os.path.exists(config_path):
        os.makedirs(config_path)
    if not os.path.exists(config_file):
        f = open(config_file, 'w')
        f.close()
    shutil.copy('Configuration.ini', config_file)
    os.chmod( config_file, stat.S_IREAD | stat.S_IWRITE )
    if remove_original_file:
        removeall(config_file)
        with open(config_file, 'w') as f:
            pass


    change_option('Server', 'server address', '"{}"'.format(server))
    change_option('Server', 'username', '"{}"'.format(username))
    change_option('Server', 'password', '"{}"'.format(password)) # this is the 'test' with encryption
    change_option('Server', 'projectarea', '"{}"'.format(project_area))

    change_option('Client', 'name', '"{}"'.format(adapter_name))
    change_option('Client', 'rootresourcefolder', '"{}"'.format(resource_folder))
    change_option('Client', 'systemlogfolder', '"{}"'.format(log_folder))
    change_option('Client', 'systemlognamestyle', '"StaticName"')
    change_option('Client', 'connectatstartup', 'TRUE')
# use the same adapter id to avoid adapter choose in webpage
    change_option('Do not touch items in this section', 'adapterid', '"_hYzYFDFYEeOfmKniIK943w"')
Esempio n. 11
0
    ch2 = logging.StreamHandler(open(autotest_log_file,'at'))
    ch2.setLevel(logging.WARNING)
    ch2.setFormatter(logging.Formatter('%(asctime)s : %(levelname)s : %(message)s'))
    logger.addHandler(ch2)

    ch_debug = logging.StreamHandler(open(debug_log_file,'at'))
    ch_debug.setLevel(logging.DEBUG)
    ch_debug.setFormatter(logging.Formatter('%(asctime)s : %(levelname)s : %(message)s'))
    logger.addHandler(ch_debug)

    cnt = 0
    while cnt < TEST_REPEAT:
        cnt += 1
        logger.critical("Stress Test No.{} begin.".format(cnt))
        unittest.main(verbosity=2, exit=False)
        if cnt%100 == 0:
            time.sleep(2)  #delete temp file too hurry might prevent firefox from closing
            removeall(r'C:\Users\msun\AppData\Local\temp')  #the files here could be too large, if running for hours
    
    '''while 1:
        try:
            unittest.main(verbosity=2,exit=False)
        except:
            print("An exception is detected.")
            logging.warning("An exception is detected.")
            continue
        else:
            suc_cnt += 1
            print("Test {} successed.".format(suc_cnt))
            logging.info("Test {} successed.".format(suc_cnt))'''
Esempio n. 12
0
 def test_config_log(self):
     ea_log_path, ea_log_file, logger = initialize_test_folders(test_name)
     logger = logging.getLogger("COSMO.config.log")
     tps_name = 'Configurations of log file'
     # initialize
     tps_step = 'Initialize log path'
     logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN'))
     config_file.initialize(log_folder= ea_log_path)
     # step 1-2
     removeall(ea_log_path)
     tps_step = '1 - 2'
     logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN'))
     ea_start(delay=15)
     ea_close()
     try:
         self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     # step 3
     removeall(ea_log_path)
     tps_step = '3'
     logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN'))
     ea_start(delay=15)
     passed = browser_auto.run_normal_test()
     time_sleep(20)
     ea_close()
     try:
         self.assertTrue(passed, 'Browser Automation Failed!')
         self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
         self.assertTrue(lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     # step 4
     tps_step = '4'
     logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step))
     ea_log_path_exists = ea_log_path + 'exists\\'
     ea_log_file_step4 = os.path.join(ea_log_path_exists, 'system log.html')
     config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path_exists))
     removeall(ea_log_path)
     os.mkdir(ea_log_path_exists)
     ea_start(delay=15)
     ea_close()
     try:
         self.assertTrue(os.path.exists(ea_log_file_step4), 'EA log: {} not found!'.format(ea_log_file_step4))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step4), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     # step 5
     tps_step = '5'
     logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step))
     ea_log_path_not_exists = ea_log_path + 'not_exists\\'
     ea_log_file_step5 = os.path.join(ea_log_path_not_exists, 'system log.html')
     config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path_not_exists))
     removeall(ea_log_path)
     ea_start(delay=15)
     ea_close()
     try:
         self.assertTrue(os.path.exists(ea_log_file_step5), 'EA log: {} not found!'.format(ea_log_file_step5))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step5), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
     # step 6
     tps_step = '6'
     logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step))
     config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path))
     config_file.change_option('Client', 'systemlognamestyle', '"TimeStampedFilename"')
     removeall(ea_log_path)
     ea_start(delay=15)
     ea_close()
     try:
         validate_str = datetime.datetime.now().strftime('system log %Y-%m-%d ') + '*.html' 
         validate_str = ea_log_path + validate_str
         logger.debug('Validate string is {}'.format(validate_str))
         files_found = glob.glob(validate_str)
         self.assertTrue(len(files_found) == 1, '{} of log(s) with {} format were found'.format(len(files_found), validate_str))
         ea_log_file_step6 = files_found[0]
         self.assertTrue(os.path.exists(ea_log_file_step6), 'EA log: {} not found!'.format(ea_log_file_step6))
         self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step6), 'Not all the keywords were found in EA log!')
     except AssertionError as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED'))
         logger.critical(str(e))
     except Exception as e:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR'))
         logger.critical(str(e))
     else:
         logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))