Karate中拼接静态与动态字符串时引号异常的解决咨询
Karate字符串拼接时变量自动加引号的解决办法
问题代码
def result = google * print 'the domain name is:', result * def url1 = 'https://'+result+'.com' * print url1
执行输出
the domain is google HTTPS:\"google\".com
问题:尝试将动态变量拼接至字符串时,变量前后被自动添加了引号,如何消除这一异常?
解决方法
问题根源在于变量定义步骤:def result = google 里的google未被引号包裹,Karate会将其识别为变量引用而非字符串字面量,后续拼接时就会自动带上引号。
只需给google添加单引号,将其定义为字符串即可:
def result = 'google' * print 'the domain name is:', result * def url1 = 'https://' + result + '.com' * print url1
修改后输出
the domain name is: google https://google.com
拼接后的字符串就不会出现多余引号了。
内容的提问来源于stack exchange,提问作者anandyita sinha
相关产品推荐
相关产品推荐

