def executeScript(inputScript, scriptOptionalArgs, inputFile=None):
    global testcaseInfoList
    global testcaseInfo
    global yamlCont
    testcaseInfoList = []
    yamlCont = {}
    if inputFile != None:
        fil = open(inputFile, "r")
        yamlCont = yaml.load(fil)
#        inputFileType = re.search('(.*).yaml', inputFile).group(1)

    inputFileType = 'unknown'
    if inputFile != None:
        inputFileType = re.search('(.*).yaml', inputFile).group(1)
    cmd = "%s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    #inputFileType = 'unknown'
    print "@@@@@@@@@@@@@@@"
    print cmd
    print "@@@@@@@@@@@@@@@"
    ps = winpexpect.winspawn(cmd)
    ps.logfile_read = sys.stdout

    ## Initialize testcaseInfo if the script is not a flist.
    if inputFileType in ['unknown']:
        scriptName = inputScript
        testcaseInfo = testInfo(scriptName)
        testcaseInfoList.append(testcaseInfo)

    timeout = -1
    ps.interact(output_filter=scriptExecutionMonitor)

    if inputFileType is 'unknown':
        ## creates a nested suite
        suiteList = []
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            suite = createRobotSuite(testcaseInfo)
            suiteList.append(suite)
        suite = TestSuite(inputScript)
        suite.suites = suiteList
        result = suite.run(output='output.xml', loglevel='debug')
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.variableFile.close()
    else:
        ## creates a single suite
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            print testcaseInfo
            suite = createRobotSuite(testcaseInfo)
            result = suite.run(output='output.xml', loglevel='debug')
            testcaseInfo.variableFile.close()

    # Generating log files requires processing the earlier generated output XML.
    ResultWriter('output.xml').write_results()
    pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)
    pp.close()
Beispiel #2
0
 def main(self, datasources, **options):
     STOP_SIGNAL_MONITOR.start()
     settings = RobotSettings(options)
     pyloggingconf.initialize(settings['LogLevel'])
     LOGGER.register_console_logger(width=settings['MonitorWidth'],
                                    colors=settings['MonitorColors'],
                                    stdout=settings['StdOut'],
                                    stderr=settings['StdErr'])
     init_global_variables(settings)
     suite = TestSuite(datasources, settings)
     output = Output(settings)
     suite.run(output)
     LOGGER.info("Tests execution ended. Statistics:\n%s" % suite.get_stat_message())
     output.close(suite)
     if settings.is_rebot_needed():
         output, settings = settings.get_rebot_datasource_and_settings()
         ResultWriter(output).write_results(settings)
     return suite.return_code
 def setUp(self):
     self.suite = TestSuite()
     self.suite.suites = self._generate_suites()
     self.suite.tests = self._generate_tests()
class TestRandomizing(unittest.TestCase):
    names = [str(i) for i in range(100)]

    def setUp(self):
        self.suite = TestSuite()
        self.suite.suites = self._generate_suites()
        self.suite.tests = self._generate_tests()

    def _generate_suites(self):
        return [TestSuite(name=n) for n in self.names]

    def _generate_tests(self):
        return [TestCase(name=n) for n in self.names]

    def _assert_randomized(self, items):
        assert_not_equals([i.name for i in items], self.names)

    def _assert_not_randomized(self, items):
        assert_equals([i.name for i in items], self.names)

    def test_randomize_nothing(self):
        self.suite.randomize(suites=False, tests=False)
        self._assert_not_randomized(self.suite.suites)
        self._assert_not_randomized(self.suite.tests)

    def test_randomize_only_suites(self):
        self.suite.randomize(suites=True, tests=False)
        self._assert_randomized(self.suite.suites)
        self._assert_not_randomized(self.suite.tests)

    def test_randomize_only_tests(self):
        self.suite.randomize(suites=False, tests=True)
        self._assert_not_randomized(self.suite.suites)
        self._assert_randomized(self.suite.tests)

    def test_randomize_both(self):
        self.suite.randomize(suites=True, tests=True)
        self._assert_randomized(self.suite.suites)
        self._assert_randomized(self.suite.tests)

    def test_randomize_recursively(self):
        self.suite.suites[0].suites = self._generate_suites()
        self.suite.suites[1].tests = self._generate_tests()
        self.suite.randomize(suites=True, tests=True)
        self._assert_randomized(self.suite.suites[0].suites)
        self._assert_randomized(self.suite.suites[1].tests)

    def test_randomizing_changes_ids(self):
        assert_equals([s.id for s in self.suite.suites],
                      ['s1-s%d' % i for i in range(1, 101)])
        assert_equals([t.id for t in self.suite.tests],
                      ['s1-t%d' % i for i in range(1, 101)])
        self.suite.randomize(suites=True, tests=True)
        assert_equals([s.id for s in self.suite.suites],
                      ['s1-s%d' % i for i in range(1, 101)])
        assert_equals([t.id for t in self.suite.tests],
                      ['s1-t%d' % i for i in range(1, 101)])
Beispiel #5
0
 def _run(self, stdout=None, stderr=None, **options):
     suite = TestSuite(name='My Suite')
     suite.resource.variables.create('${MESSAGE}', 'Hello, world!')
     suite.tests.create(name='My Test').body.create(
         'Log', args=['${MESSAGE}', 'WARN'])
     run(suite, stdout=stdout, stderr=stderr, **options)
Beispiel #6
0
 def setUp(self):
     self.suite = TestSuite()
     self.suite.suites = self._generate_suites()
     self.suite.tests = self._generate_tests()
Beispiel #7
0
class TestRandomizing(unittest.TestCase):
    names = [str(i) for i in range(100)]

    def setUp(self):
        self.suite = TestSuite()
        self.suite.suites = self._generate_suites()
        self.suite.tests = self._generate_tests()

    def _generate_suites(self):
        return [TestSuite(name=n) for n in self.names]

    def _generate_tests(self):
        return [TestCase(name=n) for n in self.names]

    def _assert_randomized(self, items):
        assert_not_equals([i.name for i in items], self.names)

    def _assert_not_randomized(self, items):
        assert_equals([i.name for i in items], self.names)

    def test_randomize_nothing(self):
        self.suite.randomize(suites=False, tests=False)
        self._assert_not_randomized(self.suite.suites)
        self._assert_not_randomized(self.suite.tests)

    def test_randomize_only_suites(self):
        self.suite.randomize(suites=True, tests=False)
        self._assert_randomized(self.suite.suites)
        self._assert_not_randomized(self.suite.tests)

    def test_randomize_only_tests(self):
        self.suite.randomize(suites=False, tests=True)
        self._assert_not_randomized(self.suite.suites)
        self._assert_randomized(self.suite.tests)

    def test_randomize_both(self):
        self.suite.randomize(suites=True, tests=True)
        self._assert_randomized(self.suite.suites)
        self._assert_randomized(self.suite.tests)

    def test_randomize_recursively(self):
        self.suite.suites[0].suites = self._generate_suites()
        self.suite.suites[1].tests = self._generate_tests()
        self.suite.randomize(suites=True, tests=True)
        self._assert_randomized(self.suite.suites[0].suites)
        self._assert_randomized(self.suite.suites[1].tests)

    def test_randomizing_changes_ids(self):
        assert_equals([s.id for s in self.suite.suites],
                      ['s1-s%d' % i for i in range(1, 101)])
        assert_equals([t.id for t in self.suite.tests],
                      ['s1-t%d' % i for i in range(1, 101)])
        self.suite.randomize(suites=True, tests=True)
        assert_equals([s.id for s in self.suite.suites],
                      ['s1-s%d' % i for i in range(1, 101)])
        assert_equals([t.id for t in self.suite.tests],
                      ['s1-t%d' % i for i in range(1, 101)])
Beispiel #8
0
 def _generate_suites(self):
     return [TestSuite(name=n) for n in self.names]
