cancel
Showing results for 
Search instead for 
Did you mean: 

Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

Highlighted
Super Contributor

Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

I think Ihave read some very inspiring threads and that gave a motivation to reflect on how I ave changed the testing approach where I work

So before I came:

We had throusands of tests cases and guess what, only thing or things would a very params in the requets

So I said this is bloody in efficient and not cool!

I have strong dev background in java and already used apache POI in my previous life to create excel spreadsheets.

So here is what I did:

I have all my test data which is referenced by test case ID

I am basically using groovy to read from this spreadsheet and run the templated test step.

 

Properties in excel are mapped on to test suite properties and these properities are expanded onto the requests.

So before it would take days to do TCs.

Now it takes minutes

Rest of of time is spent hitting the gym or having a coffeee lol

Not really Now they got me doing other stuff. for eg now I ma interested in service virtualization.

 

But the point is spent time up front and do things right!


Here is example of groovy code I use (added here from the reply below by a moderator)

 

// Declare content to be tested
import com.google.common.html.HtmlEscapers
import com.soapuitests.*

def tempExelParser = new ExcelParser()
String path = "U:\\git\\ens-automated-tests\\odm-content.xls"
String excelSheet = "test-24hr"
tempExelParser.readXLSFile(path,false,excelSheet)
String key = "test-PNR"
String value = "test-yyc-cashlessjun"
def tempMap = tempExelParser.getData(key,value)
log.info("starting tests: ${value} ----------------")
log.info("data map : ${tempMap}")

//def contentMap = tempMap
// initialize props with blanlk values

// now set with new values form excel

 

// set test case content
def prop = testRunner.testCase.testSuite.propertyList
log.info("value : ${prop}")
def propArr = testRunner.testCase.testSuite.getProperties()
for ( item in propArr ) {
testRunner.testCase.testSuite.setPropertyValue(item.key, "")
log.info("value : ${item.key} ${item.value}")
}
for ( item in tempMap) {
testRunner.testCase.testSuite.setPropertyValue(item.key, item.value)
log.info("value : ${item.key} ${item.value}")
}
// run test case

def project = testRunner.testCase.testSuite.project
def testsuite= testRunner.testCase.testSuite
tc = testsuite.getTestCaseByName("Templates")
def testStep = tc.testSteps['24hr Test Template']
//def testStep = testRunner.testCase.testSteps['24HRRequestTest']
def status = testRunner.status
log.info("status : ${status}")

def result= testStep.run(testRunner,context).getStatus().toString()
log.info("test case result : ${result}")
// get response
def currentTestStep = context.testCase.getTestStepAt(context.currentStepIndex)


String propertySpec = '${' + testStep.name + '#Response}'

assert result == "OK" : testStep.name + " ${value} Failed" 
log.info("ending tests: ${value} ----------------")

 

4 REPLIES
Moderator

Re: Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

Hi @sanj,

 

Thanks for sharing your approach with us! 

Is it possible for you to share the groovy you are using to better illustrate the approach?

It would be much appreciated!  Smiley Happy

 

Thanks in advance,

Olga Terentieva,
SmartBear Assistant Community Manager
Community Leader

Re: Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

Hey Sanj,

 

It is a good approach, though I prefer to use a database to do the same thing. but yeah, if you start clean, you build up a good dynamic foundation. There is just no point of building crap and building more crap on top of it. It will just fall apart one day haha. 

Super Contributor

Re: Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

I would prefer DB also but at our company its pretty hard to get DBs going which is why I am stuck using an approach such as Excel

Conceptuually they both lead to the same results

Here is example of groovy code I use

// Declare content to be tested
import com.google.common.html.HtmlEscapers
import com.soapuitests.*

def tempExelParser = new ExcelParser()
String path = "U:\\git\\ens-automated-tests\\odm-content.xls"
String excelSheet = "test-24hr"
tempExelParser.readXLSFile(path,false,excelSheet)
String key = "test-PNR"
String value = "test-yyc-cashlessjun"
def tempMap = tempExelParser.getData(key,value)
log.info("starting tests: ${value} ----------------")
log.info("data map : ${tempMap}")

//def contentMap = tempMap
// initialize props with blanlk values

// now set with new values form excel

 

// set test case content
def prop = testRunner.testCase.testSuite.propertyList
log.info("value : ${prop}")
def propArr = testRunner.testCase.testSuite.getProperties()
for ( item in propArr ) {
testRunner.testCase.testSuite.setPropertyValue(item.key, "")
log.info("value : ${item.key} ${item.value}")
}
for ( item in tempMap) {
testRunner.testCase.testSuite.setPropertyValue(item.key, item.value)
log.info("value : ${item.key} ${item.value}")
}
// run test case

def project = testRunner.testCase.testSuite.project
def testsuite= testRunner.testCase.testSuite
tc = testsuite.getTestCaseByName("Templates")
def testStep = tc.testSteps['24hr Test Template']
//def testStep = testRunner.testCase.testSteps['24HRRequestTest']
def status = testRunner.status
log.info("status : ${status}")

def result= testStep.run(testRunner,context).getStatus().toString()
log.info("test case result : ${result}")
// get response
def currentTestStep = context.testCase.getTestStepAt(context.currentStepIndex)


String propertySpec = '${' + testStep.name + '#Response}'

assert result == "OK" : testStep.name + " ${value} Failed"
log.info("ending tests: ${value} ----------------")

Moderator

Re: Testing approach Business logic - Scenarios as TCs in Excel Use Groovy to run these TCs

@sanj, thank you for sharing the code, I have added it to the original post and added the TechCorner label to the topic.

 

Thanks again for the contribution and for being part of our Community team! Smiley Happy

 

Olga Terentieva,
SmartBear Assistant Community Manager
Watch a Video Interview
Top Kudoed Authors
Are You In?

Meet the Community Leaders!

SmartBear Connect is an excellent opportunity for training, in-person support, and networking.

GET YOUR TICKET WITH $100 OFF