【问题标题】:Gatling configure base url in configuration fileGatling 在配置文件中配置基本 url
【发布时间】:2015-06-05 19:29:50
【问题描述】:

我想在配置文件中配置我的加特林模拟的基本 url。这样我就可以轻松地在测试系统和实时系统之间切换。

当我在 Simulation-scala 文件中配置它时,我工作得很好:

val httpConf = http
        .baseURL("http://computer-database.herokuapp.com")

如果我删除上面的行并在 config (gatling.conf) 文件中配置它:

gatling {
   http {
     baseUrls = "http://localhost8080/baserate"
     ...

我收到以下错误,我的方案不起作用,因为基本 url 为空。

09:57:26.352 [ERROR] i.g.c.c.GatlingConfiguration$ - Your gatling.conf file is outdated, some properties have been renamed or removed.
Please update (check gatling.conf in Gatling bundle, or gatling-defaults.conf in gatling-core jar).
Enabled obsolete properties:'gatling.http.baseUrls' was removed, use HttpProtocol.

在当前版本的 gatling 中是否仍然可以在

之外配置基本 url

我的版本是 gatling-maven-plugin:2.1.2。

【问题讨论】:

    标签: scala maven gatling


    【解决方案1】:

    您还可以创建一个单例对象并将其公开在任何加特林模拟类中。

    想象一下在 Configuration.scala 中有一个名为 Configuration 的单例对象,如下所示:

    object Configuration {
      val BaseUrl = "http://www.dummyurl.com"
    }
    

    这应该会减少模拟类中的代码

    import io.gatling.core.Predef._
    import io.gatling.http.Predef._
    import scala.concurrent.duration._
    
    class MySimulation extends Simulation {
    
      val HttpConf = http
        .baseURL(Configuration.BaseUrl)
    
      ...
    }
    

    如果需要,只需解析包定义和导入,

    注意:由于 val 表示不可变属性,我们应该用第一个大写字母命名它

    【讨论】:

    • 您甚至可以先从系统属性中获取基本 URL:val BaseUrl = System.getProperty("baseURL", "http://www.dummyurl.com")
    【解决方案2】:

    我通过在 /test/resources/ 中创建一个 application.properties 文件解决了这个问题

    baseUrl=http://www.example.com
    

    我这样改变了我的模拟:

    import com.typesafe.config._
    class BasicSimulation extends Simulation {
       val conf = ConfigFactory.load()
       val baseUrl = conf.getString("baseUrl")
       val httpConf = http.baseURL(baseUrl)
    

    【讨论】:

    • 这是外部化脚本变量的推荐方法。谢谢!
    【解决方案3】:

    您可以通过各种方式(系统属性、环境变量、自定义配置文件...)自行配置,但这不再是 Gatling 内置的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 2013-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多