Forum Discussion

chimas's avatar
chimas
Occasional Contributor
10 years ago

ReadyAPI 1.4.1 Inline Command is always executed

Hi

 

In Soapui I used to use this approach to create random user names. But it is not working as expected inside READY API.

 

Inside a SOAP request I have something like this:

 

<userName>User_${=(int)(Math.random()*1000)+9999}</userName>

 

That will generate one random name every time this request is called.

 

Example:

 

<userName>User_5555</userName>

 

This is fine but when I'm trying to read this generated name from another Step on the same test case one new number will be generated.

I'm using this command to read this user name from the RawRequest:

${setNewUser#RawRequest#//userName}

 

And that random command will be executed again, generating a new user name every time I try to read the username generated on that other Test Step.

Unfortunately it was working on SOAPUI 5.2.0 but it is not working on READY API

 

WorkAround:

I don’t want to change all projects I have but I know it’s possible to use this workaround to avoid this Issue. Write an Groovy script to generate this random name and storing it on a TestCase custom property.

  • TanyaYatskovska's avatar
    TanyaYatskovska
    10 years ago

    Hi Chimas,

     

    Our R&D team has found out that SoapUI and Ready! API work in the same way – a new value is generated each time they got access to userName.

    If the behavior is different in your case, could you please provide us with a sample project that demonstrates the differences between the products results?

  • TanyaYatskovska's avatar
    TanyaYatskovska
    9 years ago

    Jparel, I was informed that this behavior is related to the Groovy library update (2.1.7 for 5.1.2 and 2.4.4 for 1.5.0). Our team suggests that you update your groovy code to this:

    (int)(Math.random()*99999) + 10001

    Brackets must be around the code:

    Math.random()*99999

    Since Math.random() returns the pseudo random value from 0 till 1, when it casts to int it becomes 0! Therefore, you get 10001 every time.

     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Chimas,

     

    I’ve passed this information to our QA team. Let’s wait for the news from them.

    • TanyaYatskovska's avatar
      TanyaYatskovska
      SmartBear Alumni (Retired)

      Hi Chimas,

       

      Our R&D team has found out that SoapUI and Ready! API work in the same way – a new value is generated each time they got access to userName.

      If the behavior is different in your case, could you please provide us with a sample project that demonstrates the differences between the products results?

      • JParel's avatar
        JParel
        Occasional Contributor

        Hi Tanya,

         

        There is an issue with the behaviour from SoapUI Pro 5.1.2 to SoapUI NG Pro using Ready API 1.5.0 with regard to the math.random() function.  I have a composite project and have a property in the Test case level with the Value of ${=(int)Math.random()*99999+100001}

         

        Test Case Customer Properties.jpg

         

        On SoapUI Pro 5.1.2, this is working as expected with every call creating a new value. On Ready API 1.5.0 the random function does not work at all. All the API call are set to 100001 rather than getting a random variable. Can your team please have another look at this issue please.