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

SoapUI - need help

About half a year ago, they instructed me to test (at the same time and automate it) a project that actively uses services that meet the SOAP protocol. They showed such a cool program as SoapUI. What a wonderful program this is, what its intuitive interface and intuitive online help (soapui.org) are, we will leave outside the scope of this article.

Unfortunately, for all its merits, she is rather narrowly specialized and probably, therefore, now there is a complete lack of materials about her in Russian. The intuitive help in English cannot help with any fairly complex tasks (although it is indispensable to get started), and it’s quite difficult to find a step-by-step manual on all the Internet.

In short!

Today we will solve a specific application: namely, the automation of testing a service that returns us a list of these elements:

357
2012-04-08T00:48:49.493
Отправлено
Ошибка
Сидоров Иван Петрович
1
1
69



When a similar task confronted me, I cowardly checked it with my hands (set xpath checks) and reported that it was done (I didn’t know the product, and there is never too much time ...). Now I am ready to correct myself, but at the same time to tell everyone how this can be done. Immediately make a reservation that my method is just one of several that do not claim to be ideal or optimality. And I hope to learn other ways too - I rely on your ideas, experience, fantasies ...

If you read this article, I hope that you already have a working service that returns a similar list and the base from which it draws data. And you can write such a select so that the result matches what the service returns.

In the figure, the project that turned out for me: we have the xml received in response from the service, we have the results from the database. They do not coincide a bit, because I am too lazy to finish joining now and other mura (now irrelevant).

Now yummy:
it is clear that there is nothing you can do with the mouse and ready-made checks - you need to program. You need to program in SoapUI on Groovy. Java code is the correct 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 Script Assertion in the JDBC Request step, or you can take it out in a separate step.
I endured. Further the code, for the sake of it everything was started. I think that someone who can change it for their task will be able to figure out the comments that are, so that further words are superfluous ...

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;
}

Also popular now: