Forum Discussion

Tareque's avatar
Tareque
Occasional Contributor
17 years ago

Adding assertions to TestRequest dynamically using Groovy

Hi,
I have an urgent requirement in my project which needs to be implemented.
The requirement is that all the Input XML and the XPath assertions will be moved to the database.
The project file will not have the input XML or assertions in the Test Request.
To execute this we have created the following steps.
1. Datasource step to read the request_xml and assertion_text from DB
select request_xml, test_case_name, request_id, assert_text
  from TEST_REQUEST_DATA A, ASSERTIONS_DATA B
  where A.REQUEST_ID = B.ASSERT_REQUEST_ID
 
2. Property Transfer step to feed the request_xml property from the DataSource to the TestRequest Step.

3. Groovy Script to add assertions to the Test Request by getting the assertion_text from the DataSource

def assertText = testRunner.getTestCase().getTestStepByName("DataSource").getPropertyValue("assert_text")
testRunner.getTestCase().getTestStepByName("Test Request").addAssertion(assertText)

Step 3 fails giving the following exception
2008-01-22 14:53:29,125 ERROR [errorlog] java.lang.NullPointerException
java.lang.NullPointerException
at com.eviware.soapui.impl.wsdl.panels.teststeps.AssertionsPanel$AssertionListModel.addAssertion(AssertionsPanel.java:358)
at com.eviware.soapui.impl.wsdl.panels.teststeps.AssertionsPanel$AssertionListModel.assertionAdded(AssertionsPanel.java:350)
at com.eviware.soapui.impl.wsdl.support.assertions.AssertionsSupport.fireAssertionAdded(AssertionsSupport.java:135)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest.addAssertion(WsdlTestRequest.java:187)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.addAssertion(WsdlTestRequestStep.java:539)
at gjdk.com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at Script1.run(Script1.groovy:14)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:59)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:51)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:140)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction.actionPerformed(GroovyScriptStepDesktopPanel


My question is:
Is it possible to dynamically add assertions to a TestRequest?
And if it is could you please point out where I am going wrong.
Would appreacite any help with this problem.
Best Regards
tareque

18 Replies