Contact Us
About Us
News
Home
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome,
Guest
. Please
login
or
register
.
November 22, 2008, 09:10:52 am
Username:
Password:
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Forgot your password?
Adding assertions to TestRequest dynamically using Groovy
Welcome,
Guest
. Please
login
or
register
.
November 22, 2008, 09:10:52 am
News:
The Forums are up! Welcome to eviware.
Eviware Forum
soapUI
soapUI
Adding assertions to TestRequest dynamically using Groovy
« previous
next »
Pages:
[
1
]
Author
Topic: Adding assertions to TestRequest dynamically using Groovy (Read 887 times)
Tareque
Newbie
Posts: 17
Adding assertions to TestRequest dynamically using Groovy
«
on:
January 22, 2008, 10:08:45 pm »
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
Logged
omatzura
Administrator
Hero Member
Posts: 1,425
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #1 on:
January 22, 2008, 10:26:30 pm »
Hi,
this is definitely possible. The value of the assertText argument in your script must match that of one of the available assertion types as displayed in the combo box when adding a new assertion via the GUI.. what value are you specifying?
regards,
/Ole
eviware.com
Logged
Tareque
Newbie
Posts: 17
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #2 on:
January 22, 2008, 10:33:49 pm »
Hi Ole,
I am trying to add XPath Match assertion. The api for addAssertion does not take any assertionType parameter, all it takes is a String which I am assuming is the XPath eg:
declare namespace ns1='
http://nextel.com/ovm';
//ns1:ovm/ns1:ovm-response/ns1:plans-response/ns1:price-plan/ns1:plan-id = 'FF1001H'
Regards
Logged
omatzura
Administrator
Hero Member
Posts: 1,425
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #3 on:
January 22, 2008, 10:41:40 pm »
Hi,
try the following:
def assertion = testRunner.getTestCase().getTestStepByName("Test Request").addAssertion("XPath Match")
assertion.path = ...
assertion.expectedContent = ...
Hope this helps,
regards,
/Ole
eviware.com
Logged
Tareque
Newbie
Posts: 17
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #4 on:
January 24, 2008, 08:51:27 pm »
Thanks a lot for the code snippet that was what i was looking for. Using the following script I was able to achieve what i was trying to do.
def assertionsList = testRunner.getTestCase().getTestStepByName("Test Request").getAssertionList()
for( e in assertionsList){
testRunner.getTestCase().getTestStepByName("Test Request").removeAssertion(e)
}
def testCaseName = testRunner.getTestCase().getTestStepByName("DataSource").getPropertyValue("test_case_name")
def assertText = testRunner.getTestCase().getTestStepByName("DataSource").getPropertyValue("assert_text")
def assertion = testRunner.getTestCase().getTestStepByName("Test Request").addAssertion("XPath Match")
println " \n\n ########## Start TestCase Name " + testCaseName
assertion.name = testCaseName
assertion.path = assertText
assertion.expectedContent = true
Thanks once again
Logged
omatzura
Administrator
Hero Member
Posts: 1,425
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #5 on:
January 25, 2008, 02:50:06 pm »
Hi!
this is really cool actually (ie loading requests/assertions from a database), maybe something that should be supported natively?
regards!
/Ole
eviware.com
Logged
srinivas das l
Newbie
Posts: 6
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #6 on:
October 02, 2008, 02:21:02 pm »
Hi ,
Can u plz tell me how to rename "XPATH-match" assertion using groovy script???
Logged
omatzura
Administrator
Hero Member
Posts: 1,425
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #7 on:
October 02, 2008, 11:39:25 pm »
Hi!
sure, just get hold of the assertion and set its name property;
testCase.testRunner.testSteps["Request 1"].getAssertionByName( "My XPath Match" ).name = "..."
regards!
/Ole
eviware.com
Logged
srinivas das l
Newbie
Posts: 6
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #8 on:
October 03, 2008, 02:36:50 pm »
Hi Ole,
Thanks a lot.it's working ...I have another doubt...How to declare namespaces in the XPATH-match assertion using groovy script???
Logged
omatzura
Administrator
Hero Member
Posts: 1,425
Re: Adding assertions to TestRequest dynamically using Groovy
«
Reply #9 on:
October 03, 2008, 10:07:45 pm »
Hi!
use the XmlUtils.declareXPathNamespaces( String xmlString ) method, which will return the namespace declarations for all namespaces used in the specified xml string.
regards,
/Ole
eviware.com
Logged
Pages:
[
1
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> eviware general
-----------------------------
soapUI
-----------------------------
=> soapUI
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Powered by SMF 1.1.2
|
SMF © 2006-2007, Simple Machines LLC
Loading...