如何在加特林脚本中添加Status = KO? [英] How to add Status = KO in Gatling script?

查看:122
本文介绍了如何在加特林脚本中添加Status = KO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使我的请求失败? 我想将Status = KO放在asLongAs()部分中.我的情况是,如果我得到WorkflowFailed = TrueCount > 8,那么我想使用Status = KO失败该请求.

Is it possible to fail my request? I would like to put Status = KO in asLongAs() section. My condition is like, if I get WorkflowFailed = True or Count > 8 then I want to fail that request using Status = KO.

我在session.markAsFailed的某个地方见过,但是如何以及在何处使用它?

I have seen somewhere about session.markAsFailed but how and where to use this?

谢谢.

这是代码,

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 count = new java.util.concurrent.atomic.AtomicInteger(0)

    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")))

        }


     .asLongAs(session => session.attributes("WorkflowStatus") != "false" && count.getAndIncrement() < 8) {
        doIf(session => session("WorkflowFailed").validate[String].map(WorkflowFailed => !WorkflowFailed.contains("true")).recover(true)) 
        {
        pause(pauseTime)
        .exec(http("SaveWorkflowStatus")
                .get("""/api/actions/${WorkflowID}""")
                .headers(headers_0)
                .check(jsonPath("$.running").saveAs("WorkflowStatus"))
                .check(jsonPath("$.failed").saveAs("WorkflowFailed")))

        .exec(session => {
                val wflowStatus1 = session.get("WorkflowStatus").asOption[String]
                val wflowFailed1 = session.get("WorkflowFailed").asOption[String]
                println("Inner Loop Workflow Status: ========>>>>>>>> " + wflowStatus1.getOrElse("COULD NOT FIND STATUS"))
                println("Inner Loop Workflow Failed?? ========>>>>>>>> " + wflowFailed1.getOrElse("COULD NOT FIND STATUS"))
                println("Count =====>> " + count)
                session}) 

        }
        }   

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

推荐答案

会话中有可用的方法

exec(session => session.markAsFailed)

这篇关于如何在加特林脚本中添加Status = KO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