Neither triple single quotes nor triple double quotes work as expected in Groovy code for Test Cases

## Operating System: Windows 10

## Katalon Studio Version: <= 5.8.6

## Katalon Studio logs: not relevant

**## Environment (for Web testing): **not relevant

**## Environment (for Mobile testing): **not relevant

## Steps to reproduce

Normally, the Groovy language standard supports multiline strings by using tripple single quotes (see here) and triple double quotes (see here). Therefore I like to use this technique to formulate my database queries in the code for test cases clearly, like this:

def sqLiteString1 = sqLite.execute(new String('''
   UPDATE myTable
      SET
         foo = null;
'''))def String $table = 'myTable'
def sqLiteString2 = sqLite.execute(new String("""
   DELETE FROM $table
      WHERE
         foo = false;
"""))

I know I should try to make the complexity of the Test Cases more lean and instead outsource such code to Custom Keywords methods. But at the beginning of a new development I still work very exploratively and don’t want to deal with the certainly very important questions of code abstraction yet, which is why I edit all new code parts within one script.

## Expected Behavior

Even after I switched to the manual view to further edit the test case there (e.g. I add a new test step), the above code should still be accepted and processed by Katalon Studio as it stands, since it conforms to the Groovy language standard.

## Actual Behavior

But when I return to the script view afterwards, my above multiline strings are incorrectly corrected as follows:

def sqLiteString1 = sqLite.execute(new String('\n\tUPDATE myTable\n\t\tSET\n\t\t\tfoo = null;\n'))
def String $table = 'myTable'
def sqLiteString2 = sqLite.execute(new String("
   DELETE FROM $table
      WHERE
         foo = false;
"))

That is, the text content between the tripple single quotes has been converted to a single line, marked by single single quotes. And in the other case the triple double quotes were also converted to single double quotes, but the line breaks remained, which of course leads to script errors, which I have to correct manually in the code afterwards.

Both are not viable solutions. I suspect it won’t be easy to translate such multi-line strings into the manual view (and back again), but it certainly isn’t impossible, is it?

Please find a way, these multiline strings are simply too useful for me to do without them. Many thanks in advance!

**## Screenshots / Videos: **unnecessary

4 Likes

Triple quotes certainly do work, I use them a lot.

Try not using them inside a call to create a new instance of the String class… something like this:

String sql = '''
 UPDATE myTable 
   SET foo = null;
'''
sqLite.execute(sql)

Hi Russ,

I can not double-check that at the moment (on my private computer at home), but I think you’re wrong. :wink: As far as I know, you don’t use the Manual View at all and that’s probably the only reason why you haven’t encountered this problem yet, isn’t it? It really only occurs after you have made changes to the test case in the Manual View and then return to the Script View.

I got used to the syntax with ‘new String()’ because otherwise the Groovy sqLite driver doesn’t seem to be able to parse a variable within triple double quotes, as used in the second example above. And even if I could avoid this by splitting the declaration code to some prior lines, why should this also Groovy-compliant notation cause Katalon Studio to manipulate the string in this inconvenient way? In addition, at least when converting strings with triple double quotes, the result is also definitely erroneous, as shown above.

Ah, okay, the dreaded Manual View. Yeah, that’s a bug. Either it’s valid groovy or it isn’t. When it is valid and it doesn’t work, that’s a bug. Period.

Sorry for not paying closer attention. :*

I got used to the syntax with ‘new String()’ because otherwise the
Groovy sqLite driver doesn’t seem to be able to parse a variable within
triple double quotes, as used in the second example above.

For me looks ok using triple double quotes with groovy sql driver, variable substitution works just fine.

( i am doing it as Russ suggested, first i build the query variable than execute the statement)

You can use the ${variable} form, is more readable IMHO (although $variable works also well, I have tried both)

As for the bug with Manual View … yeah, I’ve been hit few times by the bug you mention and i stopped using it :smiley:

@Russ Thomas: No problem and thanks for the confirmation. :slight_smile:

@11075-Ibus:

For me looks ok using triple double quotes with groovy sql driver, variable substitution works just fine.

( i am doing it as Russ suggested, first i build the query variable than execute the statement)

Your parenthesis addition contains exactly the crucial difference to my notation: I don’t want to waste an additional line for declaring the string. Therefore in my case the string is not parsed in advance, but should be interpreted together with the given variable directly by the sqLite driver, which it cannot do. - Therefore the additional nesting in a ‘new String()’ statement. But this is actually off-topic here, because it concerns this external driver and not the bug in Katalon Studio I described above. :slight_smile:

well, to make my life even more complicated, I wrote a custom keyword for making the sql connection / query.

Sometime, more is less :stuck_out_tongue:

That’s exactly what I think is a pity, because I find the comfort of actually being able to switch back and forth between Script and Manual View for editing very ingenious and I haven’t found it in any other, even expensive testing software yet.

@11075-Ibus: Wouldn’t you like to upvote my change request?

Drunda Nibel

which one?

agreed, jumping between manual and script view is a bit messy and i think i already up-voted an existing feature-request/bug on this matter

as for you being a stubborn and using over-complicated code lines instead of just using a nice groovy script style syntax … well, not my style

Where is my bug report about style issues?

I was referring exactly to the fact that switching between Script and Manual mode for multiline strings leads to errors/unpleasant reformatting. This fact is completely independent of my ‘new String()’ syntax, no matter if you criticize it rightly or not. But be it so …

i don’t know why do you ask where is your bug report … since you created, you should be the one knowing the relevant link …

If you find it, sure, I will up-vote it too, since indeed, is annoying …

My bad … *this* is in bug section … ok, upvoted!

Sorry, my expression may have been ambiguous. English is not my native language. :wink: I didn’t want to ask where my bug report is, but where in my (above) bug report I was dealing with style issues. :wink:

Thanks for upvoting.

English is not my native language.

Really? You surprised me.

Drunda Nibel said:

Sorry, my expression may have been ambiguous.

that’s ok. i had a bad day too yesterday :slight_smile: