def __init__(self, targets, delay, record = False ):
        
        """
        Initializer.
        
        @type targets: list
        @param targets: list of System under test (SUT) identifiers.
        
        @type delay: float
        @param delay: Wait-time between consequtive keywords (in seconds)
        
        @type record: boolean
        @param record: Is the test recorded to html-file
        """
            
        self._targetNames = targets
        self._targets = []
        
        self.delay = delay  

        self._rec_process = None
        self._kwCount = 1
        
        self._logger = None
        self._separator = " "
        if record:
            self._logger = KeywordLogger()

        self._kw_cache = {}

        # Special commands listed here for interactive mode completer
        self._commands = {}
        self._commands["exit"] = ["quit","q","exit"]
        self._commands["kws"] = ["list","kws","list full","kws full"]
        self._commands["info"] = ["info"]
        self._commands["special"] = []
Example #2
0
    def __init__(self, targets, delay, record = False ):
        
        """
        Initializer.
        
        @type targets: list
        @param targets: list of System under test (SUT) identifiers.
        
        @type delay: float
        @param delay: Wait-time between consequtive keywords (in seconds)
        
        @type record: boolean
        @param record: Is the test recorded to html-file
        """
            
        self._targetNames = targets
        self._targets = []
        
        self.delay = delay  

        self._rec_process = None
        self._kwCount = 1
        
        self._logger = None
        self._separator = " "
        if record:
            self._logger = KeywordLogger()

        self._kw_cache = {}

        # Special commands listed here for interactive mode completer
        self._commands = {}
        self._commands["exit"] = ["quit","q","exit"]
        self._commands["kws"] = ["list","kws","list full","kws full"]
        self._commands["info"] = ["info"]
        self._commands["special"] = []
Example #3
0
class TestRunner(object):

    """   
    TestRunner class is used to run Keyword-driven tests.
    
    The class allows test to be run interactively (given through stdin), from 
    file or from server.
    
    To run tests from a server, TestRunner uses classes ToolProtocol and 
    ToolProtocolHTTP.
    """
    
    def __init__(self, targets, delay, record = False ):
        
        """
        Initializer.
        
        @type targets: list
        @param targets: list of System under test (SUT) identifiers.
        
        @type delay: float
        @param delay: Wait-time between consequtive keywords (in seconds)
        
        @type record: boolean
        @param record: Is the test recorded to html-file
        """
            
        self._targetNames = targets
        self._targets = []
        
        self.delay = delay  

        self._rec_process = None
        self._kwCount = 1
        
        self._logger = None
        self._separator = " "
        if record:
            self._logger = KeywordLogger()

        self._kw_cache = {}

        # Special commands listed here for interactive mode completer
        self._commands = {}
        self._commands["exit"] = ["quit","q","exit"]
        self._commands["kws"] = ["list","kws","list full","kws full"]
        self._commands["info"] = ["info"]
        self._commands["special"] = []
    
    def _setupTestAutomation(self):
        """Sets up test automation environment
        
        @rtype: boolean
        @returns: True if success, False otherwise
        """
        raise NotImplementedError()


    def _cleanupTestAutomation(self):
        """Cleans up test automation environment"""
        raise NotImplementedError()


    def __setTarget(self,targetName):
        
        if re.match("['\"].*['\"]",targetName):
            targetName = targetName[1:-1]
    
        if targetName == "test" or targetName == "testi":
            print "Warning: 'test' and 'testi' considered dummy targets."
            return True
    
        for t in self._targets:
            if t.name == targetName:
                self._activeTarget = t
                return True 
        return False
        
        
    def initTest(self):
        """
        
        Inits a test run.
        
        Creates a log file and starts recording if defined.
        
        """
        print "Setting up testing environment..."
        if not self._setupTestAutomation():
            return False
        print "setup complete"
        
        self._activeTarget = self._targets[0]
        
        if self._logger:
            print "Recording test to a file"
            self._logger.startLog()
            
        return True
          
    def _stopTest(self):
        """
        Stops a test run.
        
        Closes the log-file and stops recording process.
        """
        print "Cleaning up testing environment..."
        self._cleanupTestAutomation()
        print "clean up complete"

        if self._logger:
            self._logger.endLog()
        print "Test finished"
       
       
    def endTest(self):    
        print "Shutting down"
        self._stopTest()    
    

    def keywordInfo(self, kw ):
        kws = self._getKeywords()
        if kw in kws:
            print kw
            self.printKw(kw,"#",kws[kw][1])

    def printKw(self,kw,header,text):
        print header*len(kw)
        print
        docstring = text.splitlines()
        strip_len = 0
        if len(docstring[0]) == 0:
            docstring = docstring[1:]
        for line in docstring:
            if len(line.strip()) > 0:
                first_line = line.lstrip()
                strip_len = len(line) - len(first_line)
                break

        for line in docstring:
            print line[strip_len:].rstrip()
        print


    def listKeywords(self, basekw = keyword.Keyword,full=False,header="#"):
        kws = self._getKeywords({},basekw)
        kws_keys = sorted(kws.keys())
        for kw in kws_keys:
            print kw
            if full:
                self.printKw(kw,header,kws[kw][1])
    
    def _getKeywords(self, kw_dictionary = {}, basekw = keyword.Keyword):
        use_cache = len(kw_dictionary) == 0
        if use_cache and basekw in self._kw_cache:
            return self._kw_cache[basekw]

        for kw in basekw.__subclasses__():
            kw_name = str(kw)[str(kw).rfind('.')+1:str(kw).rfind("'")]
            if not kw_name.endswith("Keyword"):
                kw_dictionary[kw_name] = (str(kw.__module__),str(kw.__doc__))
            self._getKeywords(kw_dictionary,kw)
        if use_cache:
            self._kw_cache[basekw] = kw_dictionary
        return kw_dictionary    

    def __instantiateKeywordProxyObject(self,kwproxy, kwName,kwAttr,kwproxy_class):
        kwobject = None
        try:
            kwmodule = __import__(kwproxy_class, globals(), locals(), [kwproxy], -1)
