SOAPUI - SOAPRequest - Expand properties to access name property of current TestStep - properties

SoapUI provides a common syntax to dynamically insert properties in SOAP Request. In their documentation they explain how to access different properties depends on property scope:
#Project# - references a Project property
#TestSuite# - references a TestSuite property in the containing TestSuite
#TestCase# - references a TestCase property in the containing TestCase
#MockService# - references a MockService property in the containing MockService
#Global# - references a global property (optional)
#System# - references a system property
#Env# - references a environment variable
[TestStep name]# - references a TestStep property within the current TestCase
My problem is I want to access the name of the current testStep however documentation says that to access TestStep properties you need the name... There is another way to do so? like for example #TestCase#TestStep#Name. I know how to achieve this with groovy script but in my case I want to put the property directly on SOAP Request.
Thanks in advance

Finally I found the solution in the documentation, with '=' prefix it's possible to specify a groovy script and access to some context variables. In this context request variable is available and also its name property, so It's possible access to the current TestStep name with:
${=request.name}

Example below is grabbing the request from your TestCase and assigning a value to a specific element.
// get XMLHolder for request message def
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
// grabbing the specified request
def holder = groovyUtils.getXmlHolder("Specified#Request")
holder["//*:Password"] = 'password1';
For the example above you need to know the Xpath for your element.
Note, that this can be accomplished in several ways, but you specified doing in through groovy script. It can also be done through a #TestCase# property. Example:
<soapenv:Body>
<tns:AuthenticateUser>
<tns:Credentials>
<tns:IntegrationID>${IntegrationID}</tns:IntegrationID>
<tns:Username>${Username}</tns:Username>
<tns:Password>${Password}</tns:Password>
</tns:Credentials>
</tns:AuthenticateUser>

Related

Unable to add custom user property even if it does not exist

I have implemented VSTO plug-in for Outlook 2016 / 2019. I have added one custom property. On production, for one user (this user has tried on different machines as well), whenever we try to add our custom property we get exception.
I am using following code snippet :--
UserProperty securedFlag = mailItem.UserProperties.Find("Custom.Secured", true);
int currentValue = -1;
if (securedFlag == null)
{
try
{
securedFlag = mailItem.UserProperties.Add("Custom.Secured", OlUserPropertyType.olInteger, false, OlFormatInteger.olFormatIntegerPlain);
}
catch(System.Exception ex)
{
DarkAddInEventLog.WriteException(ex, "Secure");
}
}
When we execute above code, it is throwing following exception :--
"A custom field with this name but a different data type already exists. Enter a different name."
I have also tried to search same property in non-custom properties by passing false (in second argument of find API) which also throws exception that this property does not exist. Therefore it seems confirmed that this property does not exist before.
Now I have 2 doubts :--
1- If this property does not exist, then why outlook is throwing this error ?
2- Same plug-in is working with other users but only one user is facing this issue. Is it related to some mailbox configuration ?
The error means a property with the same name has already been used in the same mailbox, it might not even be your property, but since all custom properties use the same GUID (PS_PUBLIC_STRINGS), you can run into this problem with duplicate names.
Your only option is to either use a different name (and make sure it is not generic enough to conflict with other properties created by some other apps - e.g. you can prefix all your properties with a unique prefix, such as "MyCompanyProp.") or avoid using UserProperties collection completely and set your custom properties using PropertyAccessor specifying the full DASL name of the named properties with your own custom GUID.

Is there any API in JUnit 5 to test for included or excluded Tags?

I'd like to enable a test if a certain tag is "included", i.e. passed with option --include-tag of the ConsoleLauncher or useJUnitPlatform.includeTags property in Gradle. Is there any API to retrieve the value of this option in the context of test class or method?
I tried the script-based condition #EnabledIf like this:
#EnabledIf("'true' == systemProperty.get('itest.backendSystemPresent') || junitTags.contains('BackendSystemIT') == true")
But junitTags contains the #Tag annotations of the element in question, not the tags included at runtime.
Reading your question again, my answer is "No". You can't use junitTags to achieve your goals. And no, there's no such API at the moment. You would need something like:
#EnabledIf("'true' == evaluateTagExpression('BackendSystemIT') || ...)
Because you need to take care of tag expression here as well: https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions
But, tags are evaluated earlier in the process. Your condition will not get a chance to be executed when the test was already excluded by tag evaluation. So, I guess, you'll have to stick with the single system property switch to control the enabled state of the test method.
Btw. we are improving the tag expression language with any() and none() tokens, soon. https://github.com/junit-team/junit5/issues/1679
Possible solution:
Annotate your test with #Tag("BackendSystemIT")
Before running your tests, check for itest.backendSystemPresent system property and if it is set, pass a --include-tag "BackendSystemIT" to the test run.
Let Jupiter do the job of evaluating tag expressions
Is there any API to retrieve the value (of this option) of all tags that are attached directly or inherited in the context of test class or method?
Yes. Declare and use a org.junit.jupiter.api.TestInfo parameter in your test method.
#Test
#DisplayName("TEST 1")
#Tag("my-tag")
void test1(TestInfo testInfo) {
assertEquals("TEST 1", testInfo.getDisplayName());
assertTrue(testInfo.getTags().contains("my-tag"));
}
For details see https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection
But junitTags contains the #Tag annotations of the element in question, not the tags included at runtime.
This is the expected behaviour -- the platform (here: console launcher) already applied the filter passed via --include-tag and other configuration parameters. In short: there's no need to manually check for tags in standard Jupiter tests. If there's problem with the built-in filtering, please create an issue here: https://github.com/junit-team/junit5/issues/new/choose

