Exemple #1
0
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 __launch(delegate):
    ''' 
   Runs the given (no-argument) delegate method in a 'safe' script environment.
   This environment will take care of all error handling, logging/debug stream,
   and other standard initialization behaviour before delegate() is called, and
   it will take care of cleaning everything up afterwards.
   '''
    try:
        # initialize the application resources (import directories, etc)
        Resources.initialize()

        # fire up the debug logging system
        log.install(ComicRack.MainWindow)

        # install a handler to catch uncaught Winforms exceptions
        def exception_handler(sender, event):
            del sender  #unused
            log.handle_error(event.Exception)
        Application.ThreadException \
           += ThreadExceptionEventHandler(exception_handler)

        # fire up the localization/internationalization system
        i18n.install(ComicRack)

        # see if we're in a valid environment
        if __validate_environment():
            delegate()

    except Exception, ex:
        log.handle_error(ex)
def __launch(delegate):
   ''' 
   Runs the given (no-argument) delegate method in a 'safe' script environment.
   This environment will take care of all error handling, logging/debug stream,
   and other standard initialization behaviour before delegate() is called, and
   it will take care of cleaning everything up afterwards.
   ''' 
   try:
      # initialize the application resources (import directories, etc)
      Resources.initialize()
      
      # fire up the debug logging system
      log.install(ComicRack.MainWindow)
      
      # install a handler to catch uncaught Winforms exceptions
      def exception_handler(sender, event):
         log.handle_error(event.Exception)
      Application.ThreadException \
         += ThreadExceptionEventHandler(exception_handler)
         
      # fire up the localization/internationalization system
      i18n.install(ComicRack)
      
      # see if we're in a valid environment
      if __validate_environment():
         delegate()
         
   except Exception, ex:
      log.handle_error(ex)
Exemple #4
0
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
Exemple #5
0
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()
Exemple #6
0
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
Exemple #7
0
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()
Exemple #8
0
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 threadloop():
    task = None
    while task != self:
       try:
          Monitor.Enter(self)
          try:
             task = self.task
             if task != self:
                self.task = None
             if task is None:
                Monitor.Wait(self)
          finally:
             Monitor.Exit(self)
             
          if task != self and task is not None:
             task()
                   
       except Exception as ex:
          # slightly odd error handling, cause this thread should NEVER
          # die as the result of an exception!
          try: log.handle_error(ex) 
          except: pass
          task = None
Exemple #10
0
 def exception_handler(sender, event):
     log.handle_error(event.Exception)
 def exception_handler(sender, event):
     del sender  #unused
     log.handle_error(event.Exception)
Exemple #12
0
def launch_browser(url):
    '''
    Launch a new browser, and set the parameters for the browser.
    
    '''

    if env.threadlocal.TESTING_BROWSER.upper() == 'FIREFOX':
        fp = FirefoxProfile()
        fp.native_events_enabled = False

        if env.FIREFOX_BINARY == '':
            try:
                env.THREAD_LOCK.acquire()
                browser = webdriver.Firefox(firefox_profile=fp)
            except:
                if isinstance(env.RESERVED_FIREFOX_BINARY,
                              str) and env.RESERVED_FIREFOX_BINARY != "":
                    browser = webdriver.Firefox(
                        firefox_profile=fp,
                        firefox_binary=FirefoxBinary(
                            firefox_path=env.RESERVED_FIREFOX_BINARY))
                else:
                    try:
                        log.step_warning("try to start firefox again!")
                        time.sleep(20)
                        browser = webdriver.Firefox(firefox_profile=fp)
                    except:
                        log.handle_error()
                        return False
            finally:
                env.THREAD_LOCK.release()

        else:
            browser = webdriver.Firefox(
                firefox_profile=fp,
                firefox_binary=FirefoxBinary(firefox_path=env.FIREFOX_BINARY))

    elif env.threadlocal.TESTING_BROWSER.upper() == 'CHROME':
        if env.DRIVER_OF_CHROME == '':
            print('DRIVER_OF_CHROME is empty.')
            return False

        os.environ['webdriver.chrome.driver'] = env.DRIVER_OF_CHROME
        browser = webdriver.Chrome(executable_path=env.DRIVER_OF_CHROME)

    elif env.threadlocal.TESTING_BROWSER.upper() == 'IE':
        if env.DRIVER_OF_IE == '':
            print('DRIVER_OF_IE is empty.')
            return False


