Xpath assertions using Soap-Ui

Lets us make a new Soap Project and copy WSDL of our local application and then add a login request ,then login admin and then we add a new request to add products.

Or we can add a assertion for login request. we can simply click the plus button and then add an assertion contains to check if the login response contains the info we want example we are logged in etc.

Or for an add product response we can check under product details tag under item tag no 1 under product_name what is the text. After typing the above command click select from current to check the results I,e what will appear , in our case it is Harley.

Then we can use the below command to count the no of items with a given tag name

count(//productdetails/item/product_name)

Note after clicking save from current we can actually save that xpath and run our request again and if the number of items remain the same as the number we have saved the assertion will pass ,otherwise fail.

We type the below command in a new xpath assertion and click select from current ,it will print true the product name matches Harley. We can then save this assertion and run our soap request again and if the response at that particular tag is still same then again xpath assertion will pass

matches(//productdetails/item[1]/product_name/text(),'harley')

If we want the result to be any letter from a to z or capital A-Z.

matches(//productdetails/item[1]/product_name/text(),'[a-zA-Z]*')

Or we want the result to be any number

matches(//productdetails/item[1]/price/text(),'\d')

Or how many digits we want in our response I,e only 2 to 3 digits

matches(//productdetails/item[1]/price/text(),'\d{2,3}')

Similarly in login request we can add a new xpath to make sure we logged in I,e a session id is there in the response which can contain anything from lower to uppercase letter to any nos

matches(//sessionid/text(),'[a-zA-Z0-9]*')