Beispiel #9
0
def executeScript(inputScript, scriptOptionalArgs, inputFile=None):
    global testcaseInfoList
    global testcaseInfo
    global yamlCont
    testcaseInfoList = []
    yamlCont = {}
    if inputFile != None:
        fil = open(inputFile, "r")
        yamlCont = yaml.load(fil)
#        inputFileType = re.search('(.*).yaml', inputFile).group(1)

    if re.search("\.log\.", inputScript):
        cmd = "python /work/swtest01_1/sgsubramaniam/sw-test/special_script/demoScript/slowcat.py -d 0.002 %s" %inputScript
    else:
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    if re.search("\.flist$", inputScript):
        inputFileType = 'flist'
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    elif re.search("\.f10$", inputScript):
        inputFileType = 'f10'
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    else:
        inputFileType = 'unknown'
        if inputFile != None:
            inputFileType = re.search('(.*).yaml', inputFile).group(1)
        cmd = "%s %s;echo '----------'" %(inputScript, ' '.join(scriptOptionalArgs))


    ps = winpexpect.winspawn(cmd)
    ps.logfile_read = sys.stdout

    ## Initialize testcaseInfo if the script is not a flist.
    if inputFileType in ['f10', 'unknown']:
        scriptName = inputScript
        testcaseInfo = testInfo(scriptName)
        testcaseInfoList.append(testcaseInfo)

    timeout = -1
    ps.interact(output_filter=scriptExecutionMonitor)

    if inputFileType is 'flist' or 'rspec':
        ## creates a nested suite
        suiteList = []
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            suite = createRobotSuite(testcaseInfo)
            suiteList.append(suite)
        suite = TestSuite(inputScript)
        suite.suites = suiteList
        result = suite.run(output='output.xml', loglevel='debug')
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.variableFile.close()
    else:
        ## creates a single suite
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            print testcaseInfo
            suite = createRobotSuite(testcaseInfo)
            result = suite.run(output='output.xml', loglevel='debug')
            testcaseInfo.variableFile.close()

    # Generating log files requires processing the earlier generated output XML.
    ResultWriter('output.xml').write_results()
    pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)
    pp.close()
 def _generate_suite(self):
     s = TestSuite()
     s.suites = self._generate_suites()
     s.tests = self._generate_tests()
     return s
Beispiel #11
0
        self.running = False

# MAIN SCRIPT #################################################################################################

# parsing command line arguments
parseArgs(sys.argv[1:])

# generating two lists containing parallel and serial tests
para_tests = []
seri_tests = []
seri_start_tests = []
seri_end_tests = []


suiteOps = settings.RobotSettings()
suite = TestSuite([os.path.join(testDirectory, suite_name)], suiteOps)

listOfTests = []

process_suite(suite, listOfTests)		

print "Number of tests = %s" %len(listOfTests)


#for test in suite.tests:
for test in listOfTests:
    #print "run %s?" %test.longname
    for testToRun in testsToRun:
        if test.longname == testToRun:
            print "going to run %s" %test.longname
            series = is_test_series(test)
Beispiel #12
0
    def test_start_end_body_item(self):
        class Visitor(SuiteVisitor):
            def __init__(self):
                self.visited = []

            def start_body_item(self, item):
                self.visited.append(f'START {item.type}')

            def end_body_item(self, item):
                self.visited.append(f'END {item.type}')

        visitor = Visitor()
        RunningSuite.from_model(get_model('''
*** Test Cases ***
Example
    IF    True
        WHILE    True
            BREAK
        END
    ELSE IF    True
        FOR    ${x}    IN    @{stuff}
            CONTINUE
        END
    ELSE
        TRY
            Keyword
        EXCEPT    Something
            Keyword
        ELSE
            Keyword
        FINALLY
            Keyword
        END
    END
''')).visit(visitor)
        expected = '''
START IF/ELSE ROOT
    START IF
        START WHILE
            START BREAK
            END BREAK
        END WHILE
    END IF
    START ELSE IF
        START FOR
            START CONTINUE
            END CONTINUE
        END FOR
    END ELSE IF
    START ELSE
        START TRY/EXCEPT ROOT
            START TRY
                START KEYWORD
                END KEYWORD
            END TRY
            START EXCEPT
                START KEYWORD
                END KEYWORD
            END EXCEPT
            START ELSE
                START KEYWORD
                END KEYWORD
            END ELSE
            START FINALLY
                START KEYWORD
                END KEYWORD
            END FINALLY
        END TRY/EXCEPT ROOT
    END ELSE
END IF/ELSE ROOT
'''.strip().splitlines()
        assert_equal(visitor.visited, [e.strip() for e in expected])
