def __run_test_module(module): env.threadlocal.MODULE_NAME = module.__name__.split('.')[-1] testcases = [] for fun in dir(module): if (not fun.startswith("__")) and (not fun.endswith("__")) and (isinstance(module.__dict__.get(fun), types.FunctionType)): if module.__dict__.get(fun).__module__ == module.__name__: testcases.append(fun) for testcase in testcases: if testcase == 'before_each_testcase' or testcase == 'after_each_testcase' or testcase == 'before_launch_browser': return for browser in env.TESTING_BROWSERS.split('|'): env.threadlocal.TESTING_BROWSER = browser if not hasattr(env.threadlocal, "BROWSER"): env.threadlocal.BROWSER = None ###### Run Test Case ###### try: log.start_test(testcase) if hasattr(module, 'before_launch_browser'): getattr(module, 'before_launch_browser')() if (env.RESTART_BROWSER == True) or (env.threadlocal.BROWSER == None): env.threadlocal.BROWSER = launch_browser(env.BASE_URL) if hasattr(module, 'before_each_testcase'): getattr(module, 'before_each_testcase')() getattr(module, testcase)() if hasattr(module, 'after_each_testcase'): getattr(module, 'after_each_testcase')() except: log.handle_error() finally: if env.threadlocal.CASE_PASS == False: env.threadlocal.casepass = False else: env.threadlocal.casepass = True if env.threadlocal.CASE_PASS == False and env.FAST_FAIL == True: log.stop_test() return "FAST_FAIL" else: log.stop_test() if (env.RESTART_BROWSER == True): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.RESTART_BROWSER == False) and (env.threadlocal.BROWSER != None) and (env.threadlocal.casepass == False): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.threadlocal.BROWSER != None): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None
def run_module(module_name): if sys.getdefaultencoding() != 'utf-8': reload(sys) sys.setdefaultencoding('utf-8') testmodule = importlib.import_module("testcase.%s" % module_name) env.MODULE_NAME = module_name.split('.')[-1] testcases = [testmodule.__dict__.get(a).__name__ for a in dir(testmodule) if isinstance(testmodule.__dict__.get(a), types.FunctionType)] env.PROJECT_PATH = os.path.dirname(os.path.abspath(inspect.stack()[1][1])) sys.path.append(env.PROJECT_PATH) env.TESTING_BROWSERS = common.get_value_from_conf("TESTING_BROWSERS") for testcase in testcases: if testcase == "before_each_testcase" or testcase == "after_each_testcase" or testcase == "before_launch_browser": continue for browser in env.TESTING_BROWSERS.split('|'): env.RUNNING_BROWSER = browser ##### Launch Browser if "before_launch_browser" in testcases: getattr(testmodule, "before_launch_browser")() if launch_browser() == False: continue ##### Run Test Case. try: log.start_test(testcase) if "before_each_testcase" in testcases: getattr(testmodule, "before_each_testcase")() getattr(testmodule, testcase)() except: log.handle_error() finally: if "after_each_testcase" in testcases: getattr(testmodule, "after_each_testcase")() log.stop_test() ##### Clear Environment. Quite Browser, Kill Driver Processes. testcase_windingup()
def __run_test_case(case): module = importlib.import_module(case.__module__) env.threadlocal.MODULE_NAME = case.__module__.split('.')[-1] for browser in env.TESTING_BROWSERS.split('|'): env.threadlocal.TESTING_BROWSER = browser if not hasattr(env.threadlocal, "BROWSER"): env.threadlocal.BROWSER = None ###### Run Test Case ###### try: log.start_test(case.__name__) if hasattr(module, 'before_launch_browser'): getattr(module, 'before_launch_browser')() if (env.RESTART_BROWSER == True) or (env.threadlocal.BROWSER == None): env.threadlocal.BROWSER = launch_browser(env.BASE_URL) if hasattr(module, 'before_each_testcase'): getattr(module, 'before_each_testcase')() case() if hasattr(module, 'after_each_testcase'): getattr(module, 'after_each_testcase')() except: log.handle_error() finally: if env.threadlocal.CASE_PASS == False: env.threadlocal.casepass = False else: env.threadlocal.casepass = True if env.threadlocal.CASE_PASS == False and env.FAST_FAIL == True: log.stop_test() return "FAST_FAIL" else: log.stop_test() if (env.RESTART_BROWSER == True): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.RESTART_BROWSER == False) and (env.threadlocal.BROWSER != None) and (env.threadlocal.casepass == False): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.threadlocal.BROWSER != None): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None
def run_case(module_name, case_name): testmodule = importlib.import_module("testcase.%s" % module_name) env.MODULE_NAME = module_name.split('.')[-1] testcases = [testmodule.__dict__.get(a).__name__ for a in dir(testmodule) if isinstance(testmodule.__dict__.get(a), types.FunctionType)] env.PROJECT_PATH = inspect.stack()[1][1].rsplit("\\", 1)[0] env.TESTING_BROWSERS = common.get_value_from_conf("TESTING_BROWSERS") if not case_name in testcases: return for browser in env.TESTING_BROWSERS.split('|'): env.RUNNING_BROWSER = browser ##### Launch Browser if "before_launch_browser" in testcases: getattr(testmodule, "before_launch_browser")() if launch_browser() == False: continue ##### Run Test Case. try: log.start_test(case_name) if "before_each_testcase" in testcases: getattr(testmodule, "before_each_testcase")() getattr(testmodule, case_name)() except: log.handle_error() finally: if "after_each_testcase" in testcases: getattr(testmodule, "after_each_testcase")() log.stop_test() ##### Clear Environment. Quite Browser, Kill Driver Processes. testcase_windingup()
def run_module(module_name): testmodule = importlib.import_module("testcase.%s" % module_name) env.MODULE_NAME = module_name.split('.')[-1] testcases = [ testmodule.__dict__.get(a).__name__ for a in dir(testmodule) if isinstance(testmodule.__dict__.get(a), types.FunctionType) ] env.PROJECT_PATH = inspect.stack()[1][1].rsplit("\\", 1)[0] env.TESTING_BROWSERS = common.get_value_from_conf("TESTING_BROWSERS") for testcase in testcases: if testcase == "before_each_testcase" or testcase == "after_each_testcase" or testcase == "before_launch_browser": continue for browser in env.TESTING_BROWSERS.split('|'): env.RUNNING_BROWSER = browser ##### Launch Browser if "before_launch_browser" in testcases: getattr(testmodule, "before_launch_browser")() if launch_browser() == False: continue ##### Run Test Case. try: log.start_test(testcase) if "before_each_testcase" in testcases: getattr(testmodule, "before_each_testcase")() getattr(testmodule, testcase)() except: log.handle_error() finally: if "after_each_testcase" in testcases: getattr(testmodule, "after_each_testcase")() log.stop_test() ##### Clear Environment. Quite Browser, Kill Driver Processes. testcase_windingup()
def __run_test_module(module): env.threadlocal.MODULE_NAME = module.__name__.split('.')[-1] env.HTMLREPORT_MODULE_NAME = env.threadlocal.MODULE_NAME testcases = [] for fun in dir(module): if (not fun.startswith("__")) and (not fun.endswith("__")) and ( isinstance(module.__dict__.get(fun), types.FunctionType)): if module.__dict__.get(fun).__module__ == module.__name__: testcases.append(fun) for testcase in testcases: if testcase == 'before_each_testcase' or testcase == 'after_each_testcase' or testcase == 'before_launch_browser': return for browser in env.TESTING_BROWSERS.split('|'): env.threadlocal.TESTING_BROWSER = browser if not hasattr(env.threadlocal, "BROWSER"): env.threadlocal.BROWSER = None ###### Run Test Case ###### try: log.start_test(testcase) if hasattr(module, 'before_launch_browser'): getattr(module, 'before_launch_browser')() if (env.RESTART_BROWSER == True) or (env.threadlocal.BROWSER == None): env.threadlocal.BROWSER = launch_browser(env.BASE_URL) if hasattr(module, 'before_each_testcase'): getattr(module, 'before_each_testcase')() getattr(module, testcase)() if hasattr(module, 'after_each_testcase'): getattr(module, 'after_each_testcase')() except: log.handle_error() finally: if env.threadlocal.CASE_PASS == False: env.threadlocal.casepass = False else: env.threadlocal.casepass = True if env.threadlocal.CASE_PASS == False and env.FAST_FAIL == True: log.stop_test() return "FAST_FAIL" else: log.stop_test() if (env.RESTART_BROWSER == True): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.RESTART_BROWSER == False) and (env.threadlocal.BROWSER != None) and ( env.threadlocal.casepass == False): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None if (env.threadlocal.BROWSER != None): quit_browser(env.threadlocal.BROWSER) env.threadlocal.BROWSER = None