# Put condition in HTTP request using gatling

**URL:** <https://community.gatling.io/t/put-condition-in-http-request-using-gatling/3301>\
**Category:** Gatling (Open-Source)\
**Created:** [October 4, 2016, 6:40am UTC](https://community.gatling.io/t/put-condition-in-http-request-using-gatling/3301 "2016-10-04T06:40:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)\
**Post date:** [October 4, 2016, 6:40am UTC](https://community.gatling.io/t/put-condition-in-http-request-using-gatling/3301/1 "2016-10-04T06:40:00Z")

</div>

I want to add condition on http request. like this scenario,  
using API,

1. I have one action from where I find ‘Action ID’

2. That ‘Action Id’ returns ‘true/false’ which means that action which is ‘Running/Not running’ and save it in variable

I did this this two steps, Now I want to do

**3. I have to check status on condition every 15 minutes if status is ‘true’ (Running) wait for 15 minutes, re-check status every 15 minutes if status = ‘false’ then exit oR exit after 2 Hours automatically (evenif status is ‘true’)**

Want to put condition like this,

`  
Check status = true  
{  
pause for 15minutes  
request once again after 15minutes

if(status = false)  
{  
exit  
}  
else  
{  
request once again and check status, if true wait for 15minutes  
If total waiting time is more than 2 hours then exit  
}  
}  
else  
{  
exit  
}  
`

**below is the code snippet what I did,**  
`

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import scala.concurrent.duration.\_

class LaunchResources extends Simulation {

val scenarioRepeatCount = Integer.getInteger(“scenarioRepeatCount”, 1).toInt  
val userCount = Integer.getInteger(“userCount”, 1).toInt  
val UUID = System.getProperty(“UUID”, “24d0e03”)  
val username = System.getProperty(“username”, “p1”)  
val password = System.getProperty(“password”, “P12”)  
val testServerUrl = System.getProperty(“testServerUrl”, “[https://someurl.net](https://someurl.net)”)

val httpProtocol = http  
.baseURL(testServerUrl)  
.basicAuth(username, password)  
.connection(""“keep-alive”"")  
.contentTypeHeader(""“application/vnd+json”"")

val headers\_0 = Map(  
“”“Cache-Control”"" → “”“no-cache”"",  
“”“Origin”"" → “”“chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm”"")

val scn = scenario(“LaunchAction”)  
.repeat (scenarioRepeatCount) {  
exec(http(“LaunchAResources”)  
.post( “”"/api/actions""")  
.headers(headers\_0)  
.body(StringBody(s"""{“UUID”: “$UUID”, “stringVariables” : {“externalFilePath” : “/Test.mp4”}}"""))  
.check(jsonPath("$.id").saveAs(“WorkflowID”)))

.exec(http(“SaveWorkflowStatus”)  
.get("""/api/actions/{$WorkflowID}""")  
.headers(headers\_0)  
.check(jsonPath("$.status").saveAs(“WorkflowStatus”)))

}

setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)  
}  
`

Let me know if you need more info. Thanks.

---

<div class="post-metadata">

**Author:** ![Peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@Peter](https://community.gatling.io/u/Peter)\
**Post date:** [October 4, 2016, 11:43am UTC](https://community.gatling.io/t/put-condition-in-http-request-using-gatling/3301/2 "2016-10-04T11:43:51Z")

</div>

I did like this,

```auto
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class LaunchResources extends Simulation {

    val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
    val userCount = Integer.getInteger("userCount", 1).toInt
    val UUID = System.getProperty("UUID", "24d0e03")
    val username = System.getProperty("username", "p1")
    val password = System.getProperty("password", "P12")
    val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net")

    val httpProtocol = http
        .baseURL(testServerUrl)
        .basicAuth(username, password)
        .connection("""keep-alive""")
        .contentTypeHeader("""application/vnd+json""")

    val headers_0 = Map(
        """Cache-Control""" -> """no-cache""",
        """Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")

    val scn = scenario("LaunchAction")
        .repeat (scenarioRepeatCount) {
            exec(http("LaunchAResources")
                .post( """/api/actions""")
                .headers(headers_0)
                .body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
                .check(jsonPath("$.id").saveAs("WorkflowID")))

        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/{$wflowid}""")
                .headers(headers_0)
                .check(jsonPath("$.status").saveAs("WorkflowStatus")))

        .asLongAs(session => session.attributes("WorkflowStatus") != false) {
    pause(900)
    .exec(http("SaveWorkflowStatus")
            .get("""/api/actions/${WorkflowID}""")
            .headers(headers_0)
            .check(jsonPath("$.running").saveAs("WorkflowStatus")))

    }

        }

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

```

**Now how can I check whether my action is completed or not? i mean, once it goes in asLongAs loop that action waits for 15minutes → then once again request If got status = true then exit else again request. after every 15minutes until 2hours. how to code this?**
