def test_original_signal_handlers_are_restored(self): my_sigterm = lambda signum, frame: None signal.signal(signal.SIGTERM, my_sigterm) suite = TestSuite(name='My Suite') suite.tests.create(name='My Test').keywords.create('Log', args=['Hi!']) run(suite) assert_equals(signal.getsignal(signal.SIGINT), self.orig_sigint) assert_equals(signal.getsignal(signal.SIGTERM), my_sigterm)
def test_resource_imports(self): suite = TestSuite(name='Suite') suite.imports.resource('test_resource.txt') suite.tests.create(name='Test').keywords.create('My Test Keyword') assert_equals(suite.tests[0].keywords[0].name, 'My Test Keyword') result = run(suite) assert_suite(result, 'Suite', 'PASS') assert_test(result.tests[0], 'Test', 'PASS')
def test_failing_library_keyword(self): suite = TestSuite(name='Suite') test = suite.tests.create(name='Test') test.keywords.create('Log', args=['Dont fail yet.']) test.keywords.create('Fail', args=['Hello, world!']) result = run(suite) assert_suite(result, 'Suite', 'FAIL') assert_test(result.tests[0], 'Test', 'FAIL', msg='Hello, world!')
def test_library_imports(self): suite = TestSuite(name='Suite') suite.imports.library('OperatingSystem') suite.tests.create(name='Test').keywords.create('Directory Should Exist', args=['.']) result = run(suite) assert_suite(result, 'Suite', 'PASS') assert_test(result.tests[0], 'Test', 'PASS')
def test_user_keywords(self): suite = TestSuite(name='Suite') suite.tests.create(name='Test').keywords.create('User keyword', args=['From uk']) uk = suite.resource.keywords.create(name='User keyword', args=['${msg}']) uk.keywords.create(name='Fail', args=['${msg}']) result = run(suite) assert_suite(result, 'Suite', 'FAIL') assert_test(result.tests[0], 'Test', 'FAIL', msg='From uk')
def test_assign(self): suite = TestSuite(name='Suite') test = suite.tests.create(name='Test') test.keywords.create(assign=['${var}'], name='Set Variable', args=['value in variable']) test.keywords.create('Fail', args=['${var}']) result = run(suite) assert_suite(result, 'Suite', 'FAIL') assert_test(result.tests[0], 'Test', 'FAIL', msg='value in variable')
def test_reset_logging_conf(self): assert_equal(logging.getLogger().handlers, []) assert_equal(logging.raiseExceptions, 1) suite = TestSuite(name='My Suite') suite.tests.create(name='My Test').keywords.create('Log', args=['Hi!']) run(suite) assert_equal(logging.getLogger().handlers, []) assert_equal(logging.raiseExceptions, 1)
def TestSuiteFactory(datasources, **options): if isinstance(datasources, basestring): datasources = [datasources] populators.PROCESS_CURDIR = False try: return TestSuite(datasources, RobotSettings(options)) finally: populators.PROCESS_CURDIR = True
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()
def test_suites_in_suites(self): root = TestSuite(name='Root') root.suites.create(name='Child')\ .tests.create(name='Test')\ .keywords.create('Log', args=['Hello, world!']) result = run(root) assert_suite(result, 'Root', 'PASS', tests=0) assert_suite(result.suites[0], 'Child', 'PASS') assert_test(result.suites[0].tests[0], 'Test', 'PASS')
def test_variable_imports(self): suite = TestSuite(name='Suite') suite.resource.imports.variables('variables_file.py') suite.tests.create(name='Test').keywords.create( 'Should Be Equal As Strings', args=['${MY_VARIABLE}', 'An example string']) result = run(suite) assert_suite(result, 'Suite', 'PASS') assert_test(result.tests[0], 'Test', 'PASS')
def test_variables(self): suite = TestSuite(name='Suite') suite.resource.variables.create('${ERROR}', 'Error message') suite.resource.variables.create('@{LIST}', ['Error', 'added tag']) suite.tests.create(name='T1').keywords.create('Fail', args=['${ERROR}']) suite.tests.create(name='T2').keywords.create('Fail', args=['@{LIST}']) result = run(suite) assert_suite(result, 'Suite', 'FAIL', tests=2) assert_test(result.tests[0], 'T1', 'FAIL', msg='Error message') assert_test(result.tests[1], 'T2', 'FAIL', ('added tag',), 'Error')
def test_nested_setups_and_teardowns(self): root = TestSuite(name='Root') root.keywords.create('Fail', args=['Top level'], type='teardown') root.suites.append(self.suite) suite = run(root, variable=['SUITE SETUP:Fail', 'SUITE TEARDOWN:Fail']) assert_suite(suite, 'Root', 'FAIL', 'Suite teardown failed:\nTop level', 0) assert_suite(suite.suites[0], 'Setups And Teardowns', 'FAIL', 'Suite setup failed:\nAssertionError\n\n' 'Also suite teardown failed:\nAssertionError', 4) assert_test(suite.suites[0].tests[0], 'Test with setup and teardown', 'FAIL', msg='Parent suite setup failed:\nAssertionError\n\n' 'Also parent suite teardown failed:\nAssertionError\n\n' 'Also parent suite teardown failed:\nTop level')
def test_reset_logging_conf(self): import logging assert_equals(logging.getLogger().handlers, []) if not (sys.platform.startswith('java') and sys.version_info >= (2, 7)): assert_equals(logging.raiseExceptions, 1) suite = TestSuite(name='My Suite') suite.tests.create(name='My Test').keywords.create('Log', args=['Hi!']) run(suite) assert_equals(logging.getLogger().handlers, []) if not (sys.platform.startswith('java') and sys.version_info >= (2, 7)): assert_equals(logging.raiseExceptions, 1) else: assert_equals(logging.raiseExceptions, False)
def main(self, datasources, **options): STOP_SIGNAL_MONITOR.start() namespace.IMPORTER.reset() 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 createRobotSuite(testcaseInfo): suite = TestSuite(os.path.basename(testcaseInfo.scriptName)) suite.imports.library('logModule') suite.imports.variables(testcaseInfo.variableFile.name) tcList = [ val for val in testcaseInfo.tcInfo.keys() if val not in ['suite_setup', 'suite_cleanup'] ] if tcList: ## This suite has f10 testcases defined ## suite_setup should precede suite_cleanup. Otherwise, both will be set as None. if 'suite_setup' in testcaseInfo.tcInfo.keys(): suite.keywords.create('setup_log', args=['${setupLog}'], type='setup') if 'suite_cleanup' in testcaseInfo.tcInfo.keys(): suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown') else: ## This suite has no f10 testcases defined in the script. Entire script should be treated as one testcase if 'suite_cleanup' in testcaseInfo.tcInfo.keys(): suite.keywords.create('cleanup_log', args=['${cleanupLog}'], type='teardown') test = suite.tests.create(testcaseInfo.scriptName, tags=None) test.keywords.create( 'testcase_log', args=['${setupLog}', 'result=%s' % testcaseInfo.scriptResult]) for tcid in testcaseInfo.tcInfo.keys(): if tcid in ['suite_setup', 'suite_cleanup']: pass else: test = suite.tests.create(tcid, tags=None) print testcaseInfo test.keywords.create('testcase_log', args=['${testcaseInfo}', 'tcid=%s' % tcid]) return suite
def test_invalid_import_type(self): assert_raises_with_msg( ValueError, "Invalid import type 'InvalidType'. Should be " "one of 'Library', 'Resource' or 'Variables'.", TestSuite().resource.imports.create, 'InvalidType', 'Name')
def TestSuiteFactory(datasources, **options): if isinstance(datasources, basestring): datasources = [datasources] return TestSuite(datasources, RobotSettings(options))
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)
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
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)
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 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 XmlTestSuite(suite): if ROBOT_VERSION < '2.7': from robot.output import TestSuite return TestSuite(suite) from robot.result import ExecutionResult return ExecutionResult(suite).suite
def _run(self, stdout=None, stderr=None, **options): suite = TestSuite(name='My Suite') suite.variables.create('${MESSAGE}', 'Hello, world!') suite.tests.create(name='My Test').keywords.create( 'Log', args=['${MESSAGE}', 'WARN']) run(suite, stdout=stdout, stderr=stderr, **options)
def TestSuiteFactory(datasources, **options): return TestSuite(datasources, RobotSettings(options), process_variables=False)
def test_one_library_keyword(self): suite = TestSuite(name='Suite') suite.tests.create(name='Test').body.create_keyword('Log', args=['Hello!']) result = run(suite) assert_suite(result, 'Suite', 'PASS') assert_test(result.tests[0], 'Test', 'PASS')
def _generate_suite(self): s = TestSuite() s.suites = self._generate_suites() s.tests = self._generate_tests() return s