Beispiel #13
0
    def run(self):
        # generating two lists containing parallel and serial tests
        para_tests = []
        seri_tests = []
        retlist = []

        for file in self.testlist:
            suiteOps = settings.RobotSettings()
            suite = TestSuite(file, suiteOps)

            for test in suite.tests:
                # special treatment for tests without tags:
                # include them into serial execution as long as no include tags are defined
                if not test.tags and len(self.includeTags) == 0:
                    seri_tests.append(file)
                # tests with tags:
                # filter excluded tests (if any), then filter included tests (if any), then scan for
                # parallel keyword and assign to parallel / serial block
                elif len(self.excludeTags) == 0 or not test._matches_tag(
                        self.excludeTags):
                    if len(self.includeTags) == 0 or test._matches_tag(
                            self.includeTags):
                        if test._matches_tag(self.para_tag):
                            para_tests.append(file)
                        else:
                            seri_tests.append(file)
                break  #check only the first test, otherwise stuff is going to break

        # output serial test list
        serMessage = "Serial tests: "
        if len(seri_tests) == 0:
            serMessage = serMessage + "NONE"
        else:
            for test in seri_tests:
                serMessage = serMessage + test + " "
        self.log.msg(serMessage)

        # splitting parallel tests into blocks
        para_test_blocks = self.splitTestsToBlocks(para_tests)

        # output parallel test list
        paraMessage = "Parallel tests: "
        for block in para_test_blocks:
            for test in block:
                paraMessage = paraMessage + test + " "
        if len(para_test_blocks) == 0:
            paraMessage = paraMessage + "NONE"
        self.log.msg(paraMessage)

        # starting parallel pybots
        i = 0
        pybots = []
        for block in para_test_blocks:
            dynArgs = self.getDynArgs(i)
            self.log.msg(self.suite_name)
            pybots.append(
                self.startPybot("paraBlock_%s" % i, block, self.suite_name,
                                self.conf, i, dynArgs))
            retlist.append(self.conf['general']['slave_user'] + "@" +
                           self.conf['general']['slaves'][i])
            i = i + 1
            # delay start of next pybot
            time.sleep(5)

        # waiting for parallel tests to finish
        finished = False
        while not finished:
            time.sleep(10)
            message = "Finished: %s" % finished
            finished = True
            for pybot in pybots:
                message = "%s | %s: " % (message, pybot.name)
                if pybot.isRunning():
                    finished = False
                else:
                    message = "%s%s" % (message, "DONE")
        self.log.msg(message)

        self.log.msg("Parallel Tests finished ...")

        # running serial block
        pybot = None
        if len(seri_tests) > 0:
            self.log.msg("Starting serial tests...")
            pybot = self.startPybot("serial_block", seri_tests,
                                    self.suite_name, self.conf, 0,
                                    self.getDynArgs(0))
            while pybot.isRunning():
                time.sleep(5)

            self.log.msg("Serial tests finished")

        # merging outputs to one report and log
        self.log.msg("Generating report and log")
        temp, suiteName = os.path.split(self.suite_name)
        output = self.logFolder + "para_output.xml"
        report = "%s_Report.html" % os.path.join(self.logFolder, suiteName)
        log = "%s_Log.html" % os.path.join(self.logFolder, suiteName)
        outputXmls = []
        if pybot != None:
            outputXmls.append(os.path.join(self.logFolder, pybot.output))
        for pybot in pybots:
            outputXmls.append(os.path.join(self.logFolder, pybot.output))

        reportRC = self.generateReportAndLog(outputXmls, output, report, log)

        # delete XML output files after generating the report / log (if report generating
        # returned zero)
        #if reportRC == 0:
        #    for outXML in outputXmls:
        #        os.remove(outXML)

        # calculating test execution time
        endTime = datetime.now()
        executionTime = endTime - self.startTime
        self.log.msg("Execution time:", executionTime)

        retlist.insert(0, "ok")

        return retlist
