Thursday, January 08, 2009

A simple example for Xpath on web service test

when you do automation test or performance test on web service, you may need to do some correlation work on dynamic value returned by server.
Take Jmeter as an example, for correlation work, there is two ways to catch dynamic value
1. using Regular Expression Extractor-- you can write simple Regular Expression to extract the value
2. using XPath Extractor--write Xpath to seek the value

Here is a simple example to show how you deal with web service correlation work using Xpath :

I want to get the token value returned by the server, here is the response XML:





true
3FBCB0BDA521B5BC1A399AC094063993D26BC70BA1E3175927D6F






Xpath: //*[local-name()='token']

how about there is the namespace in the XML?? just like this:



getResetPasswordTokenResponse xmlns:ns1="http://user.123.com/user_security_service">

true
3FBCB0BDA521B5BC1A399AC094063993D26BC70BA1E3175927D6F






XPath://*[local-name()='token' and namespace-uri()="http://api.user.123.com"]

it is simple, and user-friendly :)

at Last, you can test your Xpath expression here : http://www.mizar.dk/XPath/Default.aspx

hope this helps!

No comments:

Post a Comment