I am new to scala and Gatling.
When Gatling does a check for a status 200 I want to include a variable onlineID into the logs so that I know which user had an issue.
object MyRequests{
val getAddressForOnlineId = feed(Configuration.csvFeeder)
.exec(
http("Abfrage von Adressdaten")
.get(Configuration.baseUrl + "/myrequest/${myonlineID}" )
.headers(Configuration.globalHeaders)
.check(status.is(200))
)
How can I do this?
Save the status in your check with saveAs and then in an exec(function) block, extract the status and myonlineID values from the Session and print into your own file or slf4j logger when status is not 200.
I recommend you have a look at the official documentation and Gatling Academy.
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 have a pretty simple scenario to get a random value from a CSV file that contains only one column with header id. Then, I want to paste this value into a body of a POST request. An example of the body of my request looks as follows:
{ "id" : "123" }. So, instead of "123", I need to use a value from a CSV file. Here are my feeder and scenario:
val csvFeeder = csv("src/test/resources/ID.csv").random
val scn = scenario("Test POST request")
.feed(csvFeeder)
.exec(http("Test POST request")
.post(uri)
.header("Content-type", "application/json")
.body(StringBody("{\"id\":\"$id\"}"))
.check(status is 200, responseTimeInMillis lte 2000)
)
This example is the closest implementation I managed to make so far. But it doesn't work as I expect. I can't paste the value from a feeder into $id that is inside a body(). Currently, Gatling sends the following body: {"id":"$id"}
How can I retrieve a value from a feeder and paste it into a body string request?
Found the solution. The code is right. The issue was in the version of artifact I was using. I used version 3.0.0-RC3 of gatling-charts-highcharts, gatling-core & gatling-http and gatling-maven-plugin was 3.0.0. Now I switched to 2.3.1 for gatling-* dependencies and used 2.2.4 for maven plugin. Now it works.
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.
A Gatling scenario with an exec chain. After a request, returned data is saved. Later it's processed and depending on the processing result, it should either fail or pass the test.
This seems like the simplest possible scenario, yet I can't find any reliable info how to fail a test from within an exec block. assert breaks the scenario and seemingly Gatling (as in: the exception throw doesn't just fail the test).
Example:
// The scenario consists of a single test with two exec creating the execChain
val scn = scenario("MyAwesomeScenario").exec(reportableTest(
// Send the request
exec(http("127.0.0.1/Request").get(requestUrl).check(status.is(200)).check(bodyString.saveAs("MyData")
// Process the data
.exec(session => {
assert(processData(session.attributes("MyData")) == true, "Invalid data");
})
))
Above the scenario somewhere along the line "guardian failed, shutting down system".
Now this seems a useful, often-used thing to do - I'm possibly missing something simple. How to do it?
You have to abide by Gatling APIs.
With checks, you don't "fail" the test, but the request. If you're looking for failing the whole test, you should have a look at the Assertions API and the Jenkins plugin.
You can only perform a Check at the request site, not later. One of the very good reasons is that if you store the bodyString in the Sessions like you're doing, you'll end using a lot of memory and maybe crashing (still referenced, so not garbage collectable). You have to perform your processData in the check, typically in the transform optional step.
were you looking for something like
.exec(http("getRequest")
.get("/request/123")
.headers(headers)
.check(status.is(200))
.check(jsonPath("$.request_id").is("123")))
Since the edit queue is already full.
This is already resolved in the new version of Gatling. Release 3.4.0
They added
exitHereIf
exitHereIf("${myBoolean}")
exitHereIf(session => true)
Make the user exit the scenario from this point if the condition holds. Condition parameter is an Expression[Boolean].
I implemented something using exitHereIfFailed that sounds like exactly what you were trying to accomplish. I normally use this after a virtual user attempts to sign in.
exitHereIfFailed is used this way
val scn = scenario("MyAwesomeScenario")
.exec(http("Get data from endpoint 1")
.get(request1Url)
.check(status.is(200))
.check(bodyString.saveAs("MyData"))
.check(processData(session.attributes("MyData")).is(true)))
.exitHereIfFailed // If we weren't able to get the data, don't continue
.exec(http("Send the data to endpoint 2")
.post(request2Url)
.body(StringBody("${MyData}"))
This scenario will abort gracefully at exitHereIfFailed if any of the checks prior to exitHereIfFailed have failed.
My tests run fine but now I need multiple sessions running at once. I've tried getting the cookie value using headerRegex("Set-Cookie", "HOME_SESSID=(.*)").saveAs("homeSessid") but when I print this out its returning a value of com.excilys.ebi.gatling.http.check.HttpMultipleCheckBuilder#6075598
I have no idea where this is coming from. My question is: what is going on?
Thanks.
edit: forgot to mention that the value its returning is not a session id and no matter what I use for the cookie name I get the same value.
edit (solution):
1) In the first .exec: .check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )
2) Then to retrieve homeSessid in later http requests I did, for example:
.post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )
1) In the first .exec:
.check( headerRegex("Set-Cookie", """HOME_SESSID=(.*dll/(\d+))""").saveAs("homeSessid") )
2) Then to retrieve homeSessid in later http requests I did, for example:
.post( session=>{session}.getAttribute("homeSessid").toString + "/some/relative/url" )
Please properly read the Check documentation. Checks save data into the Session, so that's where you have to read. Here, you're just trying to print the extractor.
For example, after performing your check, you could add a exec(function), like:
.exec(session => {
println(session("homeSessid").as[String]) // Gatling 2 API
session
})