【问题标题】:Jmeter Groovy searching for folder and block path in a fileJmeter Groovy 在文件中搜索文件夹和块路径
【发布时间】:2018-06-15 06:57:21
【问题描述】:

我正在使用 JSR223 断言,我试图在文件中找到这两行的位置,如果没有收到则断言。

  <BlockPath>XYZ\abc\a1\abc</BlockPath>
  <FolderPath>XYZ\abc\a1</FolderPath>

我试过了:

int pos1 = tstStr.indexOf("<BlockPath>XYZ\abc\a1\abc</BlockPath>");
int pos2 = tstStr.indexOf("<FolderPath>XYZ\abc\a1</FolderPath>");

我收到了这个错误

Assertion failure message: javax.script.ScriptException: 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script32.groovy: 7: unexpected char: '\' @ line 7, column 50.
ted.indexOf("<BlockPath>XYZ\abc\a1\ab

我需要从字面上寻找那两条线并获得它们的位置。确保不是 -1 或它们存在于文件中。我该怎么做?

【问题讨论】:

    标签: groovy jmeter


    【解决方案1】:

    在 Groovy 中,您需要使用另一个反斜杠来转义反斜杠,因此您需要修改您的代码,例如:

    int pos1 = tstStr.indexOf("<BlockPath>XYZ\\abc\\a1\\abc</BlockPath>");
    int pos2 = tstStr.indexOf("<FolderPath>XYZ\\abc\\a1</FolderPath>");
    

    演示:


    您的回复似乎是基于XML,因此您可以考虑使用XPath Assertion,它允许使用XPath query 语言断言响应数据,因此您将能够检查以下元素的存在:

    //BlockPath
    

    //FolderPath
    

    查看How to Use JMeter Assertions in Three Easy Steps 文章了解更多信息。

    【讨论】:

    • 谢谢你其实我已经尝试过反斜杠,即使数据存在它也找不到它。 int pos1 = tstStr.indexOf("XYZ\\abc\\a1\\abc"); int pos2 = tstStr.indexOf("XYZ\\abc\\a1");
    猜你喜欢
    • 2012-06-17
    • 2017-09-02
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    相关资源
    最近更新 更多