Forum Discussion

seemamu's avatar
seemamu
New Contributor
6 years ago
Solved

how to capture teststep status as pass/fail using groovy to write it in txt file

i am trying to generate txt file with pass/fail status for each test step using grrovy. Can anyone help me please ?

  • This can be done very simply by using the following TearDown Script:

     

    // Define variables for holding test suites, test cases and test steps
    def testSuites
    def testCases
    def testSteps
    
    // Get all the test suites from the project
    testSuites = project.testSuiteList
    
    File file = new File("C:\\Users\\luciana\\Desktop\\test.txt")
    
    /**
     * Iterate through each test suite, test case and test step
     */
    testSuites.each() {
    	// Log test suite name
    	file << "-----------------------------------\n"
    	file << "Running test suite: " + it.getName() + "\n"
    	file << "-----------------------------------\n"
    	// Get a list with the contained test cases
    	testCases = it.getTestCaseList()
    	testCases.each() {
    		// Log test case name
    		file << "-----------------------------------\n"
    		file << "Running test case: " + it.getName() + "\n"
    		file << "-----------------------------------\n"
    		// Get a list with the contained test steps
    		testSteps = it.getTestStepList()
    		testSteps.each() {
    			file << it.getName() + " - " + it.getAssertionStatus() + "\n"
    		}
    	}
    }

     

    You can download the whole project from https://github.com/lucadln/soapui/tree/master/ReadyAPI/LogAssertionResultsFile

     

    Cheers! :cathappy:

6 Replies

  • Lucian's avatar
    Lucian
    Community Hero

    This can be done very simply by using the following TearDown Script:

     

    // Define variables for holding test suites, test cases and test steps
    def testSuites
    def testCases
    def testSteps
    
    // Get all the test suites from the project
    testSuites = project.testSuiteList
    
    File file = new File("C:\\Users\\luciana\\Desktop\\test.txt")
    
    /**
     * Iterate through each test suite, test case and test step
     */
    testSuites.each() {
    	// Log test suite name
    	file << "-----------------------------------\n"
    	file << "Running test suite: " + it.getName() + "\n"
    	file << "-----------------------------------\n"
    	// Get a list with the contained test cases
    	testCases = it.getTestCaseList()
    	testCases.each() {
    		// Log test case name
    		file << "-----------------------------------\n"
    		file << "Running test case: " + it.getName() + "\n"
    		file << "-----------------------------------\n"
    		// Get a list with the contained test steps
    		testSteps = it.getTestStepList()
    		testSteps.each() {
    			file << it.getName() + " - " + it.getAssertionStatus() + "\n"
    		}
    	}
    }

     

    You can download the whole project from https://github.com/lucadln/soapui/tree/master/ReadyAPI/LogAssertionResultsFile

     

    Cheers! :cathappy:

    • cnuvas_2001's avatar
      cnuvas_2001
      Established Member

      Hi

      Thanks for the code , but which tearDown script we need to keep this script

      test case or testSuite?