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)
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
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 => %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()
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.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 => %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()
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)
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")
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")
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")
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")
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")
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
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
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
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")
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)
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")
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)
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
def step_pass(message): write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), "%s Pass: %s\n" % (common.stamp_datetime(), message))
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))
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))
def step_normal(message): info = common.stamp_datetime() + " " + "[Step]\t" + message print info with open(LOG_ABS,"a") as f: f.write(info+"\n")
def wd_info(message): info = common.stamp_datetime() + " " + "[Info]\t" + message print info with open(LOG_ABS,"a") as f: f.write(info+"\n")
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))
def step_pass(message): write_log(os.path.join("testcase", "%s.log" % (env.threadlocal.CASE_NAME)), "%s Pass: %s\n" %(common.stamp_datetime(), message))
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))
def folder(): folderInfo = common.stamp_datetime() + " " + "[CaseSuite]\t" print folderInfo with open(LOG_ABS,"a") as f: f.write(folderInfo + caseSuite + "\n")
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))