I am currently working on a script with requirement
For example :
Total number of users 5( should be like using 1 user credentials in 5 different browser sessions )
API 1 call should be executed only by User 1
API 2, 3 & 4 should be executed by all users 1-5
API 5 should be executed only by last user 5
- No multiple scenarios allowed, all the requests should be handled under only one scenario.
Here is the code sample.
val testUrl: String = "https://test.com"
val username: String = "testAdmin"
val password: String = "testadmin"
val nbUsers: Integer = 5
val testCount: Integer = Integer.getInteger("test-count", 3000)
val testIterationCount: Integer = Integer.getInteger("test-iteration-count", 20)
val userId = nbUsers.toInt
val httpProtocol: HttpProtocolBuilder = http
.baseUrl(testUrl + "/rest/2.0/")
.disableCaching
val scn: ScenarioBuilder = scenario("delete_huge_dataset")
.doIfEquals(session => session.userId, 1) {
exec(http("Add test main directory")
.post("/maindirectory")
.body(StringBody(session => s"""{ "name": "Perfmaindirectory${Random.alphanumeric.take(5).mkString}" }""")).asJson
.check(jsonPath("$.id").saveAs("maindirectoryId")))
}
.repeat(testIterationCount.toInt){
exec { session =>
val testtypeids = Array("000000001", "000001", "000001101", "00000000001")
val statusID = Array("000008", "0000058", "00000000-00019", "00000000-0009")
val PerfIDs = session("maindirectoryId").as[String] **// creating data inside maindirectory**
val testData = (1 to testCount)
.map { r =>
Json.toJson(Map(
"name" -> Json.toJson(s"Perftest${Random.alphanumeric.take(6).mkString}"),
"displayName" -> Json.toJson(s"Perftest${Random.alphanumeric.take(6).mkString}"),
"PerfIDs" -> Json.toJson(s"${PerfIDs}"),
"testtypeids" -> Json.toJson(s"${Random.shuffle(testtypeids.toList).head}"),
"statusId" -> Json.toJson(s"${Random.shuffle(statusID.toList).head}"),
"excludedFromAutoHyperlinking" -> Json.toJson(true)
))
}
val datatestJson = Json.toJson(testData)
session.set("datatestJson", datatestJson)
}
.exec(http("Add json data holding 3000 data set")
.post("test/bulk")
.body(StringBody(session => s"""${session("datatestJson").as[String]}""")).asJson
.requestTimeout(2.hours)
.check(jsonPath("$[*].id").findAll.saveAs("testIDs"))
.check(status.is(201)))
.pause(2.seconds)
.foreach("#{testIDs}", "TestID") {
exec(http("update 3000 data individually in loop * 100 repeat loop")
.post("updating/testdata")
.body(StringBody(session =>
s"""{
| "id": "",
| "additionalTypeId": "000000001",
| "legs": [
| {
| "additionalTypeId2": "00000000112311",
| "testID": "${session("TestID").as[String]}"
| }
| ]
| }""".stripMargin)).asJson
.check(jsonPath("$.id").saveAs("newtestID"))
.check(status.is(201)))
}
.doIfEquals(session => session.userId, 5) {
exec(http("Delete main directory holding 300000 data set")
.delete(session => s"domains/${session("maindirectoryId").as[String]}")
.requestTimeout(2.hours)
.check(status.is(204)))
}
setUp(scn.inject(atOnceUsers(nbUsers)))
.protocols(httpProtocol);
}
when I execute non of the script block is getting executed.
Please help me with solutions.