1

I am using session.userId to parametrize my test requests like this:

exec(http("get request")
  .get((s:Session) => "somebaseUrl/" + s.userId.toString ))

Is it possible to get sesion userId differently, so my request addresses are more DRY, eg I won't have to use lambda?

I tried using gatling DSL:

exec(http("get request")
  .get("somebaseUrl/${userId}")

but then I get: No attribute named 'userId' is defined error

I could just calculate some random id to my tests, but why when gatling already does this.

Only solution that I came up with is saving userId to some different attribute like this:

exec((s:Session) => s.set("user_id",s.userId)),
exec(http("test").get("${user_id}"))

but that doesn't seem right, and you have to make sure to call the set before all other requests.

cvakiitho
  • 1,377
  • 13
  • 27

2 Answers2

1

The userId is some internal details. Gatling Expression language only exposes Session attributes, ie the attributes Map content.

Either use the first way you described, with a function, or don't use Gatling internals and set your own UUID attribute (feeder, exec(function), etc).

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
  • bare with me, as I'm scala/gatling noob :). I probably could save lambdas to variable, and call them right? what should I pass to that variable as a parameter though? Same applies to function, I can extract lamdas to function, I have no idea what to pass to them. I mean how to get a session instance. In docs, there is `val session: Session = ???` which doesn't help either :) http://gatling.io/docs/2.1.7/session/session_api.html#id2 – cvakiitho Jan 15 '16 at 13:58
  • If you don't know how to write a function in Scala, get a look at a Scala tutorial then: http://gatling.io/docs/2.1.7/quickstart.html#a-word-on-scala – Stephane Landelle Jan 15 '16 at 15:04
  • I know how to write a scala function, I don't know, how to pass an argument with session in gatling. I mean, what is actually passing current session to a lambda in for example .get((s:Session) => "something" +s.userId)). And how to pass the session as argument to normal function. – cvakiitho Jan 25 '16 at 13:22
  • This makes me think you don't understand what a function is: some piece of code that you can pass as a parameter so that it's invoked elsewhere. What actually invokes those functions in Gatling is an implementation detail and not a user concern. – Stephane Landelle Jan 25 '16 at 13:28
  • It is possible, and also probable, that I'm thinking wrong about this. Or cannot express it correctly. But I want a simple thing, have a function that does exactly what this lamda does `(s:Session) => s.userId.toString` - in my mind that means - take given session s, and return its userId string. I know how to write a function that does this `def returnUID(s:Session): String = s.userId.toString`, I just have no idea, how to pass a session to it. As I have no idea, how the lamda is called. – cvakiitho Jan 25 '16 at 13:38
  • 1
    No offense, but you indeed look like you're missing some fundamental concepts understanding. I suspect you're trying to skip the initial learning phase and think like you're used to in procedural language. Take a few hours to go through a Scala tutorial, such as Twitter's Scala School. `def` is not a function, it's a method. But it can be automatically lifted: http://stackoverflow.com/questions/17965059/what-is-lifting-in-scala. – Stephane Landelle Jan 25 '16 at 13:57
  • Twitter's Scala School - basics: `Functions You can create functions with def.` .. Yeah I'll probably need to go deeper. Thanks for your time. – cvakiitho Jan 25 '16 at 14:07
1

To avoid using gatling internals you could use a feeder:

var userId = 0
feed(Iterator.continually(Map("userId" -> {
      userId += 1
      userId}.toString)))
ben
  • 58
  • 5