Forum Discussion

anusha21's avatar
anusha21
Occasional Contributor
7 years ago

Want to mark test step as failed

HI all

 

 I want to set teststep as fail when i run it from test suite (below is my scenario)

 

I created Two test suites 

1. one is parent one 

2. Child one which has all reusable classes and this suite is in disabled state

 

In Parent one i am running two of my child Groovy script classes , my problem is if i get any error in first step my second step stops running this is because i am using "assert", so for alternative to assert i used testRunner.fail("") i n this case my both groovy test steps are running successfully but test step is not marked in red, i want this step to be marked as red 

 

Parent groovy i written below script

import com.eviware.soapui.support.XmlHolder
import groovy.util.XmlSlurper

def tcase = testRunner.testCase
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def currentStepInd = context.currentStepIndex
def previousStep = testRunner.testCase.getTestStepAt(currentStepInd - 2)
def WDTestStepName = previousStep.name

def request1 = groovyUtils.getXmlHolder("NewBusiness#Request")
def response = groovyUtils.getXmlHolder("NewBusiness#Response")


def responseHolder1 = groovyUtils.getXmlHolder(WDTestStepName+"#Response")
responseHolder1.namespaces["ns1"]= "http://www.ssp-uk.com/Mqh/WorkingData"
def WDresponse = context.expand( '${'+WDTestStepName+'#Response#//*:WorkingData}' )
//log.info "WDresponse-->"+WDresponse
tcase.getTestSuite().removeProperty("WDResponse")
testRunner.testCase.testSuite.setPropertyValue("WDResponse",WDresponse)

 

verify_check_response = testRunner.testCase.testSuite.project.testSuites["ReusableClassScript"].testCases["ReUsableClassTC"].testSteps["verify_check_response"]
verify_check_response.run(testRunner, context)
def verifyCheckResponse = context.vcRes.verify_check_response(TSuiteName)

verify_check_response_Prior = testRunner.testCase.testSuite.project.testSuites["ReusableClassScript"].testCases["ReUsableClassTC"].testSteps["verify_check_response_Prior"]
verify_check_response_Prior.run(testRunner, context)
context.vcResP.verify_check_response_Prior(TSuiteName,transactionType)

 

 

in my Child steps in 2nd test suite 

class ClassScript
{
def log
def context
def testRunner

def ClassScript(logIn, contextIn, testRunnerIn)
{
this.log = logIn
this.context = contextIn
this.testRunner = testRunnerIn
}

//Till abobe line you must keep same code except class name
public verify_check_response(String TSuiteName)
{
log.info "..............verify_check_response Script Execution..................."
def utils = new com.eviware.soapui.support.GroovyUtils( context )
def tcase = testRunner.testCase
def responseHolder1 = utils.getXmlHolder(testRunner.testCase.testSuite.project.testSuites[TSuiteName].getPropertyValue("WDResponse"))
def error = []
def verifyCheckResponse

--------------------------------------------------

--------------------------------------------------

if(error.size() > 0)
{
verifyCheckResponse = " $error "

if(error.size() == 0){ verifyCheckResponse = "Success"
log.info "Script Passed" }
return verifyCheckResponse

}

}

context.setProperty("vcRes", new ClassScript(log, context, testRunner)) 

 

 

 

IN another child test step also i written code same like above with different conditions

 

SO what i want to do in Parent groovy script is just simply

if(verifyCheckResponse != "Success" )
{
      Here i want to fail the child groovy class test step 1 from test suite 2 --> is this is possible (i tried everything by searching in google but i didnt find any solution for this) (for clear picture my folder structure find attached Image)
}

 

your answer would be really appreciated

 

thanks

Anusha

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    If the assertion is applied and assertion fails, step is failed automatically.

    What type of test step is that? Do you have any assertions associated to that particular step?
    • anusha21's avatar
      anusha21
      Occasional Contributor

      hi

       

      i am using groovy test step, but i am using class so when assertion fails then my main groovy test step is failing, but i want to mark child script too 

       

      as i explained in my above message i am using class script

       

      thanks

      Anusha

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        The only way I know to make a groovy script test step fail is to put a fail condition in it. IE, "assert 1 == 2", or even simpler: "assert false;"

         

        That would, when triggered, make the groovy script show as a failed step. Is that what you are looking for?

  • gauravkhurana's avatar
    gauravkhurana
    Occasional Contributor

     

    I have the same problem as mentioned by you

     

    YOu want the teststep to appear fail but still want the test to continue. You cannot use assert as it stops the step there. Testrunner.fail stops testcase execution

     

    So what you can do is in each step take an arraylist

     

    ArrayList err=[]

     

    add all errors to it.. err.add (" error occured ")

     

    in the last print this arraylist

     

    err.each{log.info it}

     

    so if there are any error they will be printed.

     

    for marking the teststep as red that is failed

     

    assert err.size()==0

     

    Regards

    Gaurav Khurana

    www.udzial.com


    • anusha21's avatar
      anusha21
      Occasional Contributor

      thanks for the reply i am using the same 


      gauravkhuranawrote:

       

      I have the same problem as mentioned by you

       

      YOu want the teststep to appear fail but still want the test to continue. You cannot use assert as it stops the step there. Testrunner.fail stops testcase execution

       

      So what you can do is in each step take an arraylist

       

      ArrayList err=[]

       

      add all errors to it.. err.add (" error occured ")

       

      in the last print this arraylist

       

      err.each{log.info it}

       

      so if there are any error they will be printed.

       

      for marking the teststep as red that is failed

       

      assert err.size()==0

       

      Regards

      Gaurav Khurana

      www.udzial.com