Ask a Question

Global Datagen

Jourdelune
New Contributor

Global Datagen

I want to use a unique ID based on a TimeStamp.

I got the idea of the GroovyScript and how to inject the TimeStamp in my SOAP Request. (it work fine)

Is there a way, to define at 1 place the Datagen - GroovyScript to get the TimeStamp and use that for different Test Suites?

It would be a blast to make that Datagen global to all project.

Jourdelune
22 REPLIES 22

Re: Global Datagen

Hi Jourdelune,


You can achieve globally available functionality implemented using Groovy. Place your Groovy script in SOAP_HOME/scripts folder and use static methods like this:

class IdGen
{
  def  getId() {
  // ... your timestamp-based id generating code
  }
}


After you restart soapUI it will load these global Groovy scripts and your new methods will be available for use like this:

newId = IdGen.getId()


I hope that fills your need.


Cheers!
/Nenad Nikolic a.k.a. Shonzilla


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
sharmameera
Contributor

Re: Global Datagen

I do not have the SOAP_HOME folder where my SoapUI is installed. Instead I have the C:\Program Files\SmartBear\SoapUI-Pro-5.1.2\bin\scripts path.

But even when I place my script there, with the groovy extension and then restart SoapUI, I am unable to use that script. I get the Unable to resolve class (and class name) error.

Re: Global Datagen

Ouch!

 

I think this is due to us moving to new forums. This topic used to be in the pro forum.

 

The feature you've been trying to use is in Pro only, that's why it's not working Smiley Sad

 

If you look at the following page in the documenation: http://www.soapui.org/scripting---properties/scripting-and-the-script-library.html, you'll see that it's Pro Only:

 

"Now let's setup SoapUI Pro to load up your Groovy library. Set File > Preferences > SoapUI Pro tab > Script Library. So I would set that to "C:\GroovyLib" in my example. Then restart SoapUI Pro to pick up the library script."

 

And just to explain nomenclature, by SOAP_HOME we mean where soapUI is installed. In your case e C:\Program Files\SmartBear\SoapUI-Pro-5.1.2\.

 

Sorry about the bad news...

 

/niclas

Product Guy for Ready! API, SoapUI and all things API
sharmameera
Contributor

Re: Global Datagen

Yes, If you read my mail carefully, I am using the Pro version only. And it's not the free one. If you see the path I sent, it says "SoapUI-Pro-5.1.2". So I am trying to use the Global Datagen through the Pro version only. When I click on the link for the page in the documentation, I get the Oops... 404 Error - Page Not Found error. And  your reply does not in any way help me solve the issue of trying to get Datagen to work globally.

rupert_anderson
Valued Contributor

Re: Global Datagen

Hi,

 

At a risk of straying into this conversation, I found the topic of Global Datagen quite interesting... so I tried out an example on my SoapUI pro of a global id generator script, which I thought I'd share in case it helps your case.

 

Here is the Groovy script, a simple thread-safe id generator (SequentialIdGenerator.groovy):

 

package test

import java.util.concurrent.atomic.AtomicLong

public class SequentialIdGenerator {

public static final long counterSeed = 1000

private static AtomicLong counter = new AtomicLong(counterSeed)

public static long nextId() {
return counter.incrementAndGet()
}
}

 

(One difference with the example in this post is that I chose to use a package of 'test', not sure if this makes a differences to using the default package)

 

I placed this in a folder called 'test' (to match the package structure) in the default scripts folder that was already created in my SoapUI Home/java/app/bin/scripts (MacOSX) e.g.

 

/Applications/SoapUI-Pro-5.1.1.app/Contents/java/app/bin/scripts/test/SequentialIdGenerator.groovy

 

Then I saw the following in the SoapUI log tab:

 

Thu May 14 16:26:46 BST 2015:INFO:/Applications/SoapUI-Pro-5.1.1.app/Contents/java/app/bin/scripts/test/SequentialIdGenerator.groovy is new or has changed, reloading...
Thu May 14 16:26:46 BST 2015:INFO:Resetting groovy class cache due to 1 modified file

 

To test it, I then created a simple Groovy TestStep:

 

log.info test.SequentialIdGenerator.nextId()

 

Run it a few times to give:

 

Thu May 14 16:24:48 BST 2015:INFO:1001
Thu May 14 16:24:49 BST 2015:INFO:1002
Thu May 14 16:24:50 BST 2015:INFO:1003
Thu May 14 16:24:50 BST 2015:INFO:1004

 

I must admit I wasn't quite sure exactly how you wanted to use the timestamp across your TestSuites, at least not in a globally available sense, but would be very interested to hear? I undertand appending a Timestamp to request data to make it unique though...

 

Maybe there's a gap for me to develop a plugin for this sort of thing...

 

Hope this helps,

Rupert

 

 

 

Author of SoapUI Cookbook
sharmameera
Contributor

Re: Global Datagen

Hi Rupert,

Thanks for the explanation :-). I was able to go up till the Groovy Test Step.

 

When I run the test step,

log.info test.SequentialIdGenerator.nextId()

 

I get the error message "groovy.lang.MissingPropertyException: No such property: test for class: Script3 error at line: 1". Please see the attached image.

 

I wonder if the error is because I am trying to use this for the REST web service?

Will research more into it and update this post. Will try to execute your steps for a SOAP service and verify the behavior.

 

Thanks,

Meera

 

 

NoSuchProperty_Error.png

sharmameera
Contributor

Re: Global Datagen

Hi Rupert,

I am also attaching the error log I got ... just in case you get some clue as to why is it behaving in this manner ...

 

Fri May 15 09:49:33 MST 2015:ERROR:groovy.lang.MissingPropertyException: No such property: test for class: Script3
   groovy.lang.MissingPropertyException: No such property: test for class: Script3
       at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
       at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
       at Script3.run(Script3.groovy:1)
       at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
       at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:79)
       at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:138)
       at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)

rupert_anderson
Valued Contributor

Re: Global Datagen

Hi Meers,

 

Great, glad it has helped, at least a bit...

 

Hmm... now if the package reference (in this case 'test') is invalid, then I too get a very similar error e.g. if in the Groovy TestStep, instead of:

 

log.info test.SequentialIdGenerator.nextId() 

 

I put:

 

log.info test1.SequentialIdGenerator.nextId()

 

Than I get the same missing property exception.

 

Can I just check that the SequentialIdGenerator groovy class file is inside a folder called 'test' within the scripts folder? Sorry if you already checked this:

 

Screen Shot 2015-05-15 at 19.23.50.pngCheers,

Rup

 

Author of SoapUI Cookbook
rupert_anderson
Valued Contributor

Re: Global Datagen

Sorry Meera,

 

I just realised that screenshot didn't show the scripts folder:

 

Screen Shot 2015-05-15 at 19.26.27.png

Cheers,

Rup

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: