假设以下场景:
Scenario: check if the array contains a string
* def condition =
"""
function(){
var myFile = "computer3.jpg"
var getAttachment = ["computer3.jpg"]
var isFound = karate.match(getAttachment + " contains " + myFile)
karate.log("is Found", isFound)
return isFound.pass
}
"""
* def r = call condition
我有以下错误:
ReferenceError: "computer3" is not defined
如何使用 karate.match 检查数组是否包含 javascript 中的某些值。
以下解决方案对我有用
Scenario: prova 2
* def condition =
"""
function(){
var myFile = "computer3.jpg"
var getAttachment = ["computer3.jpg"]
var temp = "['" + getAttachment+ "'] contains '" + myFile+"'"
var isFound = karate.match(temp)
karate.log("is Found:", isFound)
return isFound.pass
}
"""
* def r = call condition