in Karate DSL, how do you escape single quotes when passing a variable within a java argument call

岁酱吖の 提交于 2019-12-08 05:00:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!