I’ve got a test suite collection, that contains multiple test suites. One of the test suites calls a test case with parameters, using Variable Binding. It’s one variable, defined as Script Variable and its type is a List of strings.
Running the test suite works fine, the test case gets called with the parameter, a list of strings.
Running the test suite collection fails when entering the parameterized test case:
Test Cases/Algemeen/Verwijder openstaande workflows FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during semantic analysis: String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1931)
at org.codehaus.groovy.runtime.MetaClassHelper.capitalize(MetaClassHelper.java:464)
at org.codehaus.groovy.control.StaticImportVisitor.getAccessorName(StaticImportVisitor.java:488)
at org.codehaus.groovy.control.StaticImportVisitor.findStaticFieldOrPropAccessorImportFromModule(StaticImportVisitor.java:368)
Suites – and most certainly Suite Collections – have their challenges. What we need is something like “universal variables” tied to the Katalon execution start point and available until all execution stops. Right now, there is nothing built in to the system that provides that “out of the box”.
However, there are ways of accomplishing something similar using other, manual means. But first…
How are you passing the variables right now? It’s not clear from your description. Can you provide code/screenshots showing the setup?
Aside: I’ll assume for now you’re not using parallel execution in the collection. That would make things much more complicated.
Thanks Russ! I don’t get why we would need ‘universal variables’. I know global variables are tied to a test suite and in my case, the test suite has the parameters hardcoded configured for the child test case.
This is the test suite collection, configured to run sequential. I’m aiming at parallel execution in the near future though.
Okay, that’s not what I imagined - thanks for clarifying. Sounds buggy, to me. I’ll move this thread. In the meantime, let’s see what the devs have to say. @ThanhTo@duyluong
Universal Variables:
To ensure that all executions have access to data at the time they need it, some people (including me) resort to outside storage. I keep a json file with start up values stored there. Typically, these are copied to GlobalVariables (if needed) and hence usable anywhere. Something new, “universal variables”, could provide that out of the box. I’ve forgotten the details of the gotcha that this addressed, something to do with a disconnect between the default profile, custom profiles, and suites? It was a scope issue of some kind. I guess I used my solution and never looked back.
2020-10-10 13:33:31.689 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-10-10 13:33:31.690 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2020-10-10 13:33:31.710 INFO c.k.katalon.core.main.TestCaseExecutor - variable = [eins, zwei, drei]
2020-10-10 13:33:31.944 DEBUG testcase.New Test Case - 1: println(variable)
[eins, zwei, drei]
2020-10-10 13:33:31.949 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
However, side note:
If you would expect the execution to iterate over the list you defined, it won’t happen. The testcase is executed only once, as shown in console output. The variable printed is a list.
If this is what you intend to achieve, all fine up to now (at least for me)
If you need to iterate over the testdata values, you have to create a testdata instead (internal data, excel, whatever) see the next example:
Now, when i execute the collection, the test case is running three times:
2020-10-10 13:47:23.560 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-10-10 13:47:23.560 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2020-10-10 13:47:23.582 INFO c.k.katalon.core.main.TestCaseExecutor - variable = eins
2020-10-10 13:47:23.818 DEBUG testcase.New Test Case - 1: println(variable)
eins
2020-10-10 13:47:23.825 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
2020-10-10 13:47:23.847 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-10-10 13:47:23.847 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2020-10-10 13:47:23.860 INFO c.k.katalon.core.main.TestCaseExecutor - variable = zwei
2020-10-10 13:47:23.862 DEBUG testcase.New Test Case - 1: println(variable)
zwei
2020-10-10 13:47:23.866 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
2020-10-10 13:47:23.886 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-10-10 13:47:23.886 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2020-10-10 13:47:23.897 INFO c.k.katalon.core.main.TestCaseExecutor - variable = drei
2020-10-10 13:47:23.900 DEBUG testcase.New Test Case - 1: println(variable)
drei
2020-10-10 13:47:23.903 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
@Michiel_van_Erp
I noticed that in your setup, the variable at testcase level is an empty list (no default value).
Mine was a string, with a default value.
So i made a new experiment similar with yours, just to be sure:
2020-10-10 15:24:08.547 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-10-10 15:24:08.547 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2020-10-10 15:24:08.570 INFO c.k.katalon.core.main.TestCaseExecutor - variable = [drei, zwei, eins]
2020-10-10 15:24:08.784 DEBUG testcase.New Test Case - 1: println(variable)
[drei, zwei, eins]
2020-10-10 15:24:08.791 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
Thanks @anon46315158 for trying to reproduce this error.
Some strange things happened. The test suite itself now started giving the same error as well.
Looking into the test case code - as you mentioned - and disabling the lines that worked with the test case parameter solved the error.
I initially had a for-loop that apparently later on was auto-optimized to these lines, where workflowsToCancel is the test case parameter:
for (def item : workflowsToCancel) {
workflowsToCancelAsString += “”$item","
}
Refactoring it into something else, made the error go away:
@anon46315158 haha, think so? I noiticed switching between script and manual had an effect on the coding layout sometimes, but didn’t know it could mess up my code. I’ll keep my eyes open … thanks again for the help!
It happens, though rarely. And, it is known to mess with string/GString constructs (exactly where your problem occurred). The complaints are on the forum somewhere. There’s a reason I moved this discussion to bug reports.
@ThanhTo for the main topic, it is not a katalon issue, for some reason the code of the OP got messed …
could be because of switching from manual to script view but for that behavior for sure there are other open topics (i’ve been hit too few times)
or take the full java approach, to avoid issues with parens.
not sure if quotes are needed inside that string too, that will be another source for headaches.
If quotes are needed inside the resulting string, the easiest solution will be to use escaping.
Even better, the entire loop can be avoided by using .join()
so we cannot say 100 % it is a bug in katalon, but more like an undesired effect, most probably the code rendering engine is confused in certain condition, particularly when coding styles are mixed.