예제 #1
0
파일: log.py 프로젝트: tinysheepyang/brush
def step_fail(message):
    """
    失败或者异常对当前页面截图
    """
    #mail(env.threadlocal.CASE_NAME, env.threadlocal.BROWSER.current_url, common.stamp_datetime_coherent())

    screenshot_name = "Fail__%s__%s__%s.png" % (common.stamp_datetime_coherent(
    ), env.threadlocal.CASE_NAME, env.threadlocal.TESTING_BROWSER)

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "------------ Fail [%s] -------------------\n" %
        common.stamp_datetime())

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "%s    Fail: %s, Check ScreenShot [%s]\n" %
        (common.stamp_datetime(), message, screenshot_name))

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "------------ Fail [%s] --------------------------------------------\n"
        % common.stamp_datetime())

    try:
        save_screen_shot(screenshot_name)
    except:
        step_normal(str(sys.exc_info()))

    env.HTMLREPORT_SCREENSHOT_NAME = screenshot_name
    env.threadlocal.CASE_PASS = False
    env.EXIT_STATUS = -1

    raise AssertionError(message)
예제 #2
0
파일: log.py 프로젝트: tinysheepyang/brush
def step_warning(message):
    screenshot_name = "Warning__%s__%s__%s.png" % (
        common.stamp_datetime_coherent(), env.threadlocal.CASE_NAME,
        env.threadlocal.TESTING_BROWSER)

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "------------ Warning [%s] -------------------\n" %
        common.stamp_datetime())

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "%s    Warning: %s, Check ScreenShot [%s]\n" %
        (common.stamp_datetime(), message, screenshot_name))

    write_log(
        os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
        "------------ Warning [%s] --------------------------------------------\n"
        % common.stamp_datetime())

    try:
        save_screen_shot(screenshot_name)
    except:
        step_normal(str(sys.exc_info()))

    env.threadlocal.CASE_WARNINGS = env.threadlocal.CASE_WARNINGS + 1
예제 #3
0
파일: log.py 프로젝트: 123tw/knitter
def stop_test():
    
    try:
        env.THREAD_LOCK.acquire()
        
        env.threadlocal.CASE_STOP_TIME = datetime.datetime.now().replace(microsecond=0)
        env.TOTAL_STOP_TIME            = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        
        if env.threadlocal.CASE_WARNINGS > 0:
            warning_message = ", has [%s] warning(s)!" % env.threadlocal.CASE_WARNINGS
        else:
            warning_message = ""
        
        if env.threadlocal.CASE_PASS == True:
            print (u"%s    [Pass]  =>  [%s] [%s] [%s] [%s]%s" %(common.stamp_datetime(), 
                                                        env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                                        env.threadlocal.MODULE_NAME, 
                                                        env.threadlocal.CASE_NAME, 
                                                        env.threadlocal.TESTING_BROWSER,
                                                        warning_message
                                                        ))
            env.TOTAL_TESTCASE_PASS = env.TOTAL_TESTCASE_PASS + 1
            
            env.HTMLREPORT_TESTCASES.append(["%s => %s" % (env.threadlocal.CASE_START_TIME.strftime("%m-%d %H:%M:%S"), env.threadlocal.CASE_STOP_TIME.strftime("%m-%d %H:%M:%S")),
                                             '<a href="testcase/%s.log">[%s] - %s</a>' % (env.threadlocal.CASE_NAME, env.threadlocal.MODULE_NAME, env.threadlocal.CASE_NAME),
                                             env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                             env.threadlocal.TESTING_BROWSER, 
                                             '<td>Pass</td>'
                                             ])
            
        else:
            print (u"%s    [Fail]  =>  [%s] [%s] [%s] [%s]%s  :( " %(common.stamp_datetime(), 
                                                                 env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                                                 env.threadlocal.MODULE_NAME, 
                                                                 env.threadlocal.CASE_NAME, 
                                                                 env.threadlocal.TESTING_BROWSER,
                                                                 warning_message
                                                                 ))
            env.TOTAL_TESTCASE_FAIL = env.TOTAL_TESTCASE_FAIL + 1
            
            env.HTMLREPORT_TESTCASES.append(["%s =&gt; %s" % (env.threadlocal.CASE_START_TIME.strftime("%m-%d %H:%M:%S"),env.threadlocal.CASE_STOP_TIME.strftime("%m-%d %H:%M:%S")),
                                             '<a href="testcase/%s.log">[%s] - %s</a>' % (env.threadlocal.CASE_NAME, env.threadlocal.MODULE_NAME, env.threadlocal.CASE_NAME),
                                             env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                             env.threadlocal.TESTING_BROWSER, 
                                             '<td class="tfail"><a href="screenshots/%s">Fail</a></td>' % env.HTMLREPORT_SCREENSHOT_NAME
                                             ])
        
        htmlreport.generate_html_report([env.TOTAL_START_TIME, env.TOTAL_STOP_TIME, datetime.datetime.strptime(env.TOTAL_STOP_TIME, "%Y-%m-%d %H:%M:%S") - datetime.datetime.strptime(env.TOTAL_START_TIME, "%Y-%m-%d %H:%M:%S"), 
                                         env.TOTAL_TESTCASE_PASS+env.TOTAL_TESTCASE_FAIL, env.TOTAL_TESTCASE_PASS, env.TOTAL_TESTCASE_FAIL], 
                                        env.HTMLREPORT_TESTCASES)
        
        env.threadlocal.CASE_PASS     = True
        env.threadlocal.CASE_WARNINGS = 0
    finally:
        env.THREAD_LOCK.release()
