def runTest(self, projectPath, projectFile, testsuiteName, testcaseName, endpoint='', projectProperties={}): """ Run a testcase @param projectPath: project path @type projectPath: string @param projectFile: xml file @type projectFile: string @param testsuiteName: testsuite name @type testsuiteName: string @param testcaseName: testcase name @type testcaseName: string @param endpoint: endpoint used (default='') @type endpoint: string @param projectProperties: project properties @type projectProperties: dict """ if len(endpoint): self.cfg['soapui-options'].append("-e %s" % endpoint) if len(projectProperties): for k, v in projectProperties.items(): self.cfg['soapui-options'].append("-P%s=%s" % (k, v)) agentData = { 'project-path': projectPath, 'project-file': projectFile, 'testsuite-name': testsuiteName, 'testcase-name': testcaseName, 'options': self.cfg['soapui-options'] } # send command to agent self.debug("request: %s" % agentData) self.sendNotifyToAgent(data=agentData) # log event tpl = self.encapsule( layer_soapui=templates.soapui(action=SOAPUI_RUN_TESTCASE, projectPath=projectPath, projectFile=projectFile, testsuiteName=testsuiteName, testcaseName=testcaseName)) self.logSentEvent(shortEvt="%s [%s -> %s]" % (SOAPUI_RUN_TESTCASE, testsuiteName, testcaseName), tplEvt=tpl)
def isStepStopped(self, timeout=20.0, stepId=None): """ """ if not ( isinstance(timeout, int) or isinstance(timeout, float) ) or isinstance(timeout,bool): raise TestAdapter.ValueException(TestAdapter.caller(), "timeout argument is not a float or integer (%s)" % type(timeout) ) # construct the expected template expected = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_STEP_STOPPED, stepId=stepId)) # try to match the template evt = self.received( expected=expected, timeout=timeout ) return evt
def isStepStopped(self, timeout=20.0, stepId=None): """ """ TestAdapter.check_timeout(caller=TestAdapter.caller(), timeout=timeout) # construct the expected template expected = self.encapsule(layer_soapui=templates.soapui( action=SOAPUI_STEP_STOPPED, stepId=stepId)) # try to match the template evt = self.received(expected=expected, timeout=timeout) return evt
def isTestcaseStopped(self, timeout=60.0): """ Wait to receive "testcase stopped" event until the end of the timeout The timeout is the max time to run all steps inside the testcase of soapui @param timeout: max time to run all steps of the testcase in second (default=60s) @type timeout: float @return: an event matching with the template or None otherwise @rtype: templatemessage """ if not ( isinstance(timeout, int) or isinstance(timeout, float) ) or isinstance(timeout,bool): raise TestAdapter.ValueException(TestAdapter.caller(), "timeout argument is not a float or integer (%s)" % type(timeout) ) # construct the expected template expected = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_TESTCASE_STOPPED)) # try to match the template evt = self.received( expected=expected, timeout=timeout ) return evt
def isTestcaseStopped(self, timeout=60.0): """ Wait to receive "testcase stopped" event until the end of the timeout The timeout is the max time to run all steps inside the testcase of soapui @param timeout: max time to run all steps of the testcase in second (default=60s) @type timeout: float @return: an event matching with the template or None otherwise @rtype: templatemessage """ TestAdapter.check_timeout(caller=TestAdapter.caller(), timeout=timeout) # construct the expected template expected = self.encapsule(layer_soapui=templates.soapui( action=SOAPUI_TESTCASE_STOPPED)) # try to match the template evt = self.received(expected=expected, timeout=timeout) return evt
def receivedNotifyFromAgent(self, data): """ Function to reimplement """ line = data['msg'] self.debug(line) # start of the run if 'Running TestCase' in line: tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_TESTCASE_STARTED)) self.logRecvEvent( shortEvt = SOAPUI_TESTCASE_STARTED, tplEvt = tpl ) # end of the run if 'TestCaseRunner Summary' in line: tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_TESTCASE_STOPPED)) self.logRecvEvent( shortEvt = SOAPUI_TESTCASE_STOPPED, tplEvt = tpl ) # send request if 'Sending request: ' in line: self.warning( "%s" % line.split("Sending request: ")[1].strip() ) # receive request if 'Receiving response:' in line: self.warning( "%s" % line.split("Receiving response:")[1].strip() ) # create step if ' running step ' in line: self.stepId += 1 self.curStepName = line.split(' running step ')[1].strip()[1:-1] # log event tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_STEP_STARTED, stepId= "%s" % self.stepId)) self.logRecvEvent( shortEvt = "%s [Id=#%s]" % (SOAPUI_STEP_STARTED, self.stepId), tplEvt = tpl ) # starting thread to check response # thread = threading.Thread(target = self.isStepStopped, args=(self.cfg['step-timeout'] , "%s" % self.stepId) ) # self.threads_list.append( thread) # thread.start() # create step in testcase self.currentStep = self.testcase().addStep(expected=self.curStepName, description=self.curStepName, summary=self.curStepName) self.currentStep.start() # error on assertion if '[different]' in line: # log event # tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_STEP_STOPPED, stepId= "%s" % self.stepId)) # self.logRecvEvent( shortEvt = "%s [Id=#%s]" % (SOAPUI_STEP_STOPPED, self.stepId) , tplEvt = tpl ) # set the step to failed self.currentStep.setFailed(actual=line.split('[different]')[1].strip() ) #step passed if 'has status VALID' in line: tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_STEP_STOPPED, stepId= "%s" % self.stepId)) self.logRecvEvent( shortEvt = "%s [Id=#%s]" % (SOAPUI_STEP_STOPPED, self.stepId) , tplEvt = tpl ) msgOk = line.split( 'INFO [SoapUITestCaseRunner] ' )[1] self.currentStep.setPassed(actual=msgOk) # assert error detected if "ASSERTION FAILED ->" in line: tpl = self.encapsule(layer_soapui=templates.soapui(action=SOAPUI_STEP_STOPPED, stepId= "%s" % self.stepId)) self.logRecvEvent( shortEvt = "%s [Id=#%s]" % (SOAPUI_STEP_STOPPED, self.stepId) , tplEvt = tpl ) # set the step to failed self.currentStep.setFailed(actual=line.split('ASSERTION FAILED ->')[1].strip() ) # unable to load xml file if "java.lang.Exception: Failed to load SoapUI project file [" in line: lineTmp = line.split("Failed to load SoapUI project file [")[1].split("]", 1)[0] self.error("Failed to load SoapUI project file: %s" % lineTmp) # bad testcase name if " java.lang.Exception: TestCase with name [" in line: lineTmp = line.split("TestCase with name [")[1].split("]", 1)[0] self.error("Bad testcase name: %s" % lineTmp) # bad testsuite name if " java.lang.Exception: TestSuite with name [" in line: lineTmp = line.split("TestSuite with name [")[1].split("]", 1)[0] self.error("Bad testsuite name: %s" % lineTmp) # connect error if 'HttpHostConnectException' in line: if self.currentStep is not None: self.currentStep.setFailed("connection to host refused") else: self.error("connection to host refused") # just to be sure, if an error is not catched if "finished with status [FAILED] in" in line: self.testcase().setFailed()