Gatling测试模块化
Modularisation of Gatling test
好的,我对此很陌生,之前我只做过 JMeter 和 Selenium 测试。由于后者,我想稍微模块化我的测试。但出于某种原因,每次尝试从不同页面放置 val 时,我都会收到 "Cannot resolve overloaded method 'exec'"。现在这就是它的样子。在我看来,所有的包都是正确的,此外,当我简单地将 loginPage.scala 的内容复制到 baseScenario 中时,它一切正常。可能是我没有完全理解 Scala 是如何工作的,因为我的主要经验是基于 Java
baseScenario.scala
package tscgatling.base
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import tscgatling.loginPage._
class baseScenario extends Simulation{
val urlBase = "xx"
val httpProtocol = http
.baseUrl(urlBase)
.acceptHeader("image/webp,image/apng,image/*,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36")
val loginNoAction = exec(loginPage.loginNoAction)
val scn = scenario("Test")
.exec(loginPage.loginNoAction)
setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}
loginPage.scala
package tscgatling.loginPage
object loginPage {
val loginNoAction = exec(http("LoginNoAction")
.get("/workplace/faces/portlets/pages/portletlogin.xhtml")
.headers(loginHeaders.headers_12))
.pause(1)
}
loginHeaders.scala
package tscgatling.loginPage
object loginHeaders {
val headers_12 = Map(
"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Proxy-Connection" -> "keep-alive",
"Upgrade-Insecure-Requests" -> "1")
}
作为 explained in the official documentation,您应该在每个要使用 Gatling DSL 的文件中导入 Predef。
好的,我对此很陌生,之前我只做过 JMeter 和 Selenium 测试。由于后者,我想稍微模块化我的测试。但出于某种原因,每次尝试从不同页面放置 val 时,我都会收到 "Cannot resolve overloaded method 'exec'"。现在这就是它的样子。在我看来,所有的包都是正确的,此外,当我简单地将 loginPage.scala 的内容复制到 baseScenario 中时,它一切正常。可能是我没有完全理解 Scala 是如何工作的,因为我的主要经验是基于 Java
baseScenario.scala
package tscgatling.base
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import tscgatling.loginPage._
class baseScenario extends Simulation{
val urlBase = "xx"
val httpProtocol = http
.baseUrl(urlBase)
.acceptHeader("image/webp,image/apng,image/*,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36")
val loginNoAction = exec(loginPage.loginNoAction)
val scn = scenario("Test")
.exec(loginPage.loginNoAction)
setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}
loginPage.scala
package tscgatling.loginPage
object loginPage {
val loginNoAction = exec(http("LoginNoAction")
.get("/workplace/faces/portlets/pages/portletlogin.xhtml")
.headers(loginHeaders.headers_12))
.pause(1)
}
loginHeaders.scala
package tscgatling.loginPage
object loginHeaders {
val headers_12 = Map(
"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Proxy-Connection" -> "keep-alive",
"Upgrade-Insecure-Requests" -> "1")
}
作为 explained in the official documentation,您应该在每个要使用 Gatling DSL 的文件中导入 Predef。