Bug with keyword Execute JavaScript


#1

There some bug with keyword Execute Javascript

I need to use in without arguments
When I try to do it for the first time and write this:

def ForAssert = WebUI.executeJavaScript(findTestData('JavaScriptHelper').getValue(1, 1), null)

After save and run test working normal, but after close test, open it again I see this

Caused by: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
	... 19 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'value' of null

Here when I open the keyword

I think this is bug, please fix it


#2

(Moved this from the Katalon Analytics category to the more appropriate Katalon Studio category.)


#3

Looking at this part of the error:

your problem actually isn’t the null argument. What’s happening is that findTestData('JavaScriptHelper') is returning null. Please make sure that you have a data file at the location you’ve specified.


#4

Also, I don’t understand your use of the WebUI.executeJavaScript() method here… Usually you use this method to do exactly that; execute some JS code, for example:

WebUI.executeJavaScript("console.log('Hello world!')", null)

Trying to execute:

findTestData('JavaScriptHelper').getValue(1, 1)

as JS code doesn’t make any sense. Unless the value you are expecting to be returned by getValue(1, 1) is a JS code snippet, which is fine, if not a little odd…


#5

If your just trying to get the value from a data file just follow this instead of using js. Not sure why you are even attempting to use JS

//get data
def data = findTestData('Data Files/DB Data')
// Get specific data (column, row) as a variable
String record = data.getValue(3, 4)
//print my variable
println record


#6

Well, findTestData returns a TestData object (interface actually). Methinks here endeth the story.

https://api-docs.katalon.com/com/kms/katalon/core/testdata/TestDataFactory.html#findTestData(java.lang.String)


#7

Right, but then he’s doing getValue(1, 1), which returns whatever is in the first cell of the Test Data as a String, which could be a JS code snippet.


#8

Which would be exceedingly…

Well, let’s leave it there :confused:


#9

I know what happen.
I write case (in data file stored JS code snippet) I need this.
I see that Execute JS need arguments, but I don’t have them, I read docs, and see that i need to write like this

WebUI.executeJavaScript("return alert("Hello world"), null)

Ok, write it, run it’s work, great
I save test case, next day open project, open test case and try to run it again. And got this error.

This works only for the first time, after save, reopen test case it not working.