cancel
Showing results for 
Search instead for 
Did you mean: 

Global input file and variables

SOLVED
Highlighted
Occasional Contributor

Global input file and variables

Hi

 

I'm a new ReadyAPI user handling a migration project. Currently the 3-4 examples we've been given had a lot of repetitive data tasks in there. For example each test have the following repeated tests

1 - Data generator (a Java UUID generator), these do need to be unique per test so they can stay

2 - Date + Time input script

4 - Input data script => This is a very long file that reads in the values of an xml file on a users machine and creates test data to use for SOAP requests.

 

What's the correct way to  have some global variables defined once per project?

 

I have tried the following as a test suite setup script as an example. But it didn't seem to work as the variable in the SOAP request wasn't populated.

 

import com.eviware.soapui.support.GroovyUtils;

def dataGenerator =UUID.randomUUID().toString()
 runner.testSuite.setPropertyValue("dgen", dataGenerator)

 // Get the default value from a project property
def dgen = runner.testSuite.project.getPropertyValue("dgen")

So not sure what I'm doing wrong here?

 

As a related relevant side note, this is all going source controlled as it needs to be deployed remotely to CI machines. The setup I've been given requires a file on the host machine. Is there a way to keep that test data xml file within the project?

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Global input file and variables

Hi @jonathon 

 

yep = the value you need to specify for the GUID is ${=java.util.UUID.randomUUID()}

 

so for my payload I have a testcase level property setup on the ehctemplateid attribute in my payload as follows:

 

{
"name" : "TestCaseNumber003",
"ehctemplateid" : "${#TestCase#ehctemplateid}",
"ehcstatus" : 814250000,
"ehcversion" : "1.0",
"countersignature" : false
}

 

and I have a testcase property entitled ehctemplateid with a value of ${=java.util.UUID.randomUUID()}

 

this will dynamically generate the GUID automatically - I just ran the test and the payload in the RAW request is as follows:

 

{
"name" : "TestCaseNumber003",
"ehctemplateid" : "00b188a2-068c-494f-99d1-8faaa7be6303",
"ehcstatus" : 814250000,
"ehcversion" : "1.0",
"countersignature" : false
}

 

nice one

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: Global input file and variables

Looks the above is in setup script of test suite.

If you want to use "dgen" in soap request,
<myElement>${#TestSuite#dgen}</myElement>


Regards,
Rao.
Highlighted
Occasional Contributor

Re: Global input file and variables

Yes, it's in the test suite setup - however I open to other ideas if better.

 

Do I replace TestSuite with my test suite's name? If so how do I handles spaces in the test suite name

Highlighted
Community Hero

Re: Global input file and variables

Hi @jonathon,

If you use ${#TestSuite#property} you don't need use the testsuite's name...this syntax means 'current testsuite level'.

If you use ${TestSuite#property}, you would replace 'TestSuite' with the testsuite's name.

See the following link https://www.soapui.org/scripting-properties/property-expansion.html

Btw. It should handle spaces in testsuite name just fine....you just need to remember to not add the extra # character in there if youre specifying testsuite name rather than testsuite level

By the way, there's a dynamic scripting option to dynamically create java uuid/guids in your payload rather than using a couple of lines of groovy.
@nmrao provided me the info to do this (all cred goes to Rao) the value you need to hardcode in your payload is something like ${=java.util.UUID.randomUUID()}...i'm going to a funeral at moment but i'll check on my laptop when i get back.

Nice one,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Global input file and variables

Hi @jonathon 

 

yep = the value you need to specify for the GUID is ${=java.util.UUID.randomUUID()}

 

so for my payload I have a testcase level property setup on the ehctemplateid attribute in my payload as follows:

 

{
"name" : "TestCaseNumber003",
"ehctemplateid" : "${#TestCase#ehctemplateid}",
"ehcstatus" : 814250000,
"ehcversion" : "1.0",
"countersignature" : false
}

 

and I have a testcase property entitled ehctemplateid with a value of ${=java.util.UUID.randomUUID()}

 

this will dynamically generate the GUID automatically - I just ran the test and the payload in the RAW request is as follows:

 

{
"name" : "TestCaseNumber003",
"ehctemplateid" : "00b188a2-068c-494f-99d1-8faaa7be6303",
"ehcstatus" : 814250000,
"ehcversion" : "1.0",
"countersignature" : false
}

 

nice one

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors