Cannot use “==” and “contains” in same line of scenario using conditional logic in Karate

前端 未结 1 661
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 13:46

This is a follow up of a question noted here

Lets says our implemented server v1 and v2 response looks as follows

v1Response = { id: \"1\", name: \"a         


        
相关标签:
1条回答
  • 2020-12-21 14:41

    For some reason you feel that hacking the match clause is the only way to solve this problem. Please keep an open mind and, here you go:

    * def schemas =
    """
    {
      v1: { id: "#string", name: "#string" },
      v2: { id: "#string", name: "#string", value: "#string" }
    }
    """
    
    * def env = 'v1'
    * def response = { id: "1", name: "awesome" }
    * match response == schemas[env]
    
    * def env = 'v2'
    * def response = { id: "2", name: "awesome", value: "karate" }
    * match response == schemas[env]
    
    * def response = { id: "1", name: "awesome" }
    * match response == karate.filterKeys(schemas[env], response)
    

    The last line is as generic as you can get.

    0 讨论(0)
提交回复
热议问题