Translating a ChainBuilder

82 views
Skip to first unread message

Robert Bacon

unread,
Oct 19, 2017, 1:57:55 PM10/19/17
to Gatling User Group
Ok, so odd question and situation.

I have a function that returns a ChainBuilder and a String.  I then assign each of these to a variable.  Then when I try to display them on the screen, the script compiles and it appears they are in the correct data type, but the string comes out as a ChainBuilder. 

Does anyone know why this might happen, and how to fix it so that the String is displayed as the String I'm expecting?

Thanks for all of your help.

Rob

enterprise.software.janitor

unread,
Oct 23, 2017, 8:26:53 AM10/23/17
to Gatling User Group
Please post your sample code and the output!

Robert Bacon

unread,
Oct 24, 2017, 12:09:57 PM10/24/17
to Gatling User Group
 Thanks for the reply,

Here is the sample code for the method:


object BasicLogin {

def login ( hostparam:String, controlparam:String, usernameparam:String, passwordparam:String) : (ChainBuilder, String) = {
 
      val user = usernameparam
     

      val password = passwordparam
     

      val host = hostparam
      val controlid = controlparam
      val logintype = "user"
     
     
 
      val jsonrequest = """{"logintype":"""" + logintype + """",
            "controlid":"""" + controlid + """",
            "user":"""" + user + """",
            "password":"""" + password + """",
            "host":"""" + host + """"
            }"""
           

      val loginChain = exec(http("Login")
          .post("sample.url.com")
          .body(StringBody(jsonrequest))
          .asJSON
          .check(jsonPath("$..result").is("true"))
          .check(jsonPath("$..session")
          .find
          .saveAs("currentSession")))
       
        val accessToken: String = exec(session => {
           val sessionid = session("currentSession").as[String]
           println("token: " + sessionid)
           session })  
           .toString

       
        return (loginChain, accessToken)
    }
}

Here is my code calling the method for login:

  val host = "IPaddress"
  val controlid = "IDcontroller"
  val username = "JDoe"
  val password = "TerriblePassword"
    
  val result = BasicLogin.login(host, controlid, username, password)
  val basiclogin:ChainBuilder = result._1
  val currentSession:String = result._2

  println("Session: " + currentSession)
  println("Login: " + basiclogin)


And here is what I get in response:

Session: ChainBuilder(List(io.gatling.core.action.builder.SessionHookBuilder@6f70f32f))
Login: ChainBuilder(List(io.gatling.http.action.sync.HttpRequestActionBuilder@3dd69f5a))


I do want to note that the println("token " + sessionID) does not get returned to the screen.  Any idea what it is I am missing here?

Thanks for the help,

Rob

enterprise.software.janitor

unread,
Oct 25, 2017, 2:26:29 PM10/25/17
to Gatling User Group
I'm curious why would you write something like this to see the value of the session? Right now it's printing the string representation of the action builder object rather than the actual value of your token.

You can very easily enable debug logging to watch session parameters as opposed to passing this variable around and printing them all over the place. Go to resources->logback.xml and uncomment the debug log to watch your session. I hope you are only doing this locally or for testing. Don't enable debug when running actual test.

If you still want to use the code as is, you should change your login method return statement from accessToken to the actual session value that you assign to val from session.


Good luck. 


--ESJ

Robert Bacon

unread,
Oct 26, 2017, 11:42:56 AM10/26/17
to Gatling User Group
Thanks for the reply ESJ.

You are correct, I am only doing this for testing.  The session will not be displayed once I have the test finished in coding.  I had it display just because I wanted to see if the value of accessToken is being passed to currentSession.  This is important because then in future functionality tests, I may need to pass the session token using currentSession as a parameter in a method.  My problem is that I have not been successful in getting the value of accessToken to be passed to currentSession

As for the return statement, are you suggesting I return sessionid instead of accessToken?  If this is the case, I have attempted to do something similar to this by trying to return currentSession from the loginChain val, using several different methods (i.e. currentSession, $currentSession, "${currentSession}", ${currentSession}) which none of those worked.  I will try returning sessionid as I think you are suggesting, but if I misunderstood, please let me know.  I will report back with how it went.

Thanks for your help!

Rob

Robert Bacon

unread,
Oct 26, 2017, 11:47:37 AM10/26/17
to Gatling User Group
So the response I got from returning sessionid is the same as with all of the currentSession attempts.  "value not found".

Any ideas as to what I'm missing?


Rob

On Wednesday, October 25, 2017 at 2:26:29 PM UTC-4, enterprise.software.janitor wrote:
On Wednesday, October 25, 2017 at 2:26:29 PM UTC-4, enterprise.software.janitor wrote:
On Wednesday, October 25, 2017 at 2:26:29 PM UTC-4, enterprise.software.janitor wrote:
On Wednesday, October 25, 2017 at 2:26:29 PM UTC-4, enterprise.software.janitor wrote:

Robert Bacon

unread,
Oct 31, 2017, 12:50:30 PM10/31/17
to Gatling User Group
Any ideas?
Reply all
Reply to author
Forward
0 new messages