Forum Discussion

skillsoft's avatar
skillsoft
Frequent Contributor
16 years ago

runTestStepByName not updating excel if Datasink disabled

Hi,

If the datasink step is disabled, the properties that you set are being set, but the datasink is not running if using runTestStepByname. By running I mean, the excel spreadsheet is not updated. It is updated if I then run the datasink manually. It looks like other's have had the same issue (see link below).

viewtopic.php?f=5&t=4362&p=14647&hilit=datasink+groovy#p14647

I am running the datasink inside a datasource loop. If a value in a certain field of the datasource is blank, I run a testcase through groovy which generates a subid and inserts that subid into the datasink property. Then it should run the datasink. As other's have had the same issue following your instructions to disable the datasink step, it looks like it's probably a bug. If that's the case, when will this be addressed? If not, what am I doing wrong? I'm running 3.6 (released version). Code is below:

if(testRunner.testCase.testSteps["companies"].getPropertyValue("BooksSubscriptionID")=="")
{
testRunner.testCase.testSuite.getTestCaseByName("Generate SubID").setPropertyValue("BooksGroupCode",testRunner.testCase.testSteps["companies"].getPropertyValue("BooksGroupCode"))
testRunner.testCase.testSuite.getTestCaseByName("Generate SubID").run(properties, false )
def strBooksSubID=testRunner.testCase.testSuite.getTestCaseByName("Generate SubID").getPropertyValue("BooksSubscriptionID")
def holder = groovyUtils.getXmlHolder("editBooks24x7 RequestSub#Request" );
holder.setNodeValue( "//subscriptionId/value", strBooksSubID);
holder.updateProperty(true);
def holder2 = groovyUtils.getXmlHolder("importBooksSubscription Request#Request" );
holder2.setNodeValue( "//booksSubscriptionID", strBooksSubID);
holder2.updateProperty(true);
testRunner.testCase.testSteps["update sub id in spreadsheet"].setPropertyValue("BooksSubscriptionID",strBooksSubID)
testRunner.runTestStepByName("update sub id in spreadsheet")
}
else
{
def holder = groovyUtils.getXmlHolder("editBooks24x7 RequestSub#Request" );
holder.setNodeValue( "//subscriptionId/value", '${companies#BooksSubscriptionID}');
holder.updateProperty(true);
def holder2 = groovyUtils.getXmlHolder("importBooksSubscription Request#Request" );
holder2.setNodeValue( "//booksSubscriptionID", '${companies#BooksSubscriptionID}');
holder2.updateProperty(true);

}


Thanks,

Mary

6 Replies

  • Hello,

    The Excel DataSink needs to do some initializing and termination before and after being run for the data to be saved correctly. When the TestStep is disabled, these methods are not automatically called, and must be invoked manually. Instead of using testRunner.runTestStepByName, try this:


    def testStep = testRunner.testCase.testSteps["update sub id in spreadsheet"]

    testStep.prepare( testRunner, context )
    testStep.run( testRunner, context )
    testStep.finish( testRunner, context )


    Regards,
    Dain
    eviware.com
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi,

    Thanks, that works a lot better. However, it is always updating the first row in the spreadsheet. I'm running the step within a datasource loop. So if I ran the testcase 5 times, because there were 5 rows in the spreadsheet, how would I make it update the correct row and not just update the first row?

    Thanks,

    Mary
  • Hello,

    In that case you would have to run the prepare line once, before the loop, and the finish line once, after the loop. Let us know if this helps!

    Regards,
    Dain
    eviware.com
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    It worked great! The correct rows were updated with the books sub id once I moved prepare to before the loop and finish to after the loop and just run each once. Thanks so much for your help!!

    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi,

    I spoke too soon. If I have 80 rows in a spreadsheet and the subscription id in rows 3,79 and 80 are blank and my code is looking to update the spreadsheet on those 3 using:
    if(testRunner.testCase.testSteps["companies"].getPropertyValue("BooksSubscriptionID")=="")
    {
    .
    .
    .
    testStep.run( testRunner, context )
    }

    What happens when the testcase is done running is rows 1,2 and 3 are overwritten instead of updating 3,79,80. I essentially have to run "run" for each row, in which case I may as well have the datasink enabled and just change the value of the subscription id in the datasink. Any other ideas or is that the way it's going to work?

    Thanks,

    Mary
  • Hello,

    Unfortunately I don't think you would be able to use the DataSink as you are describing it, without running it for each line. You could probably do thus by using a Groovy script and a third party Excel library, but there is no built-in support in soapUI for this kind of random access writing to an Excel file, sorry!

    Regards,
    Dain
    eviware.com