📜 ⬆️ ⬇️

Testing, using SoapUI, a web service that returns a list of items

SoapUI - need help

About six months ago, I was instructed to test (at the same time and automate it) a project that actively uses services that are responsible for using the SOAP protocol. Showed such a cool program like SoapUI. That's what a wonderful this program, what is its intuitive interface and intuitive online help (soapui.org), we leave behind the article.

Unfortunately, with all her virtues she is rather narrowly specialized and probably, therefore, now there is a complete lack of materials about her in Russian. Intuitive help in English can not help with any rather complex tasks (although to begin, it is indispensable), and it is quite difficult to find a step-by-step manual on all Internet spaces.

In short!

Today we will solve a specific applied task: namely, the automation of testing a service that returns us a list of such elements:
<item>
<FeedbackId>357</FeedbackId>
<RequestDate>2012-04-08T00:48:49.493</RequestDate>
<FeedbackStatusName></FeedbackStatusName>
<FeedbackTypeName></FeedbackTypeName>
<AuthorFullName> </AuthorFullName>
<FeedbackStatusId>1</FeedbackStatusId>
<FeedbackTypeId>1</FeedbackTypeId>
<AuthorUserId>69</AuthorUserId>
</item>


When a similar task arose before me, I cowardly checked with my hands (set xpath-checks) and reported that the work was done (I didn’t know the product, and there’s never much time left ...). Now I am ready to improve, but at the same time tell everyone how this can be done. At once I will make a reservation that my method is only one of several, which does not claim to be ideal or optimal. And I still hope to learn other ways - I count on your ideas, experience, fantasies ...

If you are reading this article, I hope that you already have a working service that returns a similar list and base from which it draws data. And you know how to write such a select so that the result coincides with what the service returns.

In the figure, the project that turned out for me: we have xml, received in response to the service, we have the results from the database. They a little do not coincide, because I am too lazy to add now join'y and other mura (already irrelevant).
')
Now delicious:
it is clear that you can’t do anything with a mouse and ready checks - you need to program. You need to program in SoapUI on Groovy. Java code is valid Groovy code, so you don’t need to learn anything (I, for example, do not know Groovy)).
Let's return to the problem: I see 2 ways to solve it: you can make a Script Assertion in the JDBC Request step, or you can put it into a separate step.
I rendered. Further the code, for the sake of it all and was started. I think that the one who can change it for his own task will be able to figure out the comments that are there, so further words are unnecessary ...

import com.eviware.soapui.support.XmlHolder;

boolean b = true;
def soapRequest = testRunner.testCase.getTestStepAt(0);
// - item'
XmlHolder response = new XmlHolder( soapRequest.getProperty('Response').getValue() );
int numberOfItems = response.getXmlObject().selectPath('//item').size();

if (numberOfItems != 0)
{
XmlHolder row, item;
for (int i=1; i<=numberOfItems; i++) {
row = new XmlHolder( context.expand ( '${JDBC Request#ResponseAsXml#//Row['+i+']}' ));
item = new XmlHolder( context.expand ( '${GetFeedbackList#Response#//item['+i+']}' ));
//compareItemWithRow - ,
if (!compareItemWithRow (item, row) ) {
b = false;
//
break;
}
}
}
else {
//
def jdbcRequest = testRunner.testCase.getTestStepAt(1);
response = new XmlHolder( jdbcRequest.getProperty('ResponseAsXml').getValue() )
if (response.getXmlObject().selectPath('//item').size() != 0) {
log.error "There was no items in response but I found a few in database! WTF?!"
assert false;
}
}
assert b;
return;

/** 2 XmlHolder' , - - false*/
private boolean compareItemWithRow (XmlHolder item, XmlHolder row) {
boolean b = true;

if (!item.getNodeValue('//FeedbackId').equals( row.getNodeValue('//FEEDBACKID') )) {
log.error ('''FeedbackId doesn't corresponds database! Here could be your advertisment...'''
+ item.getNodeValue('//FeedbackId') + ' != ' + row.getNodeValue('//FEEDBACKID') +
'!!!ITEM: '+ item.getXml()+
' !!!ROW: '+ row.getXml());
b=false;
}
if (!item.getNodeValue('//RequestDate').equals( row.getNodeValue('//DATEINXML') )) {
log.error ('''RequestDate doesn't corresponds database! Here could be your advertisment... "'''
+ item.getNodeValue('//RequestDate') + '" != "' + row.getNodeValue('//DATEINXML') +
'" !!!ITEM: '+ item.getXml()+
' !!!ROW: '+ row.getXml());
b=false;
}
if (!item.getNodeValue('//AuthorUserId').equals( row.getNodeValue('//REQUESTUSERID') )) {
log.error ('''AuthorUserId doesn't corresponds database! Here could be your advertisment... "'''
+ item.getNodeValue('//AuthorUserId') + '" != "' + row.getNodeValue('//REQUESTUSERID') +
'" !!!ITEM: '+ item.getXml()+
' !!!ROW: '+ row.getXml());
b=false;
}
//...
return b;
}

Source: https://habr.com/ru/post/142429/


All Articles