예제 #4
0
def stop_test():
    
    try:
        env.THREAD_LOCK.acquire()
        
        env.threadlocal.CASE_STOP_TIME = datetime.datetime.now().replace(microsecond=0)
        env.TOTAL_STOP_TIME            = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        
        if env.threadlocal.CASE_WARNINGS > 0:
            warning_message = ", has [%s] warning(s)!" % env.threadlocal.CASE_WARNINGS
        else:
            warning_message = ""
        
        if env.threadlocal.CASE_PASS == True:
            print (u"%s    [Pass]  =>  [%s] [%s] [%s] [%s]%s" %(common.stamp_datetime(), 
                                                        env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                                        env.threadlocal.MODULE_NAME, 
                                                        env.threadlocal.CASE_NAME, 
                                                        env.threadlocal.TESTING_BROWSER,
                                                        warning_message
                                                        ))
            env.TOTAL_TESTCASE_PASS = env.TOTAL_TESTCASE_PASS + 1
            
            env.HTMLREPORT_TESTCASES.append(["%s =&gt; %s" % (env.threadlocal.CASE_START_TIME.strftime("%m-%d %H:%M:%S"), env.threadlocal.CASE_STOP_TIME.strftime("%m-%d %H:%M:%S")),
                                             '<a href="testcase/%s.txt">[%s] - %s</a>' % (env.threadlocal.CASE_NAME, env.threadlocal.MODULE_NAME, env.threadlocal.CASE_NAME),
                                             env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                             env.threadlocal.TESTING_BROWSER, 
                                             '<td>Pass</td>'
                                             ])
            
        else:
            print (u"%s    [Fail]  =>  [%s] [%s] [%s] [%s]%s  :( " %(common.stamp_datetime(), 
                                                                 env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                                                 env.threadlocal.MODULE_NAME, 
                                                                 env.threadlocal.CASE_NAME, 
                                                                 env.threadlocal.TESTING_BROWSER,
                                                                 warning_message
                                                                 ))
            env.TOTAL_TESTCASE_FAIL = env.TOTAL_TESTCASE_FAIL + 1
            
            env.HTMLREPORT_TESTCASES.append(["%s =&gt; %s" % (env.threadlocal.CASE_START_TIME.strftime("%m-%d %H:%M:%S"),env.threadlocal.CASE_STOP_TIME.strftime("%m-%d %H:%M:%S")),
                                             '<a href="testcase/%s.txt">[%s] - %s</a>' % (env.threadlocal.CASE_NAME, env.threadlocal.MODULE_NAME, env.threadlocal.CASE_NAME),
                                             env.threadlocal.CASE_STOP_TIME - env.threadlocal.CASE_START_TIME, 
                                             env.threadlocal.TESTING_BROWSER, 
                                             '<td class="tfail"><a href="screenshots/%s">Fail</a></td>' % env.HTMLREPORT_SCREENSHOT_NAME
                                             ])
        
        htmlreport.generate_html_report([env.TOTAL_START_TIME, env.TOTAL_STOP_TIME, datetime.datetime.strptime(env.TOTAL_STOP_TIME, "%Y-%m-%d %H:%M:%S") - datetime.datetime.strptime(env.TOTAL_START_TIME, "%Y-%m-%d %H:%M:%S"), 
                                         env.TOTAL_TESTCASE_PASS+env.TOTAL_TESTCASE_FAIL, env.TOTAL_TESTCASE_PASS, env.TOTAL_TESTCASE_FAIL], 
                                        env.HTMLREPORT_TESTCASES)
        
        env.threadlocal.CASE_PASS     = True
        env.threadlocal.CASE_WARNINGS = 0
    finally:
        env.THREAD_LOCK.release()
