Contributions
Re: How do I record each request and response within the same test step?
In my test case I have this in the Setup Script: //Create a new filereader object, using the context variable so it can be used between test components context.fileReader = new BufferedReader(new FileReader("/Users/test/Documents/test/testdata.csv")) //Read in the first line of the data file firstLine = context.fileReader.readLine() //Split the first line into a string array and assign the array elements to various test case properties String[] propData = firstLine.split("\\,") testCase.setPropertyValue("partnerId",propData[0]) testCase.setPropertyValue("honorificPrefix",propData[1]) testCase.setPropertyValue("first",propData[2]) testCase.setPropertyValue("middle",propData[3]) testCase.setPropertyValue("last",propData[4]) testCase.setPropertyValue("honorificSuffix",propData[5]) testCase.setPropertyValue("addresstype",propData[6]) testCase.setPropertyValue("street1",propData[7]) My test case has two steps... 1. REST Request with my POST payload 2. groovy script which has the code I pasted above in my previous comment. The REST Request from Step 1goes through the data in my testdata.csv file until it reaches the end of the line. What I would like to achieve is record every request and response into a file or files (if not possible). Thanks again.2KViews0likes0CommentsRe: How do I record each request and response within the same test step?
Hi. I am not using it in the tear down script. I have one POST request and another step for the groovy script... here is what I've tried: /*Read in the next line of the file We can use the same fileReader created in the Setup script because it was assigned to the context variable.*/ nextLine = context.fileReader.readLine() if(nextLine != null){ String[] propData = nextLine.split("\\,") curTC = testRunner.testCase curTC.setPropertyValue("systemId",propData[0]) curTC.setPropertyValue("partnerId",propData[1]) curTC.setPropertyValue("honorificPrefix",propData[2]) curTC.setPropertyValue("first",propData[3]) curTC.setPropertyValue("middle",propData[4]) curTC.setPropertyValue("last",propData[5]) // Define collection of test steps def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) //Groovy Script to loop through each requests in the test case. soapuiRequests.each{ //Creating file name using current date and time Date startTime = new Date(); def cur_Time = startTime.getMonth() + 1 + "_" + startTime.getDate() + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds() def fileName = it.name + "_" + cur_Time def path = "/Users/tester/Documents/test/" def apiFile = new File(path + fileName + ".json") apiFile.write("\n\n"); apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("rawRequest").value) apiFile.append("\n\n"); apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("Response").value) apiFile.append("\n\n"); } testRunner.gotoStep(0) } That code loops through rows of data I use for my JSON request then it creates a new file which SHOULD save each unique request and response. Can you please give me a suggestion on how to do this correctly? How do I make a groovy assertion that also saves the request/response? EDIT: Rao, I just tried this (added it as an assertion to my POST request) but the results are the same. The script creates one file with one response. //Check if there is response assert context.request, "Request is empty or null" //Save the contents to a file def saveToFile(file, content) { if (!file.parentFile.exists()) { file.parentFile.mkdirs() log.info "Directory did not exist, created" } file.write(content) assert file.exists(), "${file.name} not created" } def f = new File("/Users/tester/Documents/test/testfile.json") saveToFile(f, context.response)2KViews0likes2CommentsHow do I record each request and response within the same test step?
Hello everyone. I have spent hours searching the internet for a solution to my problem but was not able to find anything... so hopefully you can help me. I have a simple test case with 2 steps: 1. POST (JSON to a REST API 2. Groovy script that reads a text file: nextLine = context.fileReader.readLine() if(nextLine != null){ String[] propData = nextLine.split("\\,") curTC = testRunner.testCase curTC.setPropertyValue("systemId",propData[0]) curTC.setPropertyValue("partnerId",propData[1]) curTC.setPropertyValue("honorificPrefix",propData[2]) curTC.setPropertyValue("first",propData[3]) curTC.setPropertyValue("middle",propData[4]) curTC.setPropertyValue("last",propData[5]) testRunner.gotoStep(0) } I also have the properties setup in the setup script. Anyway, this part is working but how do I record each request and response to a file? I was able to do this BUT it only saves the last request and response, instead of every request and response as per the data in the text file that it reads. This is the script I tried that creates a new file and saves the request and response: //Define the object for the collection of requests in the soapUI test case def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) //Groovy Script to loop through each requests in the test case. soapuiRequests.each{ //Creating file name using current date and time Date startTime = new Date(); def cur_Time = startTime.getMonth() + 1 + "_" + startTime.getDate() + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds() def fileName = it.name + "_" + cur_Time def path = "/Users/name/Documents/folder/" def apiFile = new File(path + fileName + ".json") apiFile.write("\n\n"); apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("rawRequest").value) apiFile.append("\n\n"); apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("Response").value) apiFile.append("\n\n"); }2.1KViews0likes6CommentsHow do I start a REST project but with XML in the request? Is this possible?
Our API only accepts XML in the request. I have been using the Chrome REST client plugin to test this but would love to switch to using READYAPI again. How do I create a new project using XML?Solved9 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.4KViews0likes1CommentREST testing: Connection Refused when connected to VPN
Not using any proxies. No other special configurations in the properties file (ie IPv4 setting). Requests work fine when not on VPN (problem is I need VPN in order to connect to certain servers). I'm using v4.5.1. Here is a snippet of the error I'm getting: Thu Aug 09 16:28:28 PDT 2012:ERROR:java.net.SocketException: Permission denied: connect java.net.SocketException: Permission denied: connect Please help!12 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.4KViews0likes1Comment${#project#endpoint} does not work in script assertion
Using Script Assertion.. how come this code works: import com.eviware.soapui.support.XmlHolder def holder = new XmlHolder( messageExchange.responseContentAsXml ) holder.namespaces["ns1"] = "http://www.example.com/examplepage.htm" def node = ( holder["//ns1:Response[1]/ns1:RESPONSE[1]"] ) assert node != null ...but this does not? import com.eviware.soapui.support.XmlHolder def holder = new XmlHolder( messageExchange.responseContentAsXml ) holder.namespaces["ns1"] = '${#Project#endpoint}/examplepage.htm' def node = ( holder["//ns1:Response[1]/ns1:RESPONSE[1]"] ) assert node != null Everywhere else (so far) I am able to use '${#Project#endpoint} without a problem. The second example above returns null. Thanks!13 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.4KViews0likes2Comments