Forum Discussion

RohitBBorse's avatar
RohitBBorse
Contributor
15 years ago

Saving script assertion result to a path as specified.

Hi,
I have a script assertion applied to each test request.

I wanted to save the result of this script assertion to a root folder path as specified in Launch TestRunner -> Reports -> Root Folder

If I launched test runner at project level, script assertion result should be saved in a path as specified in root folder of Project ->.Launch TestRunner -> Reports -> Root Folder.
Similarly, this should happen for test suite and test case if launched test runner for that particular level.

How I can achieve this with groovy.

Below is a groovy script in script assertion.


import org.apache.commons.codec.binary.Base64

teststep=context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()
Severity=context.expand('$'+"{"+teststep+"#Response#//*:Notifications/*:Severity}")

b64 = new Base64()

if (Severity == "SUCCESS"||"WARNING"||"NOTE")
{
LBL=context.expand('$'+"{"+teststep+"#Response#//*:Label/*:Parts/*:Image}")
LblImgType = context.expand('$'+"{"+teststep+"#Request#//*:LabelSpecification/*:ImageType}")
LblDcdBytes = b64.decode(LBL.getBytes())

FileOutputStream LabelImage = new FileOutputStream(new File(""+context.expand('${#TestSuite#LabelPath}')+""+teststep+"."+LblImgType+""));

LabelImage.write(LblDcdBytes);
LabelImage.flush();
}



Thanks
Rohit Borse

4 Replies

  • Hi,

    Please also suggest, if there is any other way for applying script assertion at global level instead of applying it for each test request.
    This global script assertion should be executed for each test request in the workspace or project or ....

    How I can make this possible with the help of groovy script.

    Thanks
    Rohit Borse
  • Hi Rohit,

    If i understood your question correctly... you want use skip the script assertion for each test step and store the result

    #1 :we can use TearDown/Report script available at testSuite /TestCase level.

    #2 : store the result into a location by using a property value & update it's value using a parameter input from enduser using groovy. in such a case, groovy will store all the result and we will be not dependent on testrunner's report/results.

    Best Regards,
    ~~Pradeep Bishnoi~~
    http://pradeepbishnoi.blogspot.com
    http://learnsoapui.wordpress.com
  • Thanks Pradeep,

    Yes, we can use TearDown script. But it will be executed in last after test suite/test case execution is finished.
    I want, the script assertion result immediately saved into local repository once the test step execution is finished.

    I have used property value as shown in code


    FileOutputStream LabelImage = new FileOutputStream(new File(""+context.expand([b]'${#TestSuite#LabelPath}'[/b])+""+teststep+"."+LblImgType+""));


    But, instead here I want to fetch the path as specified in the Report section of the Launch TestRuner of test case/test suite/test project.


    Thanks
    Rohit Borse
  • Hi Rohit,

    Yes, it will be. So as a workaround to this situation, we can use loop to navigate/run through all the teststeps.
    During this looping we can also update the value of the parameter to store the response data.

    P.S.: Here we will store the response using groovy, so the export Report feature of testrunner would not be required. Refer my blog at http://pradeepbishnoi.blogspot.com for getting the required scripts :-)

    Thanks!
    ~~Pradeep Bishnoi~~