2015-04-01 58 views
4

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

我工作得很好,当我与它配置在仿真斯卡拉文件:

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. 

难道还要在加特林的当前版本配置

我的版本是加特林Maven的插件外侧的底部网址:2.1.2。

回答

8

我解决了这个通过创建/测试/资源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) 
+0

这是外部脚本变量推荐的方式命名。谢谢! – ChaitanyaBhatt 2016-10-07 21:56:22

1

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

3

您还可以创建一个单一对象并在任何gatling模拟课堂中公开它。

想象称为配置在Configuration.scala一个单独的对象像这样的:

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) 

    ... 
} 

如果需要的话就解决包装的定义和进口voila

注:由于VAL意味着不可改变的属性,我们应该有第一大写字母

+1

您甚至可以首先从系统属性获取基本URL:'val BaseUrl = System.getProperty(“baseURL”,“http://www.dummyurl.com”)' – 2017-12-19 13:55:13