Class defined in script keeps disappearing

For one of my tests, I have defined a helper class called DiscountData defined as such:

`
class DiscountData {
private String name, type, operator, value;

public DiscountData() {

}

public DiscountData(name, type, operator, value) {
this.name = name;
this.type = type;
this.operator = operator;
this.value = value;
}

public String getName() {
return this.name;
}

public String getType() {
return this.type;
}

public String getOperator() {
return this.operator;
}

public String getValue() {
return this.value;
}

// setters
}
`

The use case of this class is as follows: right before any data-entry steps, I construct an instance of it with a row of data from the Test Data. I then use the object to fill in the fields.

This worked, up until I started adding test steps from the UI. When that happened, and I went back to Script mode, my class definition was gone and attempt to run the test case gave me this error:

`

Test Cases/AddValidDiscountsByType has ERROR(s) because (of) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/mwarren/Katalon%20Studio/TestProject/Scripts/AddValidDiscountsByType/Script1529682315911.groovy: 65: unable to resolve class DiscountData
@ line 65, column 18.
DiscountData testData = new DiscountData(data.getValue(‘Name’, index), discountType, data.getValue(‘Operator’, index),

`

How do I solve this?

Hello,

do you have proper import row for your class in the test?

Marek Melocik said:

Hello,

do you have proper import row for your class in the test?

What is “proper import row”?

It’s able to read from the Test Data just fine, it’s just that my class keeps disappearing from the Groovy Script.

I think it’s possible that you are switching to editing the script, then using Manual View, then editing the script… and so on…

There are definitely issues when doing that. Stick to Script view. It’s more “direct” and easier.

I meant import row such as

import com.yourpackage.DiscountData 

The error is saying that test script cannot find your class.

Michael Warren said:

Marek Melocik said:

Hello,

do you have proper import row for your class in the test?

What is “proper import row”?

I think you’re defining your class in the Test Case itself, in which case, you don’t need to “import” anything.

Marek is suggesting your class is defined in a keyword file, in which case it would need to be imported.

If you want to keep your class in your test case file, DO NOT use manual view for editing.

I strongly advise you to create a keyword class and import it “properly”.

1 Like