Ask a Question

Delete request and Validation is not working getting error message

New Contributor

Delete request and Validation is not working getting error message

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 */ "welcome to learn groovy" context.expand('${#TestCase#name}') 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. 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.
*/ 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. 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 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 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

//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 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
* 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
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

//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);,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
def getTestStep=testRunner.testCase.testSuite.testCases["GetEmployee"].testSteps["get"]; //we want to run the request
def contextGetEmployee=new WsdlTestRunContext(getTestStep);,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") Getresponse 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
def deleteTestStep=testRunner.testCase.testSuite.testCases["DeleteEmployee"].testSteps["delete"]; //we want to run the request
def contextDeleteEmployee=new WsdlTestRunContext(deleteTestStep);,contextDeleteEmployee)

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


Community Hero

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.

New Contributor

following error i am getting after running the code


groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method . 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


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

Showing results for 
Search instead for 
Did you mean: