以编程方式执行 Gatling 测试 [英] Programmatically execute Gatling tests

查看:80
本文介绍了以编程方式执行 Gatling 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Cucumber JVM 之类的东西来驱动为 Gatling 编写的性能测试.

I want to use something like Cucumber JVM to drive performance tests written for Gatling.

理想情况下,Cucumber 功能会以某种方式动态构建场景 - 可能重用类似于高级教程"中描述的方法的预定义链对象,例如

Ideally the Cucumber features would somehow build a scenario dynamically - probably reusing predefined chain objects similar to the method described in the "Advanced Tutorial", e.g.

val scn = scenario("Scenario Name").exec(Search.search("foo"), Browse.browse, Edit.edit("foo", "bar")

我已经查看了 Maven 插件如何执行脚本,并且我也看到提到使用 App trait 但我找不到任何关于后者的文档,这让我觉得其他人会想要在此之前...

I've looked at how the Maven plugin executes the scripts, and I've also seen mention of using an App trait but I can't find any documentation for the later and it strikes me that somebody else will have wanted to do this before...

任何人都可以(Gatling noob)指出有关如何实现这一目标的一些文档或示例代码的方向吗?

Can anybody point (a Gatling noob) in the direction of some documentation or example code of how to achieve this?

编辑 20150515

再解释一下:

我创建了一个 trait,它旨在建立一系列,我认为,由 Cucumber 步骤触发的 ChainBuilders:

I have created a trait which is intended to build up a sequence of, I think, ChainBuilders that are triggered by Cucumber steps:

trait GatlingDsl extends ScalaDsl with EN {

  private val gatlingActions = new ArrayBuffer[GatlingBehaviour]

  def withGatling(action: GatlingBehaviour): Unit = {
    gatlingActions += action
  }
}

加特林行为看起来像:

object Google {

  class Home extends GatlingBehaviour {
    def execute: ChainBuilder =
      exec(http("Google Home")
        .get("/")
      )
  }

  class Search extends GatlingBehaviour {...}

  class FindResult extends GatlingBehaviour {...}
}

在 StepDef 类中:

And inside the StepDef class:

class GoogleStepDefinitions extends GatlingDsl {

  Given( """^the Google search page is displayed$""") { () =>
    println("Loading www.google.com")
    withGatling(Home())
  }

  When( """^I search for the term "(.*)"$""") { (searchTerm: String) =>
    println("Searching for '" + searchTerm + "'...")
    withGatling(Search(searchTerm))
  }

  Then( """^"(.*)" appears in the search results$""") { (expectedResult: String) =>
    println("Found " + expectedResult)
    withGatling(FindResult(expectedResult))
  }
}

我的想法是,我可以通过以下方式执行整个动作序列:

The idea being that I can then execute the whole sequence of actions via something like:

val scn = Scenario(cucumberScenario).exec(gatlingActions)
setup(scn.inject(atOnceUsers(1)).protocols(httpConf))

然后检查报告或在测试失败时捕获异常,例如响应时间太长.

and then check the reports or catch an exception if the test fails, e.g. response time too long.

似乎无论我如何使用 'exec' 方法,它都会尝试立即在那里执行它,而不是等待场景.

It seems that no matter how I use the 'exec' method it tries to instantly execute it there and then, not waiting for the scenario.

此外,我不知道这是否是最好的方法,我们想为我们的 Gatling 测试构建一些可重用的块,这些块可以通过 Cucumber 的 Given/When/Then 风格构建.是否有更好的或现有的方法?

Also I don't know if this is the best approach to take, we'd like to build some reusable blocks for our Gatling tests that can be constructed via Cucumber's Given/When/Then style. Is there a better or already existing approach?

推荐答案

遗憾的是,目前让 Gatling 直接启动一个 Simulation 实例是不可行的.

Sadly, it's not currently feasible to have Gatling directly start a Simulation instance.

并不是说这在技术上不可行,但您只是第一个尝试这样做的人.目前Gatling通常负责编译,只能传递类名来加载,不能传递实例本身.

Not that's it's not technically feasible, but you're just the first person to try to do this. Currently, Gatling is usually in charge of compiling and can only be passed the name of the class to load, not an instance itself.

你可以先分叉 io.gatling.app.Gatlingio.gatling.core.runner.Runner,然后提供一个 PR 来支持这个新的行为.前者是主要入口点,后者可以实例化和运行模拟.

You can maybe start by forking io.gatling.app.Gatling and io.gatling.core.runner.Runner, and then provide a PR to support this new behavior. The former is the main entry point, and the latter the one can instanciate and run the simulation.

这篇关于以编程方式执行 Gatling 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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