Properties serve as a central repository and act as a temporary storage for our information. This may include not only login details such as username and password, but also session related data such as session id, page context, header details, and beyond.
This forms the seventh tutorial in our SoapUI training available online for free.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
Let’s dive in to understand how to include a property test step, how to assign values to the property, and how to display them in the log.
Adding Properties to SoapUI:
Steps for adding the properties are as follows:
- Upon right-clicking on the Test steps node
- Choose the Add Step option followed by selecting the Properties from the context menu
- Input the preferred property name and select OK
- On the properties screen, press on the symbol to add a property
- Key in your chosen property name and tap on the OK button. Let’s input Pro_Response as an example
- If necessary, provide a default value for this property. “Nothing” could be a possible input
- Next up, attach a Groovy Script test step adjacent to the property step. Refer to the picture illustrated below for clarification.
We can shift the property data throughout the test steps when the test is in execution. The Property Transfer test step is provided by SoapUI Pro to accomplish this. Refer to the image below for a visual explanation.
Include the following script in your groovy script. This script assigns string text to the property and displays it in the log post-execution of the test case.
String testString = "TestString" testRunner.testCase.setPropertyValue( "Pro_Response", testString ) def getLocalPropValue = testRunner.testCase.getPropertyValue("Pro_Response") log.info(getLocalPropValue)
- Once the above script is scribed down in the editor, double-click on the step with the test case name.
- Execute the test case by pressing on the symbol and minutely observe the results in the script log tab.
Pulling up properties:
There are several methodologies available for accessing test case, test suite, and project properties data through the script. Here are some of the examples.
def getTestCasePropertyValue = testRunner.testCase.getPropertyValue( "LocalPropertyName" ) def getTestSuitePropertyValue = testRunner.testCase.testSuite.getPropertyValue ( " LocalPropertyName " ) def getProjectPropertyValue = testRunner.testCase.testSuite.project.getPropertyValue ( " LocalPropertyName " )
For gaining global property access, follow up on the script below:
def getGlobalPropertyValue = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue ( "GlobalPropertyName" )
These instructions in the script are employed to set and get values from local and global properties.
testRunner.testCase.setPropertyValue( " LocalPropertyName ", someValue ) testRunner.testCase.testSuite.setPropertyValue( " LocalPropertyName ", someValue ) testRunner.testCase.testSuite.project.setPropertyValue( " LocalPropertyName ", someValue ) com.eviware.soapui.SoapUI.globalProperties.setPropertyValue ( " GlobalPropertyName ", someValue )
In these scripts, the testRunner object refers to project, test cases, or test suites. setPropertyValue and getPropertyValue are functions or methods.
Like mentioned in the aforementioned script, data can be allocated to properties.
testRunner.testCase.testSteps[“Properties”].setPropertyValue( “Pro_Response”, testString )
When executing the above script, the property gets updated in the property test step. The screenshot below explains this aspect.
Gathering response data:
Let’s move on to discuss how to extract response data via the script. Adhere to the steps below:
- Run the service request once and then examine the output
- Open up the Groovy script editor and right-click on it, as demonstrated in the screenshot below
Upon mentioning the property name, SoapUI Pro will generate the following script.
def response = context.expand( ‘${ServiceRequest#Response}’ )
As we’re aware, “def” is a Groovy script keyword used for defining properties/objects. By default, “response” is used by SoapUI Pro as the property name in the Get Property popup. This name could be changed accordingly. The rest of the script will be auto-generated.
Let’s try merging the previously discussed script with the above script. Here’s how it looks:
def response = context.expand( '${ServiceRequest#Response}' ) testRunner.testCase.setPropertyValue( "Pro_Response", response ) def getLocalPropValue = testRunner.testCase.getPropertyValue("Pro_Response") log.info(getLocalPropValue)
When this script is run individually, it will post all the response data in the log division. With the test case execution, the script log will display the same output.
Formulating properties from the navigation pane:
There exists another way of crafting properties locally via the property panel, which appears when you tap on the nodes beneath the project tree. Let’s understand this process:
- Add a currency converter service request and a Groovy script test step under the test suite named ConversionTestSuite.
- Click on the TestSuite name under the project, specifically ConversionTestSuite.
- Find the Property panel at the bottom end of the Navigation panel. It contains two tabs namely, TestSuite Properties and Custom Properties.
- Press on the Custom Properties tab
- Press on the plus (+) symbol to add the property as displayed below:
- Key in the name of the property and then supply a default input value as illustrated above.
- Execute the currency converter service request. This is crucial as we’ll only receive the property data when we right-click on the editor.
- Enter the following script in the editor:
def getPropValue = context.testCase.NetSuite.getPropertyValue(“FromCurrencyValue”)
- Press on the Run symbol
The script fetches the property value and assigns it to the variable “getProValue”. To print the property value, the following script can be applied:
Log.info (getPropValue);
Global Properties:
Let’s delve a bit into global properties now. These properties are predefined at one location, and can be accessed across various project components like test suites, test cases, test steps, and more.
These are the scripts you need to record data into global properties.
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue ( "prjFromCurrency", "USD" ) com.eviware.soapui.SoapUI.globalProperties.setPropertyValue ( "prjToCurrency", "INR" )
Once the test step script mentioned previously is executed, the mentioned properties will be formed and their respective values will be set. Let’s validate it.
- Tap on the File menu
- Opt for the Preferences option
- Identify the Global Properties tab on the left side and click on it
- Verify the properties on the property sheet found on the right side. For reference, take a look at the picture below:
In Conclusion:
Properties are handy for moving data between test steps, like test suites, test steps, and test cases. Properties can be defined using Groovy script. The script allows to allocate and pull out data from properties. Just with other test steps, context menu brings in the option of renaming, deleting, or disabling properties through right-clicking on it.
In our upcoming tutorial, we will dig deeper into properties and touch upon topics like passing properties into the input request, extracting them from global properties, property transfer test steps, and so on.
We welcome you to continue learning with us. Don’t hesitate to put forward your queries or share your thoughts.