cancel
Showing results for 
Search instead for 
Did you mean: 

Delete request and Validation is not working getting error message

vaichalnishad
New Contributor

Delete request and Validation is not working getting error message

import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext

/* Secenrio is we are adding employee, getting employee details and checking or comparing weather whatever details we got with
get employee matches with addEmployee. */
/* Script is invoked with log,context and testRunner variable.
This is a heart of Groovy script, we are going to use these variable in our script */
log.info "welcome to learn groovy"
log.info context.expand('${#TestCase#name}')
log.info context.expand('${#TestCase#age}')
//to access or modify any property from another testcase then you have to come through its parent only
/* here scenerio is we define id in GetEmployee under custom property and want to access that
* which is possible through testRunner only and not with context
*/
//Project >> TestSuite >> TestCase >> TestStep Remember this hierarchy Parent to child and vicavarsa.
log.info testRunner.testCase.testSuite.testCases["GetEmployee"].getPropertyValue("id")
/*In above command first we move to testCase level then testSuite and then testCases(here we
* write testcases because with testCases we are able to access all testCases),
* but inthis case we need to access only one TC that i.e GetEmployee because we want id from it.
* After this we need to get property value i.e id which we will achive with the help of getPropertyValue.
*/
log.info testRunner.testCase.testSuite.testCases["AddEmployee"].getPropertyValue("age")
//in above age is under cuctom property of AddElployee
//Project >> TestSuite >> TestCase >> TestStep Remember this hierarchy Parent to child and vicavarsa.

log.info testRunner.testCase.getPropertyValue("dept")
//in above command dept is present in script it self so no need to go till parent

// now we want to access Request property which is present under custom of get under Teststep of GetEmployee
log.info testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"].getPropertyValue("Request")

// if you want to set address in AddEmployee custom property the you need to use setPropertyValue instead of getPropertyValue
//in below command log.info is not needed as we are setting the value.
//testRunner.testCase.testSuite.testCases["GetEmployee"].setPropertyValue("address", "Dreams Rhythm")
// if you want to set pincode in AddEmployee custom property the you need to use setPropertyValue instead of getPropertyValue
//testRunner.testCase.testSuite.testCases["GetEmployee"].setPropertyValue("pincode","411021")

//Now gender is define under custom property of Project i.e Automation let us see how to access it
def project=testRunner.testCase.testSuite.project
log.info project.getPropertyValue("gender")
/*in above command at first line, we store project i.e Automation path under one variable
* i.e project and then using that variable i.e project we got property value of gender i.e M. def is used to store valuse of variable
*/

// Hit addEmployee request with properties from testcase level and do E2E Testing
/* step 1: We need to pull XML request from AddEmployee customeproperties
* sep 2: Need to import XML holder pakage i.e import com.eviware.soapui.support.XmlHolder
* step 3: need to update XML with the help of XmlHolder
*/
def addReq=testRunner.testCase.testSuite.testCases["AddEmployee"].testSteps["add"].getPropertyValue("Request")
def name=testRunner.testCase.testSuite.testCases["AddEmployee"].getPropertyValue("name")
def id=testRunner.testCase.testSuite.testCases["AddEmployee"].getPropertyValue("id")
def dept=testRunner.testCase.testSuite.testCases["AddEmployee"].getPropertyValue("department")
def age=testRunner.testCase.testSuite.testCases["AddEmployee"].getPropertyValue("age")
def xmlAdd=new XmlHolder(addReq)//update XML with the help of XmlHolder
xmlAdd.setNodeValue("//typ:addEmployee/typ:name",name)
xmlAdd.setNodeValue("//typ:addEmployee/typ:id",id)
xmlAdd.setNodeValue("//typ:addEmployee/typ:Department",dept)
xmlAdd.setNodeValue("//typ:addEmployee/typ:age",age)
def newAddXml=xmlAdd.getXml()// it will save the XML with name, id, dept and age
//log info newAddXml //if you comment this command then you are able to see Xml in Popup

//now we are putting new Xml in AddEmployee
testRunner.testCase.testSuite.testCases["AddEmployee"].testSteps["add"].setPropertyValue("Request",newAddXml)

//now call the service
//to call the service one method is there WsdlTestRunContext i.e import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
//context of AddEmployee testcase should be passed as Add step which we are trying to run belongs to that Testcase

def addTestStep=testRunner.testCase.testSuite.testCases["AddEmployee"].testSteps["add"]
def contextAddEmployee=new WsdlTestRunContext(addTestStep);

addTestStep.run(testRunner,contextAddEmployee)

// Hit getEmployee and generate response. Validate the response if it have the name which added in our earlier step.
def getReq=testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"].getPropertyValue("Request")
def getEmpxml=new XmlHolder(getReq)
getEmpxml.setNodeValue("//typ:getEmployeeDetails/typ:employeeName", name)
def newgetEmpxml=getEmpxml.getXml()// here we are saving xml and put it in one variable
testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"].setPropertyValue("Request",newgetEmpxml)
def getTestStep=testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"]; //we want to run the request
def contextGetEmployee=new WsdlTestRunContext(getTestStep);
getTestStep.run(testRunner,contextGetEmployee)

//Now we are validating the response which we got with GetEmployee and compare it with Request of AddEmployee so that we will do E2E testing.
def getRes=testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"].getPropertyValue("Response")
def getEmpres=new XmlHolder(getRes)
def Getresponse=getEmpres.getNodeValue("//ns:name")

log.info Getresponse
log.info name
assert Getresponse==name// it will compair the response of GetEmployee with request of AddEmployee

// delete request
def getRep=testRunner.testCase.testSuite.testCases["DeleteEmployee"].testSteps["delete"].getPropertyValue("Request")
def deleteEmpxml=new XmlHolder(getRep)
deleteEmpxml.setNodeValue("//typ:deleteEmployee/typ:employeeName", name)
def newdeleteEmpxml=deleteEmpxml.getXml()// here we are saving xml and put it in one variable
testRunner.testCase.testSuite.testCases["DeleteEmployee"].testSteps["delete"].setPropertyValue("Request",newdeleteEmpxml)
def deleteTestStep=testRunner.testCase.testSuite.testCases["DeleteEmployee"].testSteps["delete"]; //we want to run the request
def contextDeleteEmployee=new WsdlTestRunContext(deleteTestStep);
log.info deleteTestStep.run(testRunner,contextDeleteEmployee)

//validation
def getRes=testRunner.testCase.testSuite.testCases["DeleteEmployee"].testSteps["delete"].getPropertyValue("Response")
def deleteEmpres=new XmlHolder(getRes)
def Deleteresponse=deleteEmpres.getNodeValue("//ns:name")
log.info"Expected result is: " Deleteresponse//this is expected result
log.info "Actual result is: " name//this is Actual result
assert Deleteresponse==name

 

3 REPLIES 3
nmrao
Community Hero

Re: Delete request and Validation is not working getting error message

It would easy for some one if you describe issue.
Now people have to find out what is code and identify which might take long time.


Regards,
Rao.
vaichalnishad
New Contributor

Re: Delete request and Validation is not working getting error message

following error i am getting after running the code

 

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.eviware.soapui.support.XmlHolder# . Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [interface org.apache.xmlbeans.XmlObject] [interface org.w3c.dom.Node] error at line: 87

nmrao
Community Hero

Re: Delete request and Validation is not working getting error message

@vaichalnishad 

That is because, there is no response from "GetEmployee" test. Ensure you get the response.



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors