I am trying to parameterize a checkbox. But its giving an error

I am new to katalon . I am trying to click a checkbox by comparing values i gave in a excel sheet. For now only compairing row 1.

Calling above groovy method ifrom a test case:

excel - using the last two columns for this particular method:-image

I am getting below error everytime i try to execute it.

@sahame1989

I sincerely hope you’re not suffering from the same Groovy bug I encountered recently.

Since you are passing integers, then comparing with integers, first try altering the keyword to use int:

def clickValidCheckboxes(int isLicensed, int permission_req) { ... ```

@ThanhTo @devalex88 I think you know why I’m calling you in. Looks similar - at least the error. But shouldn’t the boxing (auto-casting/coercion) work here?

Hi @sahame1989

Can you try to add a static keyword before the function annotated with @keyword to see if it resolves the issue ? I will try to reproduce this as you’ve provided a rather generic method. Thanks for that !

@Russ_Thomas I have a hunch that the “staticness” plays a role in eradicating this error.

For now, the only consistent workaround I can think of is to strive for code as statically typed as Java as possible. Meaning you should write

int isLicensed = findTestData("....").getValue("isLicense",1);
int permissin_req = findTestData("....").getValue("permission_req", 1);
CustomKeywords.`yourMethod`(isLicensed, permission_req);
1 Like

I tried many things but nothing has worked. I discovered that i needed to declare the variables and I did the same. But I was still getting a type cast error. i used the valueOf{} to parse the excel input from last two columns. but it still doesn’t work.


There are a number of issues with your code that you should fix before we move on to discussing issues with its purpose.

This for example image means the compiler will not be able to resolve the token you provided. It has no idea what Name is since it isn’t found in the current scope.

In this code: image
you have declared isLicensed twice; once as an argument to the method, then again as a variable local to the method. And the same again with permission_req.

In the same block of code, valueOf is an issue. I have no idea what that is, nor will the compiler since once again, it can’t be found. It looks as though you’re trying to invoke a closure - but I’m not sure.

The code given to you by @ThanhTo is close to what you need – but it’s hard to say for certain. You must understand, we can’t see everything - we can only see what you provide to us.

@sahame1989

As Katalon API document shows

findTestData(...).getValue(columnName, 1)

this code returns a String, not an integer.

(You may wonder why, because in Excel, a cell value 1 looks to be a Number, not a String. But, the fact is, TestData#getValue() method always returns a value in String type in Groovy such as “0” and “1”.)

So, if you want to compare the returned String with integers like

if (isLicensed == 1) ...

then, you need to parse the returned String value into integer explicitly.

The following snippet would show you an example:

package admin

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

public class CreateProduct {

    static def clickValidCheckboxes(String licenseValue, String permissionValue) {
        Objects.requireNonNull(licenseValue, "licenseValue must not be null")
        Objects.requireNonNull(permissionValue, "permissionValue must not be null")
		
        // Java way of parsing String into int
        //int isLicensed = Integer.parseInt(licenseValue)
        //int permissionReq = Integer.parseInt(permissionValue)
		
        // Groovy way of parsing String into int
        int isLicensed = licenseValue as int
        int permissionReq = permissionValue as int
		
        if (isLicensed == 1 && permissionReq == 1) {
            WebUI.comment("case1: isLicensed=${isLicensed}, permissionReq=${permissionReq}")
        } else if (isLicensed == 1 && permissionReq == 0) {
            WebUI.comment("case2: isLicensed=${isLicensed}, permissionReq=${permissionReq}")
        } else if (isLicensed == 0 && permissionReq == 1) {
            WebUI.comment("case3: isLicensed=${isLicensed}, permissionReq=${permissionReq}")
        } else if (isLicensed == 0 && permissionReq == 0) {
            WebUI.comment("case4: isLicensed=${isLicensed}, permissionReq=${permissionReq}")
        } else {
            WebUI.comment("?????: isLicensed=${isLicensed}, permissionReq=${permissionReq}")
        }
    }
}

Or, even simpler way would be to compare a String with a String such as “0” and “1”.

Your Excel data has a typo at the cell D1:
isLiscensed --> isLicensed

This would confuse yourself.