【问题标题】:Karate test - any way to do an "or" match in "match each"?空手道测试 - 在“匹配每个”中进行“或”匹配的任何方式?
【发布时间】:2020-07-04 04:27:00
【问题描述】:

我有类似以下的内容。是否有可能让空手道为foobar 进行“或”匹配?

含义 - foofooStartWithChar 开头或 barbarStartWithChar 开头

And match each response ==
    """
    {
      foo: '#? { _.charAt(0) == fooStartWithChar}',
      bar: '#? { _.charAt(0) == barStartWithChar}',
    }
    """

【问题讨论】:

    标签: karate web-api-testing


    【解决方案1】:

    有时普通的旧 JS (+Java) 是你的朋友:

    * def response = [{ foo: 'aa', bar: 'bb' }, { foo: 'ax', bar: 'by' }]
    * def isValid = function(x){ return x.foo.startsWith('a') || x.bar.startsWith('b') }
    * match each response == '#? isValid(_)'
    

    【讨论】:

      【解决方案2】:
      * def nameStartsWith = function(x) { return x.foo.charAt(0) == fooStartWithChar || x.bar.charAt(0) == barStartWithChar}
      And match each response == '#? nameStartsWith(_)'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        • 2021-04-14
        • 1970-01-01
        • 2019-04-06
        相关资源
        最近更新 更多