Passing in data

I just found Gatling yesterday after using a paid tool and or Soap/Load UI for awhile.

My development skills are kinda low but I can read and understand … enough.

Hoping you all can help me. To get the key I need for my calls I need to call a service and save it’s full response as a variable to use as part of the header for the other endpoints.
What am I doing wrong here? The response for the key generator is only composed of the key.

val usersDataSource = csv(“domains.csv”)

val scn = scenario(“Testing”)
.feed(usersDataSource)
.exec(http(“Get API Key”)
.post("/login")
.body("""{“username”: “ausername”, “password”: “apassword”, “domain”: “${domain}”}""").asJSON
.check(regex(.))
.saveAs(“apiKey”)

.pause(222 milliseconds)
.exec(http(“cEndpoint”)
.get("/cendpoint")
.header(“aKey”, “${apiKey}”)
.queryParam("""_""", “”“1402401310313"”")

Thanks!

The problem may be with the “check(regex(.))” … that will probably match a single character.
If your apiKey is more than 1 character long, well, that regex will not work.

Try regex(.*) … presuming that is there is no other text other than apiKey in the response.

Thanks… I’m getting this error. Am I calling it wrong?

19:14:41.678 [ERROR] c.e.e.g.a.ZincCompiler$ - D:\Users\w.chung\Desktop\Gatling\user-files\simulations\API\APICalls.scala:36: illegal start of simple expression
19:14:41.685 [ERROR] c.e.e.g.a.ZincCompiler$ -.check(regex(.*))
19:14:41.687 [ERROR] c.e.e.g.a.ZincCompiler$ - ^
19:14:41.688 [ERROR] c.e.e.g.a.ZincCompiler$ - D:\Users\w.chung\Desktop\Gatling\user-files\simulations\API\APICalls.scala:137: ‘)’ expected but ‘}’ found.
19:14:41.689 [ERROR] c.e.e.g.a.ZincCompiler$ - }
19:14:41.689 [ERROR] c.e.e.g.a.ZincCompiler$ - ^
19:14:41.724 [ERROR] c.e.e.g.a.ZincCompiler$ - two errors found

I only use jsonPath, not regex. I had to look it up - is the main gatling.io page link to documentation not live?

Anyway, you should first check the mailing list archives first … that’s how I learn.

The following post will show you how to use regex correctly.
https://groups.google.com/forum/#!searchin/gatling/check%28regex/gatling/GaCZDvbo-tE/wfk6KbWszO4J

Is there any other way to just throw the whole return body into a variable? Everything between the { } in the return is what i’m trying to capture. Or am i doing this totally the wrong way?

When I take this out it compiles fine… putting it in gives me the errors

.exec(http(“Get API Key”)
.post("/login")
.body("""{“username”: “ausername”, “password”: “apassword”, “domain”: “${domain}”}""").asJSON
.check(regex(.*).saveAs(“apiKey”))

This is the error

What you pass to regex is not a valid String => double quotes!!!
regex(".*")

Thanks!!! I actually figured it out yesterday late nite and forgot to post :slight_smile: I was too concentrated on getting the regex right which i didn’t know much about :expressionless:

Now i’m getting this <<<<<<<<<<<<<<<<<<<<<<<<<
00:20:20.530 [WARN ] c.e.e.g.c.s.ELParser$ - Couldn’t resolve EL ${apiKey}

Am I saving it the wrong way?

Access-Control-Allow-Credentials: true

Access-Control-Allow-Headers: X-Requested-With,content-type, Key,accept

Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE

Content-Length: 216

Content-Type: text/html; charset=utf-8

Server: nginx/1.4.7

X-Powered-By: Express

BODY
vBOHpOGlxZmft5uQc/dUuVkwOZnroVpuGyRbULoDK+J9MYEgfE+8e0+fMgt8mQj02j28NvDc5jBmEeX/PI2Ke3kQWvH1qDbVN0gD/SDqJfHRhnUaChR8UvwQI2TXqwz6ZT1YF9dnb70ZminZXaBGFLxHeJe7i/OgdNY1JeScLJwYd1W7C1DN9P/LJt7Bc8YySto+/wtFY4b0lSdqCK0blw==

Your first request, “Get API Key”, failed (maybe because it returned a bad status code), so “apiKey” wasn’t saved.