ATS 2.0 Got the issue with keyword “Execute Javascript Integer”.

Hi support team, I need to make an actions to close current tab in browser window using JavaScript. In ATS script, I used the keyword “Execute Javascript Integer” and I entered the script  “window.close();”. But, currently, I am facing the below error. Could you guide me to build the script using keyword “Execute Javascript Integer” ? Execution started at 2019-08-19T09:47:08Z (local Amsterdam time) Execution stoped at 2019-08-19T09:47:08Z (local Amsterdam time) at 24: [Execute Javascript Integer]: with Script: window.close(); Execute Javascript Integer Caused by: com.mansystems.ATS.Runner.exceptions.RunnerException: at at com.mansystems.ATS.Runner.definitions.functions.FunctionImpl$ at com.mansystems.ATS.Runner.execution.ExecutionContextRoutine.execute( at com.mansystems.ATS.Runner.execution.ExecutionContextTestStep.executeRegularRoutineAndSetReturnValue( at com.mansystems.ATS.Runner.execution.ExecutionContextTestStep.execute( at com.mansystems.ATS.Runner.execution.ExecutionContextTestCase.executeTestSteps( at at java.util.concurrent.Executors$ at at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at Caused by: java.lang.NullPointerException at com.mansystems.ATS.Runner.definitions.functions.web.ExecuteJavascriptIntegerFunction.runInternal( at sun.reflect.GeneratedMethodAccessor140.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at com.mansystems.ATS.Runner.definitions.functions.FunctionReflectionHelper.invokeRunInternalMethod( at ... 12 more Best Regards, Len Nguyen
3 answers

The Execute Javascript Integer function expects your code to return, wait for it, an integer.
Just add a line to your code that returns a value and it will work.

return 0;



Thanks for your support, Andrej.

I was added this code + add timeout 5s

But, still display the error as below:

Execution started at 20 Aug 2019, 11:11:42  (local Amsterdam time)
Execution stoped at  20 Aug 2019, 11:13:28  (local Amsterdam time)
[Nhu][06. RITE Horizon CSC - Dispute]: 
	at 24: [Execute Javascript Integer]: 
	with Script: window.close();
return 0;
	with Timeout (ms): 5000

Execute Javascript Integer
Caused by: com.mansystems.ATS.Runner.exceptions.RunnerException: script timeout: result was not received in 5 seconds
  (Session info: chrome=75.0.3770.80)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: '185-44-129-55', ip: '', 'windows', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: unknown
Command duration or timeout: 0 milliseconds
	at com.mansystems.ATS.Runner.definitions.functions.FunctionImpl$”


Could you help to check it?



I am not sure why you added the timeout, ti is really not needed in this scenario. Timeout is used when you want to execute some javascript asynchronously. Synchronous execution is much simpler and should be preferred unless there is a good reason why it can not be used.
In any case when executing javascritp actions it is good to remember that they are scoped inside a function in the following way

// synchronous 
result = function (argument1, argument2 ... ) {
 // your code goes in here, when done return the result

// asynchronous
function(argument1, argument2, .., callback) {
  // your code goes in here, when done call the callback and pass the result

So in the case of asynchronous function the javascript code needs to look like this

var callback = arguments[arguments.length-1]; // callback is always the last argument
callback(1); // instead of return 1;

Again I would suggest to use the synchronous version without the timeout.


Read more about javascript execution in Selenium here –