Forum Discussion

cbyndr's avatar
cbyndr
Contributor
15 years ago

[SOLVED]does script assertion have access to testrunner?

In order to programmatically iterate and verify response xml child nodes, many of our test cases' assertions are handled via groovy scripts.

In order for test coverage to include assertions covered by these groovy scripts, I'm attempting to move these groovy scripts into test requests' script assertions.

The process for tackling this is described in this thread.

My original script assertions get their expected values from properties steps, which requires access to test runner. But, script assertion does not appear to have access to test runner.

Is there some way that we can access property step properties for the script assertions? Or should we plan to move the expected values out of the properties steps and into (say) a CSV file?

6 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    There is no way to access the TestRunner from the script assertion at the moment.

    You might be able to get to the properties steps through the TestCase, if that is what you need

    def testCase = messageExchange.modelItem.testStep.testCase

    Failing that, moving the expected values into a CSV file would be a good solution

    /Nenad
    http://eviware.com
  • wjblazek's avatar
    wjblazek
    Occasional Contributor

    Script assertions can access property step properties through the messageExchange object:

    def var = messageExchange.modelItem.testStep.testCase.getTestStepByName("propertyStepName").getPropertyValue("propertyName")
    messageExchange.modelItem.testStep.testCase.getTestStepByName("propertyStepName").setPropertyValue("propertyName", propNameNewValued)

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      The script is not relevant in this case.
  • Thanks Nenad, TestCase looks like it will get me into the properties step.
  • hello, is there any way how to acess testRunner now with 4.5.2?
    I need to run following code from script assertions

    def assertWas = context.expand( '${get connected meter#Response#declare namespace ns5=\'http://tieto.com/WMS/acknowledgement\'; declare namespace ack=\'http://tieto.com/WMS/GetDeliverySite\'; //ack:GetDeliverySiteResponse[1]/ack:Acknowledgement[1]/ns5:Status[1]}' )
    def assertExp = "OK"
    def assertWhat = "Response Code"
    def caseName = testRunner.testCase.name
    def errandId = context.expand( '${#TestCase#newConnectionErrandId-sub}' )

    def tc = testRunner.testCase.testSuite.project.testSuites["common"].testCases["smartAssert"]
    tc.setPropertyValue("assertWas",assertWas)
    tc.setPropertyValue("assertWhat",assertWhat)
    tc.setPropertyValue("assertExp",assertExp)
    tc.setPropertyValue("caseName",caseName)
    tc.setPropertyValue("errandId",errandId)

    def runner = tc.run( null, false )
    log.info "Status: $runner.status, time taken for TestCase was: $runner.timeTaken ms"


    or is there any workaround?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Is it the last line you need help with?

    In that case, couldn't you just write the following?

    log.info "Status: " + runner.status + ", time taken for TestCase was: " + runner.timeTaken + " ms"

    Regards,
    Manne Fagerlind
    SmartBear Sweden