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

0
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 com.mansystems.ATS.Runner.definitions.functions.FunctionImpl.run(FunctionImpl.java:71) at com.mansystems.ATS.Runner.definitions.functions.FunctionImpl$1.run(FunctionImpl.java:37) at com.mansystems.ATS.Runner.execution.ExecutionContextRoutine.execute(ExecutionContextRoutine.java:170) at com.mansystems.ATS.Runner.execution.ExecutionContextTestStep.executeRegularRoutineAndSetReturnValue(ExecutionContextTestStep.java:153) at com.mansystems.ATS.Runner.execution.ExecutionContextTestStep.execute(ExecutionContextTestStep.java:128) at com.mansystems.ATS.Runner.execution.ExecutionContextTestCase.executeTestSteps(ExecutionContextTestCase.java:199) at com.mansystems.ATS.Runner.execution.ExecutionContextTestCase.run(ExecutionContextTestCase.java:156) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at com.mansystems.ATS.Runner.execution.ExtendedFuture.run(ExtendedFuture.java:100) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException at com.mansystems.ATS.Runner.definitions.functions.web.ExecuteJavascriptIntegerFunction.runInternal(ExecuteJavascriptIntegerFunction.java:22) at sun.reflect.GeneratedMethodAccessor140.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.mansystems.ATS.Runner.definitions.functions.FunctionReflectionHelper.invokeRunInternalMethod(FunctionReflectionHelper.java:29) at com.mansystems.ATS.Runner.definitions.functions.FunctionImpl.run(FunctionImpl.java:63) ... 12 more Best Regards, Len Nguyen
asked
3 answers
2

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.

window.close();
return 0;

-Andrej

answered
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: '185.44.129.55', os.name: '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.run(FunctionImpl.java:69)
	at com.mansystems.ATS.Runner.definitions.functions.FunctionImpl$1.run(FunctionImpl.java:37)”

Video: https://automate.browserstack.com/builds/f45c08eaf0b8c27ac9a003dcf702fbe14637c683/sessions/0853dbd5383b16d2adcdd6ab846a2103808c16bb

Could you help to check it?

-NhuTrieu

answered
0

Hi,
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
window.close();
callback(1); // instead of return 1;

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

-Andrej

Read more about javascript execution in Selenium here – https://www.guru99.com/execute-javascript-selenium-webdriver.html

answered