Forum Discussion

ijasjit's avatar
ijasjit
New Contributor
9 years ago

Need to get dynamically set project variables from command line

 

Hi Guys!!

Need you help.

 

I have a step(groovy script) in 1st test case which extracts and sets project variables.

testRunner.testCase.testSuite.project.setPropertyValue("ids", result[-7..-1]);

 

With this I can use the vaue of "ids" in the 2nd testcase by using ${#Project#ids}

All this works good and the end testcase runs sucessfully using the prject variabel when I execuet the testcases manually.

(that is via GUI, by clicking on the play button).

With GUI interface I can manually check that the project variable is updated by checking the Custom Properties tab.

 

 

The problem comes when I, execuet the 2nd testcase via command line using testrunner.sh.

So when I run the 2nd testcase using command line it, seems that it can not refer to the project variable.

Or the 1st test case was not able to update the project and set the project value.

 

Can someone guide me if I am missing a step here. Please let me know if you need more information.

4 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    The screen shot shows multiple test cases. And the groovy script is from one of the test case.

     

    Are you running only one test case from commandline? And that does not the run the groovy script where project variables are set? If so, the groovy script should get executed for each test case. 

    Consider restructring the test steps.

    • ijasjit's avatar
      ijasjit
      New Contributor

      Hi nmrao,

       
      The groovy Script - GetCoupns (part of AddCouponsToACard test-case) is setting a project variable ids. 
      The next test-case RemoveCouponsFromACard is supposed to use the project variable ids. This will be used in the test-step RemoveCouponsFromACard.
       
      Its like, I can only remove coupon number which I had added.
      This all works good when I execute the testcase via GUI by click on Play button.
      I can manually see thet the ids is always updated with a new value, each time the AddCouponsToACard test case is run.
       
       
      The issue comes when I execute  AddCouponsToACard by using the command line testrunner.sh
       
      testrunner.sh -sExternal_Web_PROD -cAddCouponsToACard  -r -a -f/opt/SOAR_Test/work/External_Web_PROD -I /opt/External_SoapUI_Project/External_Web_Prod.xml
       
      With this command line execution, the project variable 'ids'  is not being set and hence when RemoveCouponsFromACard is run the 'ids' used is not the one which was used by AddCouponsToACard 
       
      testrunner.sh -sExternal_Web_PROD -cRemoveCouponsFromACard  -r -a -f/opt/SOAR_Test/work/External_Web_PROD -I /opt/External_SoapUI_Project/External_Web_Prod.xml
       
       
      I tried adding another step, a groovy script to RemoveCouponsFromACard test-case, to log the project id it will be using. But unfortunately the ids logged was not what AddCouponsToACard had used.
       
      def test = context.expand( '$(#Project#ids}' )
      log.info = ("Coupon id picked by the RemoveCouponsFromACard Script =" + test
       
       
      -- 
      Thanks,
      JASJIT SINGH
      • nmrao's avatar
        nmrao
        Champion Level 3
        If the test case is to be run automatically, it needs to have all the steps. It can't run one step from other test case and one for another.