Beispiel #14
0
 def test_invalid_import_type(self):
     assert_raises_with_msg(ValueError,
                            "Invalid import type 'InvalidType'. Should be "
                            "one of 'Library', 'Resource' or 'Variables'.",
                            TestSuite().imports.create,
                            'InvalidType', 'Name')
 def _generate_suite(self):
     s = TestSuite()
     s.suites = self._generate_suites()
     s.tests  = self._generate_tests()
     return s
Beispiel #16
0
def executeScript(inputScript, scriptOptionalArgs, inputFile=None):
    global testcaseInfoList
    global testcaseInfo
    global yamlCont
    testcaseInfoList = []
    yamlCont = {}
    if inputFile != None:
        fil = open(inputFile, "r")
        yamlCont = yaml.load(fil)
    #        inputFileType = re.search('(.*).yaml', inputFile).group(1)

    if re.search("\.log\.", inputScript):
        cmd = (
            "python /work/swtest01_1/sgsubramaniam/sw-test/special_script/demoScript/slowcat.py -d 0.002 %s"
            % inputScript
        )
    else:
        cmd = "f10tool %s %s" % (inputScript, " ".join(scriptOptionalArgs))
    if re.search("\.flist$", inputScript):
        inputFileType = "flist"
        cmd = "f10tool %s %s" % (inputScript, " ".join(scriptOptionalArgs))
    elif re.search("\.f10$", inputScript):
        inputFileType = "f10"
        cmd = "f10tool %s %s" % (inputScript, " ".join(scriptOptionalArgs))
    else:
        inputFileType = "unknown"
        if inputFile != None:
            inputFileType = re.search("(.*).yaml", inputFile).group(1)
        cmd = "%s %s;echo '----------'" % (inputScript, " ".join(scriptOptionalArgs))

    ps = winpexpect.winspawn(cmd)
    ps.logfile_read = sys.stdout

    ## Initialize testcaseInfo if the script is not a flist.
    if inputFileType in ["f10", "unknown"]:
        scriptName = inputScript
        testcaseInfo = testInfo(scriptName)
        testcaseInfoList.append(testcaseInfo)

    timeout = -1
    ps.interact(output_filter=scriptExecutionMonitor)

    if inputFileType is "flist" or "rspec":
        ## creates a nested suite
        suiteList = []
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            suite = createRobotSuite(testcaseInfo)
            suiteList.append(suite)
        suite = TestSuite(inputScript)
        suite.suites = suiteList
        result = suite.run(output="output.xml", loglevel="debug")
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.variableFile.close()
    else:
        ## creates a single suite
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            print testcaseInfo
            suite = createRobotSuite(testcaseInfo)
            result = suite.run(output="output.xml", loglevel="debug")
            testcaseInfo.variableFile.close()

    # Generating log files requires processing the earlier generated output XML.
    ResultWriter("output.xml").write_results()
    pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)
    pp.close()
Beispiel #17
0
def generate_test_doc(args):
    opts, datasources = process_arguments(args)
    suite = TestSuite(datasources, RobotSettings(opts))
    outpath = get_outpath(opts['output'], suite.name)
    serialize_test_doc(suite, outpath, opts['title'])
    exit(msg=outpath)