Forum Discussion

chmelvv's avatar
chmelvv
Occasional Contributor
8 years ago
Solved

How to modify testStepResult?

Hi, I use log processing script (as TestSuite tear down script) used for a lot of our projects. It gets information (like request URL) from testStepResult. But I need to add more information unique...
  • chmelvv's avatar
    chmelvv
    8 years ago

    Hi Tanya,

    thanks for quick reply!

     

    I chose following solution: I used event listener TestRunListener.afterStep and inside it after each step append needed information into TestSuite property, then in test suite TearDown script wrote it to needed file.

     

    1) TestSuite`s Setup Script:

    To clean data from previous run.

    testSuite.getTestCaseByName("testCaseName").setPropertyValue("logFile", "")

    2) Event Listener

    Name: TestRunListener.afterStep

    Event: TestRunListener.afterStep

    Target: Rest request (inside testCaseName test case)

    if ( "FAILED".equals( testStepResult.getStatus().toString() ) ){
       def URL = testStepResult.getMessageExchanges()[0].getProperty("URL")
    	
       def parameter1 = context.expand( '${DataSource#<SOME_PARAMETER1>}' )
       def parameter2 = context.expand( '${DataSource#<SOME_PARAMETER2>}' )
    
    def logFile = testRunner.getTestCase().getProperty("logFile").getValue() + URL 
    + " " + parameter1 + " " + parameter2 + "\n"
    	testRunner.getTestCase().setPropertyValue("logFile", logFile)
    }

     

    3) TestSuite`s TearDown Script:

    File reportFile = new File("report.txt")
    	
    def logFile = testSuite.getTestCaseByName("testCaseName").getProperty("logFile").getValue()
    reportFile.write(logFile , "utf-8")