cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
New Contributor

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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! Cat Happy



If my answer helped please click on the 'Accept as Solution' button.

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

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

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! Cat Happy



If my answer helped please click on the 'Accept as Solution' button.

View solution in original post

Highlighted
Community Hero

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

Thanks for sharing that script, @Lucian. That looks pretty handy!




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Community Hero

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

ya betcha!



If my answer helped please click on the 'Accept as Solution' button.
Highlighted
New Contributor

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

thanks for sharing 

Highlighted
Community Hero

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

You're welcome! Smiley Happy



If my answer helped please click on the 'Accept as Solution' button.
Highlighted
Established Member

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

Hi

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

test case or testSuite?

 

 

 

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors