Beispiel #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'))
Beispiel #2
0
def ts_test_case_1():
    r''' handle the click operation needed for C:\Users\Public\Documents\National Instruments\TestStand 2012\Examples\Demo\C\computer.seq .'''
    try_to_focus_window('About This Example')
    normal_type(0x0D) # 0x0D is the ENTER key.
    try_to_focus_window('Test Simulator')
    normal_type(0x0D)
    time_sleep(10)
Beispiel #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'))
Beispiel #4
0
def item_click(tab=None, item='_tab', delay=0.5):
    if None == tab:
        if '_tab' == item:
            logger.error('item = _tab is illegal')
            return False
        for tabgroup in positions:
            for n in positions[tabgroup]:
                if item == n:
                    logger.debug('item_click: tab = {}, item = {}, pos = {}'.format(tabgroup, n, positions[tabgroup]['_tab']))
                    mouse_click(positions[tabgroup]['_tab'])
                    mouse_click(positions[tabgroup][n])
                    time_sleep(delay)
                    return True
        logger.error('item = {} not found'.format(item))
        return False

    if not tab in ea_tabs:
        logger.error('tab = {} not found'.format(item, tab))
        return False
    if not item in positions[tab]:
        logger.error('item = {} in tab = {} not found'.format(item, tab))
        return False

    #print(tab, item, positions[tab][item])
    logger.debug('item_click: tab = {}, item = {}, pos = {}'.format(tab, item, positions[tab][item]))
    if '_main' != tab:
        mouse_click(positions[tab]['_tab'])
    mouse_click(positions[tab][item])
    time_sleep(delay)
    return True
Beispiel #5
0
def ea_config(opt, inp_str, clear_length=30):
    item_click(item=opt)
    if 'folder' in opt:
        clear_length = 80
    clear_type(inp_str, clear_length)
    time_sleep(0.5)
# Click twice on Aplly button
    item_click('_main', 'apply')
    item_click('_main', 'apply')
Beispiel #6
0
def focus_window(title=title, suppress_warning=False):
    win = win32gui.FindWindow(None, title)
    if win == 0:
        if suppress_warning:
            logger.debug('focus window failed, window "{}" not found!'.format(title))
        else:
            logger.warning('focus window failed, window "{}" not found!'.format(title))
    ctypes.windll.user32.SwitchToThisWindow(win, True)
    ctypes.windll.user32.SetFocus(win)
    time_sleep(0.5)
    return win
Beispiel #7
0
def test_positions():
    ea_start()
    time_sleep(5)
    for tabgroup in positions:
        if tabgroup == '_main':
            continue
        for n in tabgroup:
            print(tabgroup, n)
            item_click(positions[tabgroup][n])
            time_sleep(2)
    ea_close()
Beispiel #8
0
def ea_close(delay=5):
    #print(win32process.GetProcessVersion(ea_handle[2]))
    time_sleep(0.1)
    item_click('_main', 'close')
    time_sleep(0.1)
# some prompt window (like "Cannot close TS auto...", which is added in cosmo 1.5 b5) could block for the click
    normal_type(0x0D) # 0x0D is the ENTER key.
    time_sleep(0.1)
    item_click('_main', 'close')
    logger.info('UI of EA is end')
    time_sleep(1)
    ea_wait_process_end()
    time_sleep(delay)
Beispiel #9
0
def ea_wait_process_end():
    if ea_handle == None:
        return
    logger.info('looking for the process' + str(ea_handle)) 
    ver = win32process.GetProcessVersion(ea_handle[2])
    while ver != 0:
        if win32gui.FindWindow(None, title) != 0:
            logger.warning('Window of EA exists. Try to close it again.') 
            ea_close()
        time_sleep(3)
        ver = win32process.GetProcessVersion(ea_handle[2])
        logger.debug('Version of EA\'s process is ' + str(ver)) 
    logger.info('Process of EA is end')
    return
Beispiel #10
0
def ts_start(delay=0):
    win32process.CreateProcess(
            os.path.join(ts_path, ts_name),
            '', None, None, 0,
            win32process.CREATE_NO_WINDOW,
            None,
            ts_path,
            win32process.STARTUPINFO())
    if try_to_focus_window('Compatibility'):
        normal_type(0x0D) # 0x0D is the ENTER key.
    if try_to_focus_window('Login'):
        normal_type(0x0D) # 0x0D is the ENTER key.
    time_sleep(delay)
    return
Beispiel #11
0
def ts_close():
    logger = logging.getLogger("COSMO.ts.auto")
    closed = False
    for i in range(1,10):
        logger.debug('try to find ts window')
        win = focus_window('NI TestStand - Sequence Editor [Edit]')
        if win != 0:
            logger.debug('try to close ts')
            try:
                closeWindowWithMouse(win)
            except:
                continue
            time_sleep(10)
            normal_type(0x0D) # 0x0D is the ENTER key.
            closed = True
        else:
            return closed
    return closed
Beispiel #12
0
def mouse_click(position):
    win = focus_window()
    position_ref = win32gui.GetWindowRect(win)
    #print('ea found', position_ref)

    time_sleep(0.03)
    win32api.SetCursorPos((position[0]+position_ref[0], position[1]+position_ref[1]))
    time_sleep(0.03)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time_sleep(0.03)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
    time_sleep(0.5)
Beispiel #13
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
Beispiel #14
0
def ea_start(delay=0, handle_ts=True):
    # todo: look for the thread of teststand
    # todo: make sure thread of ea is not exist
    global ea_handle
    if ea_handle != None:
        ea_wait_process_end()
        ea_handle = ea_start_process()
    else:
        ea_handle = ea_start_process()
    logger.debug('EA is started')
    time_sleep(5)
    if handle_ts:
        if try_to_focus_window('Compatibility'):
            normal_type(0x0D) # 0x0D is the ENTER key.
        if try_to_focus_window('Login'):
            normal_type(0x0D) # 0x0D is the ENTER key.

    # item_click('_main', 'connect') EA GUI is not started yet, so could not click for now
    # todo: make sure the "auto connect" option is on or off
    time_sleep(delay)
Beispiel #15
0
def test_keybd(): # todo: this function is for test only.
    ea_start()
    time_sleep(5)
    #item_click('login', 'server')
    print(item_click(item='server'))
    clear_type(r'C:\cosmo_auotest\test1()_;')
Beispiel #16
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'))