2015-04-01 57 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