如何在javascript中使用karate.match

问题描述 投票:0回答:1

假设以下场景:

 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 中的某些值。

karate
1个回答
0
投票

以下解决方案对我有用

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
© www.soinside.com 2019 - 2024. All rights reserved.