I am very new to SoapUI, and need some help,
I want to test multiple SOAP requests - just kind of smoke test and save result in text file along with error message of failed response.
I have created testcase with all SOAP request and used invalid HTTP assertion to validate pass/fail one [as mentioned just smoke test] and wirting result in to txt file using tear down script.
I have created Custom properties for each SOAP request and using property transfer step fetched Error message & reporting entity.
Now my concern is, how to write those property values in txt file along with result.
I am using below mentioned teardown script to store result.
`import org.codehaus.groovy.scriptom.*
import org.codehaus.groovy.scriptom.tlb.office.excel.*
def testsuitename=testRunner.testCase.testSuite.name
def testcasename=testRunner.testCase.name
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def results = testRunner.results
f = new File( "C:\\Users\\%user%\\Documents\\Downloads\\Smoke Test Result\\result.txt")
for( r in testRunner.results )
{
f.append(r.testStep.name + "," + r.status + "\r\n")
}`
Output is something like this:
step-1-name,FAILED
step-2-name,OK
step-3-name,OK
I am looking for output with error message
step-1-name,FAILED,Error message,Reporting Entity
step-2-name,OK,null,null
step-3-name,OK,null,null
I have already fetched Error message & entity using XPATH in properties.
Related
The test below checks the performance of a graphql endpoint. A CSV file of id's is fed into the test. When run, about 1% of the requests fail because the endpoint returns an error for some of the id's fed in. But, the message returned from graphql is not very descriptive, so I have no idea which id's actually failed. I'd like to be able to add a step to the test which logs the request body and response for all the failed requests.
I could enable the debug log but this will log everything. I'm only interested in logging the requests which fail. Is it possible to add something like a on failure step which would let me log out the request body and response so that I know which id's failed?
class Test extends CommonSimulation {
val graphqlQuery: String =
"""
|{"query":"{person(personId:\"${id}\")}"}
|""".stripMargin
val gqsPerson: ScenarioBuilder = scenario("Service Test")
.feed(csv(Data.getPath + "id.csv").random)
.exec(http("My test")
.post("https://localhost:4000/graphql")
.body(StringBody(graphqlQuery)).asJson
.check(jsonPath("$.errors").notExists)
.headers(headers)
)
setUp(
authToken.inject(atOnceUsers(1))
.andThen(
gqsPerson.inject(constantConcurrentUsers(1) during 1)
))
}
Please have a look at the documentation: https://gatling.io/docs/gatling/guides/debugging/#logback
I'm currently trying to mock external server using Wiremock.
One of my external server endpoint takes a payload.
This endpoint is defined as follow :
def sendRequestToMockServer(payload: String) = {
for {
request_entity <- Marshal(payload).to[RequestEntity]
response <- Http().singleRequest(
HttpRequest(
method = HttpMethods.GET,
uri = "http://localhost:9090/login",
entity = request_entity
)
)
} yield {
response
}
}
To mock this endpoint using Wiremock, I have written the following code :
stubFor(
get(urlEqualTo("/login"))
.willReturn(
aResponse()
.withHeader("Content-Type","application/json")
.withBodyFile("wireMockResponse.json")
.withStatus(200)
)
.withRequestBody(matchingJsonPath("requestBody.json"))
)
where I Have defined the request body in the requestBody.json file.
But when I run tests , I keep getting an error indicating that the requested Url is not found.
I'm thinking that the error is related to this line withRequestBody(matchingJsonPath("requestBody.json")), because when I comment it the error disappear.
Any suggestions on how to work around this?
matchingJsonPath does not populate a file at a provided filepath, but instead evaluates the JsonPath provided. See documentation.
I'm not entirely sure there is a way to provide the request body as a .json file. If you copy the contents of the file into the withRequest(equalToJson(_yourJsonHere_)), does it work? If it does, you could get the file contents as a JSON string above the definition and provide it to the function (or I guess, make a function to return a JSON string from a .json file).
Additionally, you could make a custom request matcher that does the parsing for you. I think I'd recommend this only if the above does not work.
I have a REST API project in SOAP UI which contains 20 test cases in a test suite. I want to add some header value and sslkeystore in every test step. Here is my code.
import com.eviware.soapui.support.types.StringToStringMap
testCaseList = testSuite.getTestCases()
testCaseList.each
{
testCase = testSuite.getTestCaseByName(it.key)
restTestSteps = testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)//only RestTestRequest steps
restTestSteps.each
{
it.getRestRequest().setHttpHeader("TEST2")
it.testRequest.setSslKeystore("**************")
}
}
Above code "TEST2" contains the header value that I want to add to every test cases. I have configured TEST2 in ws-security configuration under outgoing ws-security configuration.
But in above code I am getting following error:
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.getRestRequest() is applicable for argument types: () values: [] Possible solutions: getTestRequest(), getHttpRequest()
Anybody help me please how can I add header value in every test steps.
If you want to set the header values for each step in a test case, you can create a groovy test step that will do this. Place the groovy step at the beginning of the test case and it will work even if you change or add new steps. I'm sure you could tweak the getAllHttpSteps to include all test cases in the suite as well, and place this as the first test run.
/**
* This script populates all http requests in a test case with headers:
*/
import com.eviware.soapui.support.types.StringToStringMap
// make a list of all http rest requests
getAllHttpSteps=testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)
// iterate through the list of requests and populate the request headers
for (step in getAllHttpSteps)
{
def headers = new StringToStringMap()
headers.put("SomeHeader", "SomeHeaderValue")
headers.put("sslKeystore", "keystoreValue")
}
If you want to add header value and sslkeystore in every test step, then add these values as Properties OR Custom Properties in Project. Then assign these values in each step. Are you willing to do this with groovy script?
I'm newbie to soap and soapui, I'm trying to create a test case in which I will send the same request(XML attachment) many times(about 500), the problem is that each time I need to increment/change a value in the request (the id).
Therefore, I wonder if the is a way to pass this parameter to the attached xml file ? or if there is another ways to do the test case.
Thank you in advance
UPDATE
here is the content of the xml file :
<mod:sendMSG xmlns:mod="http://test.soap/service/model">
<id>${#Project#parameter1}</id>
<date>2016-04-03T04:03:00</date>
<infos>
<firstName>AT </firstName>
<lastName>AT </lastName>
......
</infos>
</mod:sendMSG>
which is included in the soap request, ass shown in the following image :
Test steps:
Groovy Script
SOAP Request (disabled)
I disabled the SOAP Request because it runs once more after the script has already looped the request x times.
Groovy script:
int loops = 500;
for ( iter in 1..loops ) {
//Overwrite the 'parameter1' property at project level
testRunner.testCase.testSuite.project.setPropertyValue("parameter1", iter.toString())
//log.info("iter: " + testRunner.testCase.testSuite.project.getPropertyValue("parameter1"));
// Run the teststep named 'SOAP Request'
def testStep = testRunner.testCase.testSteps['SOAP Request'];
testStep.run( testRunner, context )
}
Now you should be able to run your TestCase. I recommend saving your project before, I had some problems with SoapUI crashing on me when running.
I got this error message while trying to execute the get method.
Validation failed: Values not equal for element '$..userName', expected 'admin' but was '["admin",null,"HiCitrus","Unisys1","dscsc"]'
This is the script I have used:
http().client(todoClient)
.send()
.get("/rest/api/user/allusers")
.contentType("application/json");
http().client(todoClient)
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
// .validate(path, controlValue);
.validate("$..userName","admin");"
There are multiple parameters available for the username - is there a way to validate if I find the username "Admin"? Tried with the code below, but it's throwing an error.
.validate("$..userName",contains("admin"));