ScriptView > ManualView > ScriptView

@ThanhTo @duyluong This has been a bug since forever. It’s well documented here somewhere, but here’s what I saw just now…

Switching between Manual View and Script view can trash your script. Manual View tries to format the code and sometimes gets it horribly wrong. I just tried it again now, because it’s been so long since I went in there – and puff! A half dozen lines managed to survive while the other 50+ lines were trashed. Thankfully I had a backup.

Here’s a minimal STR:

Create a simplistic script.

import something
import something_else

class my_class {

  my_class() {
    println("my_class")
  }
} 

try {
  new my_class() 
} catch(Exception e) {
  println(e.message)
}

Visit Manual View.
Add a custom keyword (I used the first one in the list).
Return to Script View.
Bang.

import something as something
import something_else as something_else
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable

try {
    new my_class()
}
catch (Exception e) {
    println(e.message)
} 

CustomKeywords.'com.kms.katalon.keyword.applitools.BasicKeywords.checkElement'(null, null)

What just happened?

It deleted the class my_class.
(And added way too many unnecessary imports).

Interesting.

I think one basic aspect here is the way, you use the test case scripting mode. As far as I understand Katalon Studio, it’s not meant to be used like that. The scripting mode should not contain class definitions or anything that is not well representable in the manual mode, right? It should only have content that can be represented in a line wise manner that fits to the manual mode (i.e. there is a representation of the script in the manual view, as it is the case with your try-catch phrase). The rest of the script should go to the keyword nodes. At least this is how I experience these two test modes (scripting and manual) to work well together.

Let’s not forget: The test cases are meant to be used by manual testers supported by developers - at least this is the total nature of Katalon Studio, right? If you want to do massive scripting without the support of test engineers working with the manual mode, you would be well advised to go straight for a core selenium project or maybe a tool that wraps selenium for developers nicely, like Ranorex Webtestit, for example.

But of course, you did report something that should be viewed as a bug. Katalon Studio should definitely not mess with script content, but give out a clear warning if script content is not compatible with the manual mode.

It’s Groovy. It should work.

A script is a script-class. A class can contain a class. End of story.

Nope. That’s your baggage, not how Katalon/Groovy works.

I don’t know what that is.

You’re restricting how it can be used when you say that.

Yeah, this is a pretty serious bug, and I think there have been other reports of it floating around, where people mysteriously lose data without any apparent cause. It’s good you were able to find a reproduceable scenario for it.

I’ve always suspected that Katalon generates scripts using reflection, and that’s why, for each script you write, Katalon generates a “.tc” file as well as a “Script0123456789.groovy” file. Not sure if that’s actually what’s happening behind the scenes, just a guess, but I wouldn’t be surprised if the bug lives within this process.

1 Like

katalon-tree
Please see that image. This is the Katalon tree in version 8.0.5. It has a “Keywords” and a “Test Cases” node. I think, you are basically right by reporting this bug, but I wonder why you would create a class under the test cases node, when you could also create it under the keywords node, where it makes so much more sense (at least to me :wink: ).

1 Like

Gee. Thanks.

“Why” questions can lead to turtles, all the way down. So, with the proviso we stick with the topmost turtle and leave it at that…

OO > POM > DRY.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.