#                    kwobject = eval("kwmodule." + kw + "()")
            kwobject = getattr(kwmodule,kwproxy)()
                                       
            if not kwobject.initialize(kwName, kwAttr,self._activeTarget):
                kwobject = None
            if kwobject:
                print 'Recognized keyword: %s' % kwName
                print 'Attributes: %s' % kwAttr
        except Exception, e:
            print e
            print "Error: KeywordProxy error"
            kwobject = None
        return kwobject
class TestRunner(object):

    """   
    TestRunner class is used to run Keyword-driven tests.
    
    The class allows test to be run interactively (given through stdin), from 
    file or from server.
    
    To run tests from a server, TestRunner uses classes ToolProtocol and 
    ToolProtocolHTTP.
    """
    
    def __init__(self, targets, delay, record = False ):
        
        """
        Initializer.
        
        @type targets: list
        @param targets: list of System under test (SUT) identifiers.
        
        @type delay: float
        @param delay: Wait-time between consequtive keywords (in seconds)
        
        @type record: boolean
        @param record: Is the test recorded to html-file
        """
            
        self._targetNames = targets
        self._targets = []
        
        self.delay = delay  

        self._rec_process = None
        self._kwCount = 1
        
        self._logger = None
        self._separator = " "
        if record:
            self._logger = KeywordLogger()

        self._kw_cache = {}

        # Special commands listed here for interactive mode completer
        self._commands = {}
        self._commands["exit"] = ["quit","q","exit"]
        self._commands["kws"] = ["list","kws","list full","kws full"]
        self._commands["info"] = ["info"]
        self._commands["special"] = []
    
    def _setupTestAutomation(self):
        """Sets up test automation environment
        
        @rtype: boolean
        @returns: True if success, False otherwise
        """
        raise NotImplementedError()


    def _cleanupTestAutomation(self):
        """Cleans up test automation environment"""
        raise NotImplementedError()


    def __setTarget(self,targetName):
        
        if re.match("['\"].*['\"]",targetName):
            targetName = targetName[1:-1]
    
        if targetName == "test" or targetName == "testi":
            print "Warning: 'test' and 'testi' considered dummy targets."
            return True
    
        for t in self._targets:
            if t.name == targetName:
                self._activeTarget = t
                return True 
        return False
        
        
    def initTest(self):
        """
        
        Inits a test run.
        
        Creates a log file and starts recording if defined.
        
        """
        print "Setting up testing environment..."
        if not self._setupTestAutomation():
            return False
        print "setup complete"
        
        self._activeTarget = self._targets[0]
        
        if self._logger:
            print "Recording test to a file"
            self._logger.startLog()
            
        return True
          
    def _stopTest(self):
        """
        Stops a test run.
        
        Closes the log-file and stops recording process.
        """
        print "Cleaning up testing environment..."
        self._cleanupTestAutomation()
        print "clean up complete"

        if self._logger:
            self._logger.endLog()
        print "Test finished"
       
       
    def endTest(self):    
        print "Shutting down"
        self._stopTest()    
    

    def keywordInfo(self, kw ):
        kws = self._getKeywords()
        if kw in kws:
            print kw
            self.printKw(kw,"#",kws[kw][1])

    def printKw(self,kw,header,text):
        print header*len(kw)
        print
        docstring = text.splitlines()
        strip_len = 0
        if len(docstring[0]) == 0:
            docstring = docstring[1:]
        for line in docstring:
            if len(line.strip()) > 0:
                first_line = line.lstrip()
                strip_len = len(line) - len(first_line)
                break

        for line in docstring:
            print line[strip_len:].rstrip()
        print


    def listKeywords(self, basekw = keyword.Keyword,full=False,header="#"):
        kws = self._getKeywords({},basekw)
        kws_keys = sorted(kws.keys())
        for kw in kws_keys:
            print kw
            if full:
                self.printKw(kw,header,kws[kw][1])
    
    def _getKeywords(self, kw_dictionary = {}, basekw = keyword.Keyword):
        use_cache = len(kw_dictionary) == 0
        if use_cache and basekw in self._kw_cache:
            return self._kw_cache[basekw]

        for kw in basekw.__subclasses__():
            kw_name = str(kw)[str(kw).rfind('.')+1:str(kw).rfind("'")]
            if not kw_name.endswith("Keyword"):
                kw_dictionary[kw_name] = (str(kw.__module__),str(kw.__doc__))
            self._getKeywords(kw_dictionary,kw)
        if use_cache:
            self._kw_cache[basekw] = kw_dictionary
        return kw_dictionary    

    def __instantiateKeywordProxyObject(self,kwproxy, kwName,kwAttr,kwproxy_class):
        kwobject = None
        try:
            kwmodule = __import__(kwproxy_class, globals(), locals(), [kwproxy], -1)
#                    kwobject = eval("kwmodule." + kw + "()")
            kwobject = getattr(kwmodule,kwproxy)()
                                       
            if not kwobject.initialize(kwName, kwAttr,self._activeTarget):
                kwobject = None
            if kwobject:
                print 'Recognized keyword: %s' % kwName
                print 'Attributes: %s' % kwAttr
        except Exception, e:
            print e
            print "Error: KeywordProxy error"
            kwobject = None
        return kwobject