首页 > 解决方案 > 空手道测试 - 在“匹配每个”中进行“或”匹配的任何方式?

问题描述

我有以下类似的东西。是否有可能让空手道为fooand进行“或”匹配bar

含义 -foofooStartWithCharORbar开头barStartWithChar

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

标签: karateweb-api-testing

解决方案


有时普通的旧 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(_)'

推荐阅读