I’m trying to make this work:
`
object Login {
val sequence =
feed( Config.USER_FEED )
.group( “Login” ) {
.exec()
.expect_302_REDIRECT_TO( LOGIN_URL,
http( “1) Main URL” )
.get( Path.root )
)
.expect_200_OK(
http( “2) Login Page” )
.get( $(LOGIN_URL) )
.check( css( “”“input[name=“session”]”"", “value” ).saveAs( SESSION_ID ) )
)
.expect_302_REDIRECT(
http( “3) Submit Credentials” )
.post( $(LOGIN_URL) )
.headers( Headers.formPost )
.formParam( “session”, $(SESSION_ID) )
.formParam( “username”, $(USER_NAME) )
.formParam( “password”, $(PASSWORD) )
.formParam( “action”, “Login” )
)
…
`
Here’s what I’m doing to implement it:
`
object SessionConstant {
def $( s : String ) = { “${” + s + “}” }
// debug
val REQUEST_URI = “REQUEST_URI”
val RESPONSE_STATUS = “RESPONSE_STATUS”
val RESPONSE_BODY = “RESPONSE_BODY”
// Redirect
val REDIRECT_TO = “REDIRECT_TO”
// …
}
`
`
import io.gatling.core.Predef._
import io.gatling.core.structure.ChainBuilder
import io.gatling.http.Predef._
import io.gatling.http.request.builder.HttpRequestBuilder
import io.gatling.http.request.builder.HttpRequestWithParamsBuilder
import SessionConstant._
object Expect {
def debugExtracts ( request : Any ) =
if ( request.isInstanceOf[HttpRequestBuilder] ) request.asInstanceOf[HttpRequestBuilder]
else request.asInstanceOf[HttpRequestWithParamsBuilder]
.check( status.saveAs( RESPONSE_STATUS ) )
.check( header(“Location”).optional.saveAs( REDIRECT_TO ) )
.check( currentLocation.saveAs( REQUEST_URI ) )
.check( bodyString.saveAs( RESPONSE_BODY ) )
implicit class ChainBuilderExtensions ( val c : ChainBuilder ) {
def expect_200_OK ( request : Any ) =
c.exec( debugExtracts( request ).check( status.is( 200 ) ) )
.doIf( session => session( RESPONSE_STATUS ).as[Int] != 200 ) { exec( DEBUG.lastRequest _ ) }
.exitHereIfFailed
def expect_302_REDIRECT ( request : Any ) =
c.exec( debugExtracts( request ).check( status.is( 302 ) ) )
.doIf( session => session( RESPONSE_STATUS ).as[Int] != 302 ) { exec( DEBUG.lastRequest _ ) }
.exitHereIfFailed
def expect_302_REDIRECT_TO ( name : String, request : Any ) =
expect_302_REDIRECT( request )
.exec( session => session.set( name, session( REDIRECT_TO ) ) )
}
}
`
It compiles and runs. But when it gets to the .doIf() block it complains that RESPONSE_STATUS does not exist, implying that debugExtracts() did not properly add the check to save the status. Any thoughts as to why it is not working? Or suggestions on the “right” way of doing this?
Thanks!