Esempio n. 1
0
    def RunTestCaseType3_flag(self, appPath, testCase):
        '''
        This method runs type3 tests with flag type actions. This kind of test takes as input a list
        of arguments (action) and waits for user interaction. User has to answer
        yes or no to an expected statement.
        If at least one action fails (a negative answer from the user), the test will fail.
        '''    
        testFailed = False
        testActions = {}
        sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
        for actionId, action in sortedCases:
            if testFailed == True:
                break      
            testActions[actionId] = None
            appArgs = appPath+' '+action.action
            args = shlex.split(appArgs)
            try:
                app = Process(args)
            except OSError:
                sys.exit("Error, please specify a valid path for the tested application.")
            while testActions[actionId] == None:
                for responseId, response in sorted(testCase.responses.iteritems()):
                    if responseId == actionId:
                        print "\n", response.response
                        print "YES/NO"  #YES, test passato. No, test Fallito
                        user_answer = lower(raw_input())
                        if user_answer.find('y') != -1:
                            print "TestCase %s Action %s Passed\n" % (testCase.id, actionId)
                            self.TakeScreenshot(testCase.id, actionId)
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)
                            testActions[actionId] = True
                            
                        if user_answer.find('n') != -1:
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)
                            
                            testActions[actionId] = False
                            testFailed = True
                        if user_answer.find('n') == -1 and user_answer.find('y') == -1:
                            pass
                        
        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                self.TakeScreenshot(testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            self.TakeScreenshot(testCase.id)
            testCase.status = 'PASSED'
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 2
0
    def RunTestCaseType3_flag(self, appPath, testCase):
        '''
        This method runs type3 tests with flag type actions. This kind of test takes as input a list
        of arguments (action) and waits for user interaction. User has to answer
        yes or no to an expected statement.
        If at least one action fails (a negative answer from the user), the test will fail.
        '''    
        testFailed = False
        testActions = {}
        sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
        for actionId, action in sortedCases:
            if testFailed == True:
                break      
            testActions[actionId] = None
            appArgs = appPath+' '+action.action
            args = shlex.split(appArgs)
            try:
                app = Process(args)
            except OSError:
                sys.exit("Error, please specify a valid path for the tested application.")
            while testActions[actionId] == None:
                for responseId, response in sorted(testCase.responses.iteritems()):
                    if responseId == actionId:
                        print "\n", response.response
                        print "YES/NO"  #YES, test passato. No, test Fallito
                        user_answer = lower(raw_input())
                        if user_answer.find('y') != -1:
                            print "TestCase %s Action %s Passed\n" % (testCase.id, actionId)
                            self.TakeScreenshot(testCase.id, actionId)
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)
                            testActions[actionId] = True
                            
                        if user_answer.find('n') != -1:
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)
                            
                            testActions[actionId] = False
                            testFailed = True
                        if user_answer.find('n') == -1 and user_answer.find('y') == -1:
                            pass
                        
        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                self.TakeScreenshot(testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            self.TakeScreenshot(testCase.id)
            testCase.status = 'PASSED'
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 3
0
 def RunTestCaseType2_command(self, appPath, testCase):
     '''
     This method runs type2 tests with command type actions. This kind of test takes as input a list
     of arguments (action) and search for a log in the standard output of the
     application to be tested. User can skip any test actions using a 
     Keyboard interrupt (CTRL+C)
     If at least one action fails to retrieve its log, the test will fail.
     A timeout has to be setted before (default value is 900sec)
     '''       
     testFailed = False
     testActions = {}
     print "Launching main application."
     appArgs = appPath
     args = shlex.split(appArgs)
     ready = False
     
     try:
         app = Process(args)
     except OSError, e:
         print str(e)
         sys.exit("Error, please specify a valid path for the tested application.")
Esempio n. 4
0
    def RunTestCaseType3_command(self, appPath, testCase):
        '''
        This method runs type3 tests with c type actions. This kind of test takes as input a list
        of arguments (action) and waits for user interaction. User has to answer
        yes or no to an expected statement.
        If at least one action fails (a negative answer from the user), the test will fail.
        '''    
        testFailed = False
        testActions = {}
        print "Launching main application."
        appArgs = appPath
        args = shlex.split(appArgs)
        ready = False
        try:
            app = Process(args)
        except OSError:
            sys.exit("Error, please specify a valid path for the tested application.")
        while ready == False:
            outAndErr = app.readboth()
            for out in outAndErr:
                if out.find(self.readyLog) != -1:
                    print "Main application is ready, starting test actions"
                    ready = True
        
        sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
        for actionId, action in sortedCases:
            if testFailed == True:
                break

            actionArgs = shlex.split(action.action)
            try:
                actionRunning = Popen(actionArgs)
            except OSError:
                if self.userDefinedKill is None:
                    app.terminate()
                else:
                    Popen(self.userDefinedKill)
                
                errorAction = "Error, please specify a valid command for action %s." % actionId
                sys.exit(errorAction)
            
            testActions[actionId] = None
            print "Running Action %s, Press CTRL-C to skip test" % actionId    
                      
            while testActions[actionId] == None:   
                for responseId, response in sorted(testCase.responses.iteritems()):
                    if responseId == actionId:
                        print "\n", response.response
                        print "YES/NO"  #YES, test passed. No, test failed
                        user_answer = lower(raw_input())
                        if user_answer.find('y') != -1:
                            print "TestCase %s Action %s Passed\n" % (testCase.id, actionId)
                            self.TakeScreenshot(testCase.id, actionId)
                            sleep(self.sleepingTime)
                            actionRunning.kill()
                            testActions[actionId] = True
                        if user_answer.find('n') != -1:
                            sleep(self.sleepingTime)
                            actionRunning.kill()
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)

                            testActions[actionId] = False
                            testFailed = True
                        if user_answer.find('n') == -1 and user_answer.find('y') == -1:
                            pass
                        
        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                self.TakeScreenshot(testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            self.TakeScreenshot(testCase.id)
            testCase.status = 'PASSED'
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 5
0
    def RunTestCaseType2_flag(self, appPath, testCase):
        '''
        This method runs type2 tests with flag type actions. This kind of test takes as input a list
        of arguments (action) and search for a log in the standard output of the
        application to be tested. User can skip any test actions using a 
        Keyboard interrupt (CTRL+C)
        If at least one action fails to retrieve its log, the test will fail.
        A timeout has to be setted before (default value is 900sec)
        '''       
        testFailed = False
        testActions = {}
        try:
            sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
            for actionId, action in sortedCases:
                if testFailed == True:
                    break
                print "Running Action %s, Press CTRL-C to skip test" % actionId    
                testActions[actionId] = None
                appArgs = appPath+' '+action.action
                args = shlex.split(appArgs)          
                try:
                    app = Process(args)
                except OSError:
                    sys.exit("Error, please specify a valid path for the tested application.")
                startTime = time()              
                while testActions[actionId] == None:   
                    outAndErr = app.readboth()
                    for out in outAndErr:
                        sleep(0.1)
                        for responseId, response in sorted(testCase.responses.iteritems()):
                            if responseId == actionId:
                                log = response.response
                                
                                if out.find(log) != -1:
                                    print "TestCase %s Action %s Passed" % (testCase.id, actionId) 
                                    testActions[actionId] = True          
                                    if self.userDefinedKill is None:
                                        app.terminate()
                                    else:
                                        Popen(self.userDefinedKill)
                                        
                                if out.find(log) == -1 and time()-startTime>self.timeOut:
                                    print "\nTestCase %s Action %s Failed" % (testCase.id, actionId)
                                    
                                    if self.userDefinedKill is None:
                                        app.terminate()
                                    else:
                                        Popen(self.userDefinedKill)
                                    
                                    testActions[actionId] = False
                                    testFailed = True 
                                                     
        except KeyboardInterrupt:
            print "\nTestCase %s Action %s Failed" % (testCase.id, actionId)
            
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
            
            testActions[actionId] = False
            testFailed = True

        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            testCase.status = 'PASSED'
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 6
0
    def RunTestCaseType3_command(self, appPath, testCase):
        '''
        This method runs type3 tests with c type actions. This kind of test takes as input a list
        of arguments (action) and waits for user interaction. User has to answer
        yes or no to an expected statement.
        If at least one action fails (a negative answer from the user), the test will fail.
        '''    
        testFailed = False
        testActions = {}
        print "Launching main application."
        appArgs = appPath
        args = shlex.split(appArgs)
        ready = False
        try:
            app = Process(args)
        except OSError:
            sys.exit("Error, please specify a valid path for the tested application.")
        while ready == False:
            outAndErr = app.readboth()
            for out in outAndErr:
                if out.find(self.readyLog) != -1:
                    print "Main application is ready, starting test actions"
                    ready = True
        
        sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
        for actionId, action in sortedCases:
            if testFailed == True:
                break

            actionArgs = shlex.split(action.action)
            try:
                actionRunning = Popen(actionArgs)
            except OSError:
                if self.userDefinedKill is None:
                    app.terminate()
                else:
                    Popen(self.userDefinedKill)
                
                errorAction = "Error, please specify a valid command for action %s." % actionId
                sys.exit(errorAction)
            
            testActions[actionId] = None
            print "Running Action %s, Press CTRL-C to skip test" % actionId    
                      
            while testActions[actionId] == None:   
                for responseId, response in sorted(testCase.responses.iteritems()):
                    if responseId == actionId:
                        print "\n", response.response
                        print "YES/NO"  #YES, test passed. No, test failed
                        user_answer = lower(raw_input())
                        if user_answer.find('y') != -1:
                            print "TestCase %s Action %s Passed\n" % (testCase.id, actionId)
                            self.TakeScreenshot(testCase.id, actionId)
                            sleep(self.sleepingTime)
                            actionRunning.kill()
                            testActions[actionId] = True
                        if user_answer.find('n') != -1:
                            sleep(self.sleepingTime)
                            actionRunning.kill()
                            if self.userDefinedKill is None:
                                app.terminate()
                            else:
                                Popen(self.userDefinedKill)

                            testActions[actionId] = False
                            testFailed = True
                        if user_answer.find('n') == -1 and user_answer.find('y') == -1:
                            pass
                        
        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                self.TakeScreenshot(testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            self.TakeScreenshot(testCase.id)
            testCase.status = 'PASSED'
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 7
0
    def RunTestCaseType2_flag(self, appPath, testCase):
        '''
        This method runs type2 tests with flag type actions. This kind of test takes as input a list
        of arguments (action) and search for a log in the standard output of the
        application to be tested. User can skip any test actions using a 
        Keyboard interrupt (CTRL+C)
        If at least one action fails to retrieve its log, the test will fail.
        A timeout has to be setted before (default value is 900sec)
        '''       
        testFailed = False
        testActions = {}
        try:
            sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
            for actionId, action in sortedCases:
                if testFailed == True:
                    break
                print "Running Action %s, Press CTRL-C to skip test" % actionId    
                testActions[actionId] = None
                appArgs = appPath+' '+action.action
                args = shlex.split(appArgs)          
                try:
                    app = Process(args)
                except OSError:
                    sys.exit("Error, please specify a valid path for the tested application.")
                startTime = time()              
                while testActions[actionId] == None:   
                    outAndErr = app.readboth()
                    for out in outAndErr:
                        sleep(0.5)
                        for responseId, response in sorted(testCase.responses.iteritems()):
                            if responseId == actionId:
                                log = response.response
                                
                                if out.find(log) != -1:
                                    print "TestCase %s Action %s Passed" % (testCase.id, actionId) 
                                    testActions[actionId] = True          
                                    if self.userDefinedKill is None:
                                        app.terminate()
                                    else:
                                        Popen(self.userDefinedKill)
                                        
                                if out.find(log) == -1 and time()-startTime>self.timeOut:
                                    print "\nTestCase %s Action %s Failed" % (testCase.id, actionId)
                                    
                                    if self.userDefinedKill is None:
                                        app.terminate()
                                    else:
                                        Popen(self.userDefinedKill)
                                    
                                    testActions[actionId] = False
                                    testFailed = True 
                                                     
        except KeyboardInterrupt:
            print "\nTestCase %s Action %s Failed" % (testCase.id, actionId)
            
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
            
            testActions[actionId] = False
            testFailed = True

        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                testCase.status = 'FAILED (%s)' % id 

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            testCase.status = 'PASSED'
        result = (testCase.id,testCase.status)       
        return result
Esempio n. 8
0
    def RunTestCaseType1(self, appPath, testCase):
        """
        This method runs type1 tests. This kind of test takes asks user to do an
        action and search for a log in the standard output of the
        application to be tested. User can skip any test action using a 
        Keyboard interrupt (CTRL+C)
        If at least one action fails to retrieve its log, the test will fail.
        A timeout has to be set before (default value is 15min).
        """
        testFailed = False
        testActions = {}
        appArgs = appPath
        args = shlex.split(appArgs)
        try:
            app = Process(args)
        except OSError:
            sys.exit("Error, please specify a valid path for the tested application.")
        try:
            sortedCases = [(k, testCase.actions[k]) for k in sorted(testCase.actions, key=asint)]
            for actionId, action in sortedCases:
                if testFailed == True:
                    break
                startTime = time()
                testActions[actionId] = None
                print "\n", actionId, action.action
                print "Press CTRL-C to skip test"
                while testActions[actionId] == None:
                    outAndErr = app.readboth()
                    for out in outAndErr:
                        sleep(0.1)
                        for responseId, response in sorted(testCase.responses.iteritems()):
                            if responseId == actionId:
                                log = response.response
                                if out.find(log) != -1:
                                    print "TestCase %s Action %s Passed" % (testCase.id, actionId)
                                    testActions[actionId] = True
                                if out.find(log) == -1 and time() - startTime > self.timeOut:
                                    print "TestCase %s Action %s Failed" % (testCase.id, actionId)
                                    print "Press q to terminate this test or r to retry it"
                                    userInput = raw_input()

                                    if userInput == "q":
                                        if self.userDefinedKill is None:
                                            app.terminate()
                                        else:
                                            Popen(self.userDefinedKill)

                                        testActions[actionId] = False
                                        testFailed = True

                                    if userInput == "r":
                                        startTime = time()
                                        print actionId, action.action

                                    if userInput != "q" and userInput != "r":
                                        print "Press q to terminate this test or to retry it"
                                        userInput = raw_input()

        except KeyboardInterrupt:
            print "\nTestCase %s Action %s Failed" % (testCase.id, actionId)
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
            testActions[actionId] = False
            testFailed = True

        for id, t in testActions.iteritems():
            if t == False:
                testFailed = True
                print "TEST %s FAILED, (action %s)" % (testCase.id, id)
                testCase.status = "FAILED (%s)" % id

        if testFailed == False:
            print "TEST %s PASSED" % testCase.id
            testCase.status = "PASSED"
            if self.userDefinedKill is None:
                app.terminate()
            else:
                Popen(self.userDefinedKill)
        result = (testCase.id, testCase.status)
        return result