예제 #5
0
def step_fail(message):
    screenshot_name = "%s__%s__Fail__%s.png" % (env.CASE_NAME, env.platformName, common.stamp_datetime_coherent())
    
    with open(u"%s\\Result\\testcase\\%s__%s.log" % (env.PROJECT_PATH, env.CASE_NAME, common.stamp_date()), "a") as f:
        f.write("------------ Fail [%s] -------------------\n" % common.stamp_datetime())
        f.write("%s    Fail: %s, Check ScreenShot [%s]\n" % (common.stamp_datetime(), message, screenshot_name))
        f.write("------------ Fail [%s] --------------------------------------------\n" % common.stamp_datetime())
    
    common.mkdirs("%s\\Result\\screenshots\\" % env.PROJECT_PATH)
    env.driver.save_screenshot(u"%s\\Result\\screenshots\\%s" % (env.PROJECT_PATH, screenshot_name))
    
    env.CASE_PASS = False
    
    raise AssertionError(message)
예제 #6
0
def userlog(message):
    info = common.stamp_datetime() + " " + "[UserLog]\t" + message
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #7
0
def assert_normal(message):
    info = common.stamp_datetime() + " " + "[!Error]\t" + message
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #8
0
def assert_screen(PIC_ABS):
    info = common.stamp_datetime() + " " + "[!Error]\t" + "Error! ScreenShot is Saved in [{0}]".format(PIC_ABS)
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #9
0
def wd_screen(message):
    info = common.stamp_datetime() + " " + "[Screen]\t" + "ScreenShot is Saved in [{0}]".format(message)
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #10
0
def check_normal(message):
    info = common.stamp_datetime() + " " + "[Check]\t" + message
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #11
0
파일: log.py 프로젝트: 123tw/knitter
def step_warning(message):
    screenshot_name = "Warning__%s__%s__%s.png" % (common.stamp_datetime_coherent(), env.threadlocal.CASE_NAME, env.threadlocal.TESTING_BROWSER)
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "------------ Warning [%s] -------------------\n"%common.stamp_datetime())
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "%s    Warning: %s, Check ScreenShot [%s]\n" %(common.stamp_datetime(), message, screenshot_name))
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "------------ Warning [%s] --------------------------------------------\n"%common.stamp_datetime())
    
    try:
        save_screen_shot(screenshot_name)
    except:
        step_normal(str(sys.exc_info()))
    
    env.threadlocal.CASE_WARNINGS = env.threadlocal.CASE_WARNINGS + 1
