Saturday, September 3, 2011

Property Transfer in soapUI

Property transfer function (/TestStep) provides an option to transfer properties between TestSteps and their TestCase, TestsSuite and Project. For example, Property transfer TestStep could be used to pass sessonID value extracted from a response of one request into subsequent request.

Alright let’s get started on how to transfer a property.

Assumption: soapUI application is installed on your machine.
For blogging purpose, I am using free soapUI 4.0 incase you do not have Pro soapUI.

Step 1:
First we will need a wsdl. For demonstration purpose, I am using Metric Weight Unit Convertor.

Step 2: Start the application and then navigate(File ->New soapUI project) to New soapUI project window.

Step 3: Enter a project name in Project Name text box. Lets call it "WeightConvertor". Also enter the wsdl URL from step 1 into Initial WSDL/WADL textbox. See the screenshot below:

Step 4: click OK button. If the application is able to successfully access the WSDL then a new project called "WeightConverter" is added under "Projects" list. You will also see the Bindings. If you expand those bindings, you will see Operations and SOAP requests.

Step 5: Right click "WeightConverter" project and Click "New TestSuite" option. Enter a TestSuite name (i.e. Metric TestSuite) in the textbox and click OK button. A TestSuite is created under the WeightConverter project.

Step 6: Right click the TestSuite and select "New TestCase" option. Enter a TestCase name(i.e. WeightTestCase) in the textbox and click OK button. A TestCase is created under the TestSuite. A TestCase window is displayed.

Step 7: Add two steps to this TestCase. One step called as "GramToKilogramStep" and other one called "KilogramToGramStep". Make sure you follow all the steps required to create these steps. Finally you will have something like this as shown in the screenshot

Step 8: Double click "GramToKilogramStep" and enter following values in place of question mark.
MetricWeightValue = 3000
fromMetricWeightUnit = gram
toMetricWieghtUnit= kilogram
Once done click on the Green Run button. If successful, you should see "3" in the response. See the screenshot below.

Step 9: Double click "KilogramToGramStep" and enter following values in place of question mark.
fromMetricWeightUnit = kilogram
toMetricWieghtUnit= gram
NOTE: Leave MetricWeightValue as it is. We want to pass the value received in step 8 above using Transfer Property TestStep into this variable. If you try to run this step, you will get"Server was unable to read request" error response.

Step 10: Right click "Test Steps" and add a "Property Transfer" step. The step will be added at the bottom of the test step list. A Property Transfer window is displayed.

Note: You want this step to be between the two steps so that the value captured in GramToKilogramStep is passed to KilogramToGramStep. Therefore, hightlight the step and move it between the two steps.

Step 11: Enter a name for Transfer by clicking the "Plus" sign in the Property Transfer window.

Step 12:
In Source dropdown, select "GramToKilogramStep" and Property as "Response"
and in Target dropdown, select "KilogramToGramStep" and Property as "Request". In the source text box, we will need to declare a namespace and enter the XPath of the property that we want to transfer. See the screenshot under step 13.

Step 13: Once done, run the test step and in transfer log you will notice that pResponse has a value 3 now. See the screenshot below.

Step 14: Open up the "KilogramToGramStep" test step. You will now notice that "MetricWieghtValue" has automatically been assigned value 3. Run the step and you will see the correct response from the server with Result as 3000.

Well this sum up how to use Property Transfer TestStep to transfer a value from a response to a request.

2 comments:

Sonal said...

Great post. thank you for the detailed explantion

Anonymous said...

Very nice paji..