Forum Discussion

stenofski's avatar
stenofski
Occasional Contributor
10 years ago

Calculate within the request before sending - Property Expansion, Dynamic Properties, Request

Hey,

 

i would like to calculate a value within the request based on another property. The current issue i have is that he calculates the value but the soap request isnt correct or he dont calculate and the value is correct.

 

Counter=01,02,03-20 <---always needs an leading 0, till 10 is reached. But with an leading 0 the code dosent work.

 

${=def bla=${#TestSuite#Counter};bla.plus(1); }

What i want to archive, if "count" is less than 10, add an leading 0, if its bigger than 9, do nothing. But at both situations i need to increase it by 1.

 

Best Regards

Sten Flade

  • Hi Sten,

     

    Have you seen the Groovy 'padLeft' command? Maybe this can do what you need?

     

    Consider the example:

     

    for ( i in 0..10 ) {
        log.info i.toString().padLeft(2,'0')
    }

     

    This prints:

     

    • Thu Sep 17 17:55:15 BST 2015:INFO:00
    • Thu Sep 17 17:55:15 BST 2015:INFO:01
    • Thu Sep 17 17:55:15 BST 2015:INFO:02
    • Thu Sep 17 17:55:15 BST 2015:INFO:03
    • Thu Sep 17 17:55:15 BST 2015:INFO:04
    • Thu Sep 17 17:55:15 BST 2015:INFO:05
    • Thu Sep 17 17:55:15 BST 2015:INFO:06
    • Thu Sep 17 17:55:15 BST 2015:INFO:07
    • Thu Sep 17 17:55:15 BST 2015:INFO:08
    • Thu Sep 17 17:55:15 BST 2015:INFO:09
    • Thu Sep 17 17:55:15 BST 2015:INFO:10

    So, basically you could get your counter value (as a String) and use padLeft(2, '0') to append a 0 when the counter is <10, is this the sort of thing you want?

     

    Cheers,

    Rupert

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi Sten,

     

    Have you seen the Groovy 'padLeft' command? Maybe this can do what you need?

     

    Consider the example:

     

    for ( i in 0..10 ) {
        log.info i.toString().padLeft(2,'0')
    }

     

    This prints:

     

    • Thu Sep 17 17:55:15 BST 2015:INFO:00
    • Thu Sep 17 17:55:15 BST 2015:INFO:01
    • Thu Sep 17 17:55:15 BST 2015:INFO:02
    • Thu Sep 17 17:55:15 BST 2015:INFO:03
    • Thu Sep 17 17:55:15 BST 2015:INFO:04
    • Thu Sep 17 17:55:15 BST 2015:INFO:05
    • Thu Sep 17 17:55:15 BST 2015:INFO:06
    • Thu Sep 17 17:55:15 BST 2015:INFO:07
    • Thu Sep 17 17:55:15 BST 2015:INFO:08
    • Thu Sep 17 17:55:15 BST 2015:INFO:09
    • Thu Sep 17 17:55:15 BST 2015:INFO:10

    So, basically you could get your counter value (as a String) and use padLeft(2, '0') to append a 0 when the counter is <10, is this the sort of thing you want?

     

    Cheers,

    Rupert

      • stenofski's avatar
        stenofski
        Occasional Contributor

        Sorry! I diddn't understand your respons properly at first.

        I tried it with your suggestion and it works like charm!

         

        THANK YOU SO MUCH! :heart:

         

        The solution who ever is also looking for something simliar. :smileywink:

        {=def bla=${#TestSuite#Counter};bla.plus(1).toString().padLeft(2,'0');}

        It gets an testsuite propert, increases it by 1 and occurs as 02.

         

        Best Regards

        Sten