在Karate DSL中,如何在java参数调用中传递变量时转义单引号 [英] in Karate DSL, how do you escape single quotes when passing a variable within a java argument call
问题描述
我正在尝试添加对数据库的调用,作为API项目正在进行的端到端工作的一部分。如何在断言方法中作为参数传递的变量中转义单引号。我尝试过以下内容并没有奏效。
I'm trying to add making calls to a database as part of an end to end effort with the API project at work. How would I escape single quotes within a variable that is being passed as an argument within an assert method. I have tried the following and it did not work.
- 断言JavaClass.executeSQLQuery('SELECT COUNT(*)作为结果从PartType WHERE reference ='evaluate';','1') == true
错误是它无法评估值中的单引号
ERROR is that it cannot evaluate the single quotes within the value
其他尝试
-
def sqlQuery =
def sqlQuery =
SELECT COUNT(*)As Result
FROM PartType
WHERE reference ='updateerferencee';
""" SELECT COUNT(*) As Result FROM PartType WHERE reference = 'updateerferencee'; """
- 断言JavaMethods.executeSQLQuery(sqlQuery,'1')== true
错误:见附件
推荐答案
通过我的新手编程技巧,我意识到我试图调用一个被评估为javascript和whol的java方法这件事被烘焙成了空手道迷你语言(这让我感到困惑)。答案已经过测试并在下面工作。
Through my novice programming skills, I realized I was trying to call a java method that is being evaluated as javascript and the whole thing is baked into the Karate mini-language (which confused the s*** out of me). Answer has been tested and working below.
断言JavaClass.executeSQLQuery('SELECT COUNT(*)作为结果从PartType WHERE reference = \'evaluate \';','1')== true
assert JavaClass.executeSQLQuery('SELECT COUNT(*) As Result FROM PartType WHERE reference = \'evaluate\';', '1') == true
这篇关于在Karate DSL中,如何在java参数调用中传递变量时转义单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!