#       os.popen('TASKKILL /F /IM iexplore.exe')
        os.popen('TASKKILL /F /IM IEDriverServer.exe')

        dc = DesiredCapabilities.INTERNETEXPLORER.copy()

        dc['nativeEvents'] = False
        dc['acceptSslCerts'] = True

        os.environ['webdriver.ie.driver'] = env.DRIVER_OF_IE

        browser = webdriver.Ie(executable_path=env.DRIVER_OF_IE,
                               capabilities=dc)

    elif env.threadlocal.TESTING_BROWSER.upper() == 'PHANTOMJS':
        browser = webdriver.PhantomJS(
            r'D:\\Emma\\qiqi\\pop\\drivers\\phantomjs\\phantomjs.exe')

    if not env.BROWSER_VERSION_INFO.has_key(env.threadlocal.TESTING_BROWSER):
        env.BROWSER_VERSION_INFO[
            env.threadlocal.TESTING_BROWSER] = browser.capabilities['version']

    browser.set_window_size(1920, 1080)
    browser.set_window_position(0, 0)
    browser.set_page_load_timeout(300)
    browser.implicitly_wait(0)

    browser.get(url)

    return browser
Exemple #13
0
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
Exemple #14
0
def launch_browser(url):
    '''
    Launch a new browser, and set the parameters for the browser.
    
    '''
    
    if env.threadlocal.TESTING_BROWSER.upper() == 'FIREFOX':
        fp = FirefoxProfile()
        fp.native_events_enabled = False
        
        if env.FIREFOX_BINARY == '':
            try:
                env.THREAD_LOCK.acquire()
                browser = webdriver.Firefox(firefox_profile=fp)
            except:
                if isinstance(env.RESERVED_FIREFOX_BINARY, str) and env.RESERVED_FIREFOX_BINARY != "":
                    browser = webdriver.Firefox(firefox_profile=fp, 
                                                firefox_binary=FirefoxBinary(firefox_path=env.RESERVED_FIREFOX_BINARY))
                else:
                    try:
                        log.step_warning("try to start firefox again!")
                        time.sleep(20)
                        browser = webdriver.Firefox(firefox_profile=fp)
                    except:
                        log.handle_error()
                        return False
            finally:
                env.THREAD_LOCK.release()
                
        else:
            browser = webdriver.Firefox(firefox_profile=fp, 
                                            firefox_binary=FirefoxBinary(firefox_path=env.FIREFOX_BINARY))
        
        
    
    elif env.threadlocal.TESTING_BROWSER.upper() == 'CHROME':
        if env.DRIVER_OF_CHROME == '':
            print ('DRIVER_OF_CHROME is empty.')
            return False
        
        os.environ['webdriver.chrome.driver'] = env.DRIVER_OF_CHROME
        browser = webdriver.Chrome(executable_path=env.DRIVER_OF_CHROME)
    
    
    elif env.threadlocal.TESTING_BROWSER.upper() == 'IE':
        if env.DRIVER_OF_IE == '':
            print ('DRIVER_OF_IE is empty.')
            return False
        
#       os.popen('TASKKILL /F /IM iexplore.exe')
        os.popen('TASKKILL /F /IM IEDriverServer.exe')
        
        dc = DesiredCapabilities.INTERNETEXPLORER.copy()
        
        dc['nativeEvents'] = False
        dc['acceptSslCerts'] = True
        
        os.environ['webdriver.ie.driver'] = env.DRIVER_OF_IE
        
        browser = webdriver.Ie(executable_path=env.DRIVER_OF_IE, 
                                   capabilities=dc)
    
    
    elif env.threadlocal.TESTING_BROWSER.upper() == 'PHANTOMJS':
        browser = webdriver.PhantomJS(r'E:\\AutomationWork\\phantomjs-1.9.8-windows\\phantomjs.exe')
    
    
    
    if not env.BROWSER_VERSION_INFO.has_key(env.threadlocal.TESTING_BROWSER):
        env.BROWSER_VERSION_INFO[env.threadlocal.TESTING_BROWSER] = browser.capabilities['version']
    
    
    browser.set_window_size(1366, 758)
    browser.set_window_position(0, 0)
    browser.set_page_load_timeout(300)
    browser.implicitly_wait(0)
    
    browser.get(url)
    
    
    return browser
 def exception_handler(sender, event):
    log.handle_error(event.Exception)