Forum Discussion

TesterNo1's avatar
TesterNo1
Contributor
9 years ago

Using GotoStepbyname from Event TestRunListener.afterStep

 

I am trying to use conditional go to from TestRunListener.afterStep but control is not transfered to respective step.Same stament in test case groovy works.i think i am missing somehting with variabales

 

i see this event is invoked with testrunner,context,testStepResult,log variables.

 

Intention is to write the logs in db if scenario fails.

 

 

testRunner.gotoStepByName("Step1")

                                             or 

context.getTestRunner().gotoStepByName("Step1")

 

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    If that is your requirement, then teardown script can be used. Sounds good?
    • TesterNo1's avatar
      TesterNo1
      Contributor

       

      Thanks Rao.

      Sometimes we tend to run our test cases one by one for debugging.In that case,i need to have tear down copied to each and every test case instead of suite level.That is why i thought it better be handled from event so it will be in one single place.Easy to make changes since code is in one place.

       

       

      what happens is testRunner.gotoStep("SQLWrite") does work when invoked from inside the event but it doesnt trigger when inside the below if condition.

       

       

       

       

      import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStepResult
      import com.eviware.soapui.model.testsuite.*
      import com.eviware.soapui.impl.wsdl.teststeps.RestRequestStepResult
      import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
      def xmlUtils = new com.eviware.soapui.support.xml.XmlUtils();
      
      if (!testStepResult.getStatus().toString().equals("OK"))
      {
      testStatus=testStepResult.getStatus().toString()
      currentTestStep=context.getCurrentStep().getLabel()
      testCaseComment=currentTestStep
      //log.info warnMsg
      def TestCase = testRunner.getTestCase().getName()
      log.info TestCase
      testRunner.testCase.getTestStepByName("TestRunnerProperties").setPropertyValue("TestLastFailedStep",testCaseComment)
      testRunner.testCase.getTestStepByName("TestRunnerProperties").setPropertyValue("TestCaseStatus",testStatus)
      
      testRunner.gotoStep("SQLWrite")
      context.getTestRunner().gotoStepByName("SQLWrite") 
      }
      
      
      • TesterNo1's avatar
        TesterNo1
        Contributor

        Rao,

         

        i tried  RunTestStepbyname followed by testrunner.fail and it did the job.

         

        Thank you :-)