예제 #12
0
파일: log.py 프로젝트: suxianxin/knitter
def stop_test():
    env.CASE_STOP_TIME = datetime.datetime.now().replace(microsecond=0)

    with open(u"%s\\result\\summary.log" % env.PROJECT_PATH, "a") as f:
        if env.CASE_PASS == True:
            add_excel_report_data(env.EXCEL_REPORT_DATA, env.MODULE_NAME,
                                  env.CASE_NAME, env.RUNNING_BROWSER, "Pass")
            f.write(u"%s    [Pass]  =>  [%s] [%s] [%s]\n" %
                    (common.stamp_datetime(), env.CASE_STOP_TIME -
                     env.CASE_START_TIME, env.CASE_NAME, env.RUNNING_BROWSER))
        else:
            add_excel_report_data(env.EXCEL_REPORT_DATA, env.MODULE_NAME,
                                  env.CASE_NAME, env.RUNNING_BROWSER, "Fail")
            f.write(u"%s    [Fail]  =>  [%s] [%s] [%s]  :( \n" %
                    (common.stamp_datetime(), env.CASE_STOP_TIME -
                     env.CASE_START_TIME, env.CASE_NAME, env.RUNNING_BROWSER))

    generate_result_xls()
    env.CASE_PASS = True
예제 #13
0
파일: log.py 프로젝트: Liubusy/knitter
def stop_test():
    env.CASE_STOP_TIME = datetime.datetime.now().replace(microsecond=0)
    
    with open(u"%s\\result\\summary.log" % env.PROJECT_PATH, "a") as f:
        if env.CASE_PASS == True:
            add_excel_report_data(env.EXCEL_REPORT_DATA, env.MODULE_NAME, env.CASE_NAME, env.RUNNING_BROWSER, "Pass")
            f.write(u"%s    [Pass]  =>  [%s] [%s] [%s]\n" %(common.stamp_datetime(), 
                                                            env.CASE_STOP_TIME - env.CASE_START_TIME, 
                                                            env.CASE_NAME, 
                                                            env.RUNNING_BROWSER))
        else:
            add_excel_report_data(env.EXCEL_REPORT_DATA, env.MODULE_NAME, env.CASE_NAME, env.RUNNING_BROWSER, "Fail")
            f.write(u"%s    [Fail]  =>  [%s] [%s] [%s]  :( \n" %(common.stamp_datetime(), 
                                                                 env.CASE_STOP_TIME - env.CASE_START_TIME, 
                                                                 env.CASE_NAME, 
                                                                 env.RUNNING_BROWSER))
    
    generate_result_xls()
    env.CASE_PASS = True
예제 #14
0
def case_End():
    info = common.stamp_datetime() + " " + "[TestCase]\t" + "\tEnd!"
    print info
    print DIVIDING_LINE
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
        f.write(DIVIDING_LINE+"\n") 
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
        f.write(DIVIDING_LINE+"\n") 
예제 #15
0
def wd_page(message):
    wd_page = message
    info = common.stamp_datetime() + " " + "[Info]\t" + "The HTML Page is Saved in [{0}]".format(HTML_ABS)
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:         
        f.write(info+"\n")
    with open(HTML_ABS,"w") as f:
        f.write(wd_page)
예제 #16
0
def case_start(CaseName):
    info = common.stamp_datetime() + " " + "[TestCase]\t" + '"' + CaseName + '"' + "\tStart!"
    print DIVIDING_LINE
    print info
    with open(LOG_ABS,"a") as f:      
        f.write(DIVIDING_LINE+"\n")   
        f.write(info+"\n")
    with open(USERLOG_ABS,"a") as f:      
        f.write(DIVIDING_LINE+"\n")   
        f.write(info+"\n")
예제 #17
0
파일: log.py 프로젝트: 123tw/knitter
def step_fail(message):
    
    screenshot_name = "Fail__%s__%s__%s.png" % (common.stamp_datetime_coherent(), env.threadlocal.CASE_NAME, env.threadlocal.TESTING_BROWSER)
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),  
              "------------ Fail [%s] -------------------\n"%common.stamp_datetime())
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "%s    Fail: %s, Check ScreenShot [%s]\n" %(common.stamp_datetime(), message, screenshot_name))
    
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "------------ Fail [%s] --------------------------------------------\n"%common.stamp_datetime())
    
    try:
        save_screen_shot(screenshot_name)
    except:
        step_normal(str(sys.exc_info()))
    
    env.HTMLREPORT_SCREENSHOT_NAME = screenshot_name
    env.threadlocal.CASE_PASS = False
    env.EXIT_STATUS = -1
    
    raise AssertionError(message)
