scala - Gatling - 无法解析为正确的 Uri,缺少方案
问题描述
我有基本的 Gatling 脚本,我尝试在其中登录应用程序,仅此而已。
出于某种原因,我得到了错误:
j.l.IllegalArgumentException: "https://my-site.com/"login could not be parsed into a proper Uri, missing scheme
在我看来,它已附加在 baseUrl 引号的末尾。
这是我的模拟课:
package simulations.stage
import io.ecx.steps.{Config, Login}
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class RampUsersLoadSimulations extends Simulation{
val httpConf = http.baseUrl(Config.baseUrl)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36")
.inferHtmlResources()
.acceptEncodingHeader("gzip, deflate, br")
before {
println(s"Running for: ${Config.baseUrl}")
}
val login = scenario("Scenario: Login to the storefront")
.exec(Login.login(Config.accounts))
setUp(
login.inject(
nothingFor(5 seconds),
atOnceUsers(Config.userCount),
rampUsers(Config.userCount) during(Config.rampDuration seconds)
).protocols(httpConf)
).maxDuration(Config.testDuration seconds)
}
这是我的登录步骤实现:
package io.ecx.steps
import io.gatling.core.Predef._
import io.gatling.http.Predef._
object Login {
def login(accountsPath: String) = {
val accounts = csv(accountsPath).random
feed(accounts)
.exec(http("Open login page")
.get("login")
.check(status.is(200)))
.pause(2)
.exec(http("Log in with credentials to the storefront")
.post("j_spring_security_check")
.formParam("email", "${username}")
.formParam("password", "${password}"))
.pause(5)
}
}
这是我的配置步骤实现:
package io.ecx.steps
import com.typesafe.config.ConfigFactory
object Config {
private def getProperty(propertyName: String, defaultValue: String) = {
Option(System.getenv(propertyName))
.orElse(Option(System.getProperty(propertyName)))
.getOrElse(defaultValue)
}
def userCount: Int = getProperty("USERS", "5").toInt
def rampDuration: Int = getProperty("RAMP_DURATION", "10").toInt
def testDuration: Int = getProperty("DURATION", "12").toInt
def environment:String = getProperty("ENVIRONMENT", "STAGE")
val conf = ConfigFactory.load()
val accounts = conf.getString("accounts")
val baseUrl = if (environment == "STAGE") conf.getString("baseUrlStage") else conf.getString("baseUrlProd")
}
在我的属性文件中,我有:
#COMMON
accounts=data/stage/accounts.csv
#STAGE
baseUrlStage="https://my-site.com/"
#PROD
baseUrlProd="TBD"
有人可以帮忙吗:)
谢谢!
解决方案
错误是明确的:"https://my-site.com/"login
无法解析为正确的 Uri,缺少方案。
实际上,您的属性文件中的值已损坏。
而不是baseUrlStage="https://my-site.com/"
,你应该有baseUrlStage=https://my-site.com/
。
推荐阅读
- gradle - 如何将自定义独立插件中的 build.gradle 属性应用于应用该插件的项目
- oracle - PLSQL 过程循环给出意外结果
- python - PyVista TypeError:SetSpacing 参数
- java - 内容提供者权限问题?
- php - 在 laravel 中获取用户帖子计数
- swift - 没有双引号的 Swift Post 请求参数
- java - 为什么在使用通配符参数化类型的泛型类型时必须添加显式转换?
- facebook - Facebook Messenger API 消息附件示例不起作用
- linux - 用于将日期字符串转换为特定时间戳格式的 Shell 脚本
- java - 模拟方法实现 Junit mockito