Determine if i18n is enabled for a JCR Property

How to access the corresponding FieldDefinition, if I have only the jcr property name at hand.
Is there any desired functionality,like find a field definition by a jcr property name ? If not, how would I access configured field definitions in java code ?
Scenario : I need to determine, if a given jcr property name was configured to be an i18n-capable field in definition ?
The answer is you can never be sure if property was configured to be i18n-able (or have any other trait) at the time it was last edited as definition might have changes since.
However to achieve what you want (obtain the definition), what you need to do is:
get a parent node of the property in question,
get value of it's mgnl:template property. That's your templateId,
use the templateId to obtain template from the registry,
read value of dialog property of the template, that's your dialogId
use the dialogId to obtain dialog from the registry
scan tabs in the dialog to find property definition with name of the jcr property you have started with

SoapUI Free - Groovy Script in Property Value to Get TestSuite Property

I am using the free (non-PRO) SoapUI 5.0 and I have a list of properties in a Test Suite.
I then have a number of Test Steps, each one having the same name as a Test Suite property.
I'm trying to write Groovy script in a Test Step property to retrieve the value of the Test Suite property with the same name.
For example:
Test Suite has a property colour_red with the value 12345.
Within the Test Suite is a Test Case, with a Test Step also called colour_red.
Within the colour_red Test Step is a property "info".
I'm trying to get the property value for "info" to be the Test Suite
property colour_red value of 12345.
What I have so far in the "info" property value:
${=new GroovyShell().evaluate(testRunner.testCase.testSuite.project.getPropertyValue(context.getCurrentStep().getLabel()))}
I'm not sure if I need the new GroovyShell().evaluate bit, but without that it still doesn't work. I cannot tell exactly what is being picked up but it is not the value of the Test Suite property with the same name.
From what I can see the script should retrieve the current Test Step name (colour_red) and then look for a property called that in the Test Suite.
My reason for doing this is that I have data in the Test Suite property values which needs to be shared between numerous Test Cases (all with many Test Steps).
Without the PRO version I am struggling but I think with Groovy there should be a way to do this.
Any help appreciated, thanks.
I think researching property expansion will help you.
http://www.soapui.org/Scripting-Properties/property-expansion.html
To get you going...
You can easily reference property values using these dynamic references:
Put a reference like ${#TestSuite#colour_red} as the property value of "info".
Now the info property value is dynamicaly set to whatever the TestSuite's colour_red property value is.
I think this does what you want:
def myStep = context.currentStep.name
def myValue = context.expand( '${#Project#' + myStep + '}' )
testRunner.testCase.setPropertyValue("info", myValue)
I made it a little more verbose than it needs to be. I do not think that -Pro will help you, unless I misunderstood what you need.

How to use Global Property name in my JSON input request using SoapUI?

I have a SoapUI project which contains around 60 plus services. Each service requires some input which will be changed for every execution. So I have created certain Global Properties and assign some values to that properties.
I have to use these properties values in my SoapUI request ( i.e. JSON Format request ).
If it is groovy script means, I will use like this.
String HTiC_Username = com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties['HTiC_Username'].value;
But, how to get the value of the Global Property in the request?
Hope you understand my question. Please provide proper guidance.
Thanks
To dynamically "expand" (i.e. substitute) the value of a property into a test step, the following syntax is used: ${#scope#propertyName}
...where 'scope' refers to the level at which the property has been defined (e.g. Global, Project, TestSuite, TestCase).
So to expand a property named username defined as a Global property, for example, the following code can be used directly within a Request Test Step (e.g within a JSON body, or header value, etc):
${#Global#username}
To access the same property value within a Groovy Test Step, you can use the following syntax:
context.expand('${#scope#propertyName}')
...as in the following example:
context.expand('${#Global#username}')
What we did was the following:
created a test data file to store all the specific input data for the different services (testdata.properties)
Example content of testdata.properties:
Billing_customerID=1234567
OtherService_paymentid=12121212
....
create a SoupUi global parameter (File/Preferences/Global properties): testdata_filepath=C:\...
For specific services we added a Properties test step. You can specify the "Load from" field to our new global parameter: ${#Global#testdata_filepath} Now you can use the Load button to load parameters.
Finally you can reference the parameter in your xml in the following format: ${Properties#Billing_customerID}
Example content of a service with parameter:
...
<BillingCustomerIdentification>
<BillingCustomerID>${#Properties#Billing_customerID}</BillingCustomerID>
</BillingCustomerIdentification>
...
To set up your projects in this manner also helps to automate service tests eg. using Hudson (see my previous SO answer).
If it is too heavy and automation is not a target, you can simply use ${#Global#someinputvariable} format in your xml ;-)