예제 #18
0
def step_fail(message):
    
    screenshot_name = "Fail__%s__%s__%s.png" % (common.stamp_datetime_coherent(), env.threadlocal.CASE_NAME, env.threadlocal.TESTING_BROWSER)
    
    write_log(os.path.join("testcase", "%s.txt" % (env.threadlocal.CASE_NAME)),
              "------------ Fail [%s] -------------------\n"%common.stamp_datetime())
    print("testcase : %s ------------ Fail [%s] -------------------\n" % (env.threadlocal.CASE_NAME, common.stamp_datetime()))
    
    write_log(os.path.join("testcase", "%s.txt" % (env.threadlocal.CASE_NAME)), 
              "%s    Fail: %s, Check ScreenShot [%s]\n" %(common.stamp_datetime(), message, screenshot_name))
    print("testcase : %s -- %s    Fail: %s, Check ScreenShot [%s]" % (env.threadlocal.CASE_NAME, common.stamp_datetime(), message, screenshot_name))
    
    write_log(os.path.join("testcase", "%s.txt" % (env.threadlocal.CASE_NAME)), 
              "------------ Fail [%s] --------------------------------------------\n"%common.stamp_datetime())
    print("testcase : %s------------ Fail [%s] --------------------------------------------\n" % (env.threadlocal.CASE_NAME, common.stamp_datetime()))
    
    try:
        save_screen_shot(screenshot_name)
    except:
        step_normal(str(sys.exc_info()))
    
    env.HTMLREPORT_SCREENSHOT_NAME = screenshot_name
    env.threadlocal.CASE_PASS = False
    env.EXIT_STATUS = -1
예제 #19
0
파일: log.py 프로젝트: tinysheepyang/brush
def step_pass(message):
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)),
              "%s    Pass: %s\n" % (common.stamp_datetime(), message))
예제 #20
0
def step_normal(message):
    write_log(os.path.join("testcase", "%s.txt" % (env.threadlocal.CASE_NAME)), 
              "%s    Step: %s\n" %(common.stamp_datetime(), message))
    print ("testcase : %s   %s    Step: %s\n" % (env.threadlocal.CASE_NAME, common.stamp_datetime(), message))
예제 #21
0
def step_section(message):
    write_log(os.path.join("testcase", "%s.txt" % (env.threadlocal.CASE_NAME)), 
              "\n%s    Section: %s\n" %(common.stamp_datetime(), message))
예제 #22
0
def step_normal(message):
    info = common.stamp_datetime() + " " + "[Step]\t" + message
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #23
0
def wd_info(message):
    info = common.stamp_datetime() + " " + "[Info]\t" + message
    print info
    with open(LOG_ABS,"a") as f:         
        f.write(info+"\n")
예제 #24
0
파일: log.py 프로젝트: Liubusy/knitter
def step_section(message):
    with open(u"%s\\result\\TestCase\%s__%s.log" % (env.PROJECT_PATH, env.CASE_NAME, common.stamp_date()), "a") as f:
        f.write(u"\n%s    Section: %s\n" %(common.stamp_datetime(), message))
예제 #25
0
파일: log.py 프로젝트: 123tw/knitter
def step_pass(message):
    write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), 
              "%s    Pass: %s\n" %(common.stamp_datetime(), message))
예제 #26
0
파일: log.py 프로젝트: suxianxin/knitter
def step_section(message):
    with open(
            u"%s\\result\\TestCase\%s__%s.log" %
        (env.PROJECT_PATH, env.CASE_NAME, common.stamp_date()), "a") as f:
        f.write(u"\n%s    Section: %s\n" % (common.stamp_datetime(), message))
예제 #27
0
def folder():
    folderInfo = common.stamp_datetime() + " " + "[CaseSuite]\t"
    print folderInfo
    with open(LOG_ABS,"a") as f:      
        f.write(folderInfo + caseSuite + "\n")
예제 #28
0
def step_pass(message):
    with open(u"%s\\Result\\testcase\\%s__%s.log" % (env.PROJECT_PATH, env.CASE_NAME, common.stamp_date()), "a") as f:
        f.write("%s    Pass: %s\n" % (common.stamp_datetime(), message))