问题
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.
- assert JavaClass.executeSQLQuery('SELECT COUNT(*) As Result FROM PartType WHERE reference = 'evaluate';', '1') == true
ERROR is that it cannot evaluate the single quotes within the value
Other Attempts
def sqlQuery =
""" SELECT COUNT(*) As Result FROM PartType WHERE reference = 'updateerferencee'; """
- assert JavaMethods.executeSQLQuery(sqlQuery, '1') == true
ERROR: See attachment
回答1:
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.
assert JavaClass.executeSQLQuery('SELECT COUNT(*) As Result FROM PartType WHERE reference = \'evaluate\';', '1') == true
来源:https://stackoverflow.com/questions/47063856/in-karate-dsl-how-do-you-escape-single-quotes-when-passing-a-variable-within-a