Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在gatling中,如何验证通过css检查提取的字符串的值?_Css_Scala_Gatling - Fatal编程技术网

在gatling中,如何验证通过css检查提取的字符串的值?

在gatling中,如何验证通过css检查提取的字符串的值?,css,scala,gatling,Css,Scala,Gatling,我正在编写一个Gatling模拟,我想验证某个元素是否存在,以及其中一个属性的内容是否以某个子字符串开头。例如: val scn: ScenarioBuilder = scenario("BasicSimulation") .exec(http("request_1") .get("/path/to/resource") .check( status.is(200), css("form#name", "action").ofType[String].startsWi

我正在编写一个Gatling模拟,我想验证某个元素是否存在,以及其中一个属性的内容是否以某个子字符串开头。例如:

val scn: ScenarioBuilder = scenario("BasicSimulation")
  .exec(http("request_1")
  .get("/path/to/resource")
  .check(
    status.is(200),
    css("form#name", "action").ofType[String].startsWith(BASE_URL).saveAs("next_url")))
现在,当我在上面添加
startsWith
时,编译器会报告一个错误,即
startsWith不是io.gatling.http.check.body.HttpBodyCssCheckBuilder[String]
的成员。如果我不使用
startsWith
,则一切正常。我知道预期的表单元素在那里,但我无法确认它的
@action
属性是否以正确的基开始

如何确认属性以某个子字符串开头?

请参阅此

我已从那里复制了以下内容,但它是一个会话功能,工作方式如下:-

doIf(session => session("myKey").as[String].startsWith("admin")) {  // executed if the session value stored in "myKey" starts with "admin"  exec(http("if true").get("..."))}

我也有同样的问题。我想一个选择是使用验证器,但我不确定如何在运行中声明一个验证器,以根据
基本URL
进行验证(文档中没有给出任何示例)。您可以使用
transform
is

可能是这样的:

css("form#name", "action").transform(_.startsWith(BASE_URL)).is(true)
css("form#name", "action").transform(_.substring(0, BASE_URL.length)).is(BASE_URL).saveAs
如果您还希望一次性包含
saveAs
调用,您可能还可以执行以下操作:

css("form#name", "action").transform(_.startsWith(BASE_URL)).is(true)
css("form#name", "action").transform(_.substring(0, BASE_URL.length)).is(BASE_URL).saveAs
但这更难理解。此外,我不确定当子字符串抛出异常(如IndexOutOfBounds)时会发生什么