I'm automating a SoapUI project with Groovy that generate and excel report at the end with the results of my requests.
My problem is that I want to get the desktop path in which the file will be saved.
Something similar to this java code, but in Groovy :
String userHomeFolder = System.getProperty("user.home") + "/Desktop";
Thanks in advance !
To get your desktop path in Groovy you can use your Java code directly, since it works perfectly:
String userHomeFolder = System.getProperty("user.home") + "/Desktop";
If you want an alternative a Groovy way to do so could be:
String userHomeFolder = System.properties['user.home'] + "/Desktop"
Or:
String userHomeFolder = System.properties.'user.home' + "/Desktop"
All of this gets the same result.
Groovier way:
String userHomeFolder = "${System.properties.'user.home'}/Desktop"
you might also want to use a propper File.separator, but even with a mix of / and \ is should work fine
Related
I'm trying to add custom property on the ppt file. But Received value("güsiöçÇÖISÜG") is not equal sent value("ğüşiöçÇÖİŞÜĞ").
I faced a strange situation like that:
Open the sample.ppt by LibreOffice.
Save (CTRL+S) and Close, any change is not necessarily.
Run the code again.
And two values are equal
Sample ppt files is here: https://drive.google.com/drive/folders/1qTlREuLAAM-I0JIn-htPwLEUwRjQ9IiJ?usp=sharing
Is there anyone to help me, thanks.
You need to check encodings of your Excel files. Most probably a software (DSO) generates a UTF-8 based document instead of UTF-16. For example, you may try using the following code:
Dim strEncodingName As String = String.Empty
Dim myStreamRdr As System.IO.StreamReader = New System.IO.StreamReader(myFileName, True)
Dim myString As String = myStreamRdr.ReadToEnd()
strEncodingName = mmFileIA.CurrentEncoding.EncodingName
I would like to create custom variable for theos. In example ##DATECREATED## to print current date for my tweak deceptions (I'm soooo bored to edit it manually :D)
Like ##FULLPROJECTNAME## prints out tweak name in control and Makefile...
Edit: I did it with adding this to my nic.pl:
use DateTime;
$NIC->variable("DATECREATED") = DateTime->now->strftime('%d/%m/%Y');
Is it possible to do it without editing original nic.pl?
Thanks for suggestions!
I have found a solution for it!
I had to put this code inside control.pl in my theos template:
use DateTime;
NIC->variable("DATECREATED") = DateTime->now->strftime('%d/%m/%Y');
Trying to setup a livetemplate for Flutter which is this:
S.of(context).$END$$lowerCaseName$ $lowerCaseName$":$SELECTION$
Where lowerCaseName is camelCase(String). But when I run it, I get an extra " right after $END$
For example, if I select "test string" in my code and surround with the live template, instead of getting this:
String test = S.of(context).TestString TestString":"test string";
I get this:
String test = S.of(context)."TestString "TestString":"test string";
Any ideas?
the problem is that $SELECTION$ value is the whole string you select, including quotes. So you have to strip them somehow. I'd suggest using groovyScript() - see https://www.jetbrains.com/help/idea/edit-template-variables-dialog.html, http://bartololeo.blogspot.com/2014/01/idea-12-how-to-write-live-template-with.html. For example, the following function specified as expression for $lowerCaseName$ should do the thing:
camelCase(groovyScript("_1.replace('\"', '')", SELECTION))
I'm pretty new to testing and SoapUI and I've just faced a problem:
I have 2 soap requests from which I transfer data (using PropertyTransfer) to Properties - I can do that and it works fine for me.
But now I would like to take those values in my groovy script (which is next step of my testcase). How to do that? So far, I have found following:
testRunner.testCase.getPropertyValue("SomeProp")
But it doesn't work for me. I guess it's not that Properties. Any tips?
In the Groovy script panel you can right-click and select Get Data, to help you out. You will end up with something like this:
context.expand( '${Properties step#SomeProp}' )
Same thing can also be written as:
testRunner.testCase.testSteps['Properties step'].getPropertyValue("SomeProp")
Few cents:
if we are loading properties file through external file via -Dsoapui.properties=\tmp.properties
Contents of tmp.properties
serialNumber=908664374
ideal way to load the property 'serialNumber' in groovy file would be,
def serialnumber = context.expand('${#serialNumber}')
But if you have a property at any level [test suites, test cases or project] inside your SOAPUI project, say you have it at project level, then it would be
def serialnumber1 = context.expand('${#Project#serialNumber}')
The first expression works with:
context.expand( '${Properties_step#SomeProp}' )
To read property from Project level properties
testRunner.testCase.testSuite.project.getPropertyValue( "PropertyName")
To read property from Test Case level properties
testRunner.testCase.getPropertyValue("PropertyName")
Two answers are possible for this type of scenarios ,
Setting and Getting the Property values,
Message Exchange
Test Runner
Message Exchange :
def testCase=messageExchange.modelItem.testCase.getPropertyValue("Propertyname")
Test Runner:
testRunner.testCase.getPropertyValue("PropertyName")
Note : context also helps to retrieve the same .
I'm new to groovy scripting in SoapUI and a bit confused regarding the amount of information available, so I may just have overlooked the answer to this.
There is a method context.getCurrentStep() available in scripts which loaded the GroovyUtils. But in a script step this, of course, returns the name of the script step itself.
Now I want to access the name (more precisely the response) of the previous step without using it's name explicitly. Is there an easy method to acchieve this?
You could do something like:
def currentStepInd = context.currentStepIndex
def previousStep = testRunner.testCase.getTestStepAt(currentStepInd - 1)
log.info previousStep.name
More information is available in the API JavaDocs.
You would want to do the following in your script:
def response = context.expand( '${previous_step_name#Response#}' )