Forum Discussion

mpw83's avatar
mpw83
Contributor
6 years ago

Run a test case only if specified test case is passed

I have a test case called 'Fund loans'. In this Test case, I have a step called "Funded by Investor".  What this is doing, funding the loan by the investor. To fund the loan, the investor should have enough credits.  Each time when I run the test case it's funding the loan and the same time the available funds get reduced. To avoid this situation I have created another test case call 'Add Funds to Investor" to increase the investor funds.  

I want to execute this 'Add Funds to Investor" test case as a step under 'Fund loans' test case only if  'Fund by Investor' test step is passed. I don't see any 'TearDown Script' option for steps. 

 

Test Suite: Fund loan 100% 
Test Case: 'Fund loans' 

Test Steps: 'Funded by Investor'  

Test Steps: 'Add Funds to Investor' run if 'Funded by Investor' is passed

 

I tried to add a TearDown Script on test case ''Fund loans' as follows 

for( r in testRunner.results ) {
log.info "TestStep [" + r.testStep.name + "] finished with status " + r.status
if ( r.testStep.name == "Funded by Investor") {
	if (r.status == 'PASS' ) {
            log.info("Funds added..........")
testRunner.runTestStepByName('Add Funds to Investor'); } else { log.info("Add Funds To Investor will not run because Fund the loan is failed") } } }

I can see following in the logs

Thu Apr 11 16:27:33 NZST 2019: INFO: TestStep [Funded by Investor] finished with status PASS
Thu Apr 11 16:27:33 NZST 2019: INFO: Add Funds To Investor will not run because Fund the loan is failed

It does not print the "Funds added.........." even the step is PASS. 
What is the best way to do this? Can we directly do this instead of using a TearDown Script?.  If I have to use TearDown Script then what is wrong with my script and why the condition "if (r.status == 'PASS' )" is not getting successful? 

Help much appreciated, Thanks  

 

  • On your second if statement try adding .toString() after status. After I did that, funds added printed in my log

    if (r.status.toString() == 'PASS' ) {

    Also I think you need to use double quotes when you try to run the test step by name. That did not work for me until I changed it.

     

    testRunner.runTestStepByName("Add Funds to Investor");
  • On your second if statement try adding .toString() after status. After I did that, funds added printed in my log

    if (r.status.toString() == 'PASS' ) {

    Also I think you need to use double quotes when you try to run the test step by name. That did not work for me until I changed it.

     

    testRunner.runTestStepByName("Add Funds to Investor");
    • mpw83's avatar
      mpw83
      Contributor

      jsheph01 Thanks for the reply, I tried what you suggested. Seems like now IF condition is working.  It's only identified the results of the last 5 steps and not looping through all the steps. Please see attached screenshot. If step 'Fund by Investor' is failed then it's identifying its failed. 

      Do you have any idea? Or is there any better way to do this? Thanks 

  • I am not sure how you have your test setup but if the funded by investor is in a loop the Fund loans will run each time that step is passed. In that case you might want to create a groovy script step after Funded by Investor and put your script in there.