Service Virtualization

  • 1.  Expanding {{variable}}

    Posted Aug 07, 2017 02:28 PM

    If I save content that contains {{variables}} the {{variables}} aren't being expanded to show the value. If I use a step like Write to Delimited file and list the {{variables}} I do see all the values expanded.

     

    Is there some way to force the expansion of {{variables}} so I see the value and not the reference to the variable?

     

    For context, I've got inputs like below that I pass different values for {{Host}} and {{CustomerId}} that I want to see the value passed for the test. 

    https://{{Host}}/v1/customers/authorizedusers?customerid={{CustomerId}} 

     

    In my ITR log output, when I set above string is shows setting with {{variables}} which get expanded and used when I pass to my REST step. I'm looking for a way to get the values passed in the {{variables}} without write to file so I can see

    https://ServerName/v1/customers/authorizedusers?customerid=123456

    I'm sure I'm missing something simple, has anyone solved this?



  • 2.  Re: Expanding {{variable}}

    Broadcom Employee
    Posted Aug 07, 2017 03:01 PM

    The following string when added to Log Message area of a step will show you the expanded value, provided Host & CustomerId properties have appropriate values available before that step is executed.

     

    https://{{Host}}/v1/customers/authorizedusers?customerid={{CustomerId}}

     

    I hope this satisfies your need.



  • 3.  Re: Expanding {{variable}}

    Posted Aug 07, 2017 03:13 PM

    Thanks for the reply Prem. Built-in functionality like Log Message and Write to Delimited file are correctly expanding the {{variables}}, but I want to save variables to another source and the {{variables}} aren't being expanded automatically. I would prefer not to output a file, load the file and then save it to a DB and instead just save the data to DB directly (or, lookup each {{var}} and replace the value) e.g. if I have testExec.setStateValue("endpoint", "https://{{Host}}/v1/customers/authorizedusers?customerid={{CustomerId}}"); and {{Host}} and {{CustomerId}} variables have values I want to see a string that has https://ServerName/v1/customers/authorizedusers?customerid=123456 



  • 4.  Re: Expanding {{variable}}
    Best Answer

    Broadcom Employee
    Posted Aug 07, 2017 03:23 PM

    Depending on where you set testExec.setStateValue - I can think of two options:

     

    1) Use testExec.setStateValue("endpoint", "https://"+testExec.getStateString("Host","")+"/v1/customers/authorizedusers?customerid="+testExec.getStateString("CustomerId",""));

     

    Or 

    use testExec.setStateValue("endpoint",testExec.parseInState("https://{{Host}}/v1/customers/authorizedusers?customerid={{CustomerId}}"));

     

    Both these assume that Host & CustomerId have appropriate values available.

     

    Does this help?



  • 5.  Re: Expanding {{variable}}

    Posted Aug 07, 2017 03:28 PM

    testExec.parseInState() looks like exactly what I was looking for - thanks! I'll give that a try.



  • 6.  Re: Expanding {{variable}}

    Posted Aug 07, 2017 03:35 PM

    Thanks Prem, confirmed below is getting the values and they end up in db results now.

     

    results.put("Endpoint", testExec.parseInState(testExec.getStateValue("FullEndpoint")));
    results.put("Request", testExec.parseInState(testExec.getStateValue("Request")));