我尝试将断言添加到WsdlTestRequestStep
,但到目前为止我在大多数部分都失败了。
我尝试的第一件事是使用WsdlTestRequestStep.addAssertion
添加断言,该断言仅适用于SoapResponseAssertion
并正确更新了GUI。当我尝试使用其他一些断言类型时,SoapUI在控制台窗口中响应并出错,并使用带有空类型属性的断言损坏了我的项目文件。 (见下文addNotSoapFaultAssertion
)。
然后我确实更新了测试步骤的请求配置。每次都有效,没有错误。但是,GUI只在我重新加载项目时才刷新,这是不切实际的。 (见下文AddAssertions
)
现在,我想知道是否有办法使这项工作正常,这意味着没有错误和立即的GUI更新。
import com.eviware.soapui.config.CredentialsConfig;
import com.eviware.soapui.config.TestAssertionConfig;
import com.eviware.soapui.config.WsdlRequestConfig;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.NotSoapFaultAssertion;
import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapFaultAssertion;
import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapResponseAssertion;
import com.eviware.soapui.model.testsuite.TestAssertion;
import org.apache.log4j.Logger;
public class SomeTestStep
{
private WsdlTestRequestStep _step;
[...]
public void AddAssertions() {
//addSoapResponseAssertion();
//addNotSoapFaultAssertion();
// directly manipulating config tree, but only updates UI after project reload
WsdlRequestConfig config = _step.getTestRequest().getConfig();
TestAssertionConfig testAssertionConfig = config.addNewAssertion();
testAssertionConfig.setType("SOAP Fault Assertion");
testAssertionConfig.setName("Not SOAP Fault");
// setConfig did not really change anything in terms of GUI updates, I kept it in anyway
_step.getTestRequest().setConfig(config);
}
private void addSoapResponseAssertion() {
//<con:assertion type="SOAP Response" name="SOAP Response"/>
_step.addAssertion(SoapResponseAssertion.ID);
}
private void addNotSoapFaultAssertion() {
// should create:<con:assertion type="SOAP Fault Assertion" name="Not SOAP Fault"/>
// but creates: <con:assertion type="" />
_step.addAssertion(SoapResponseAssertion.ID);
}
}
答案 0 :(得分:2)
经过大量的代码处理后,我终于找到了解决问题的方法。
诀窍是要理解WsdlTestRequestStep.addAssertion
需要将Assertion的标签作为参数与相应的Assertion工厂中设置的标签进行比较。因此,在我的示例中,获取标签的最简单方法是从NotSoapFaultAssertion.Factory
本身获取它。
以下代码段根据需要起作用:
private void addNotSoapFaultAssertion() {
//<con:assertion type="SOAP Fault Assertion" name="Not SOAP Fault"/>
_step.addAssertion((new NotSoapFaultAssertion.Factory()).getAssertionLabel());
}
我希望这将有助于将来遇到同样问题的任何人。
这是我能找到的所有断言工厂的列表:
SoapResponseAssertion.Factory
SoapRequestAssertion.Factory
SchemaComplianceAssertion.Factory
SimpleContainsAssertion.Factory
SimpleNotContainsAssertion.Factory
XPathContainsAssertion.Factory
NotSoapFaultAssertion.Factory
SoapFaultAssertion.Factory
ResponseSLAAssertion.Factory
GroovyScriptAssertion.Factory
XQueryContainsAssertion.Factory
WSSStatusAssertion.Factory
WSAResponseAssertion.Factory
WSARequestAssertion.Factory
JMSStatusAssertion.Factory
JMSTimeoutAssertion.Factory
JdbcStatusAssertion.Factory
JdbcTimeoutAssertion.Factory
HttpDownloadAllResourcesAssertion.Factory