Source:
public void test_BrowserFunction_callback_with_javaReturningArray () { assumeFalse(webkit1SkipMsg(), isWebkit1); AtomicReferenceArray<Object> returnArray = new AtomicReferenceArray<>(3); class JavascriptCallback extends BrowserFunction { JavascriptCallback(Browser browser, String name) { super(browser, name); } @Override public Object function(Object[] arguments) { return new Object[] {"a String", 42, true}; } } class JavascriptCallback_javascriptReceivedJavaArray extends BrowserFunction { JavascriptCallback_javascriptReceivedJavaArray(Browser browser, String name) { super(browser, name); } @Override public Object function(Object[] arguments) { Object[] returnVal = (Object[]) arguments[0]; returnArray.set(0, returnVal[0]); returnArray.set(1, returnVal[1]); returnArray.set(2, returnVal[2]); return null; } } String htmlWithScript = "<html><head>\n" + "<script language=\"JavaScript\">\n" + "function callCustomFunction() {\n" + " document.body.style.backgroundColor = 'red'\n" + " var retVal = jsCallbackToJava()\n" + " document.write(retVal)\n" + " jsSuccess(retVal)\n" + "}" + "</script>\n" + "</head>\n" + "<body> If you see this, javascript did not receive anything from Java. This page should just be '{\"a String\", 42, true}' </body>\n" + "</html>\n"; browser.setText(htmlWithScript); new JavascriptCallback(browser, "jsCallbackToJava"); new JavascriptCallback_javascriptReceivedJavaArray(browser, "jsSuccess"); browser.addProgressListener(callCustomFunctionUponLoad); shell.open(); boolean passed = waitForPassCondition(() -> "a String".equals(returnArray.get(0)) && Double.valueOf(42.0d).equals(returnArray.get(1)) && Boolean.valueOf((boolean) returnArray.get(2)) == true); String message = "Java should have returned something back to javascript. But something went wrong"; assertTrue(message, passed); }

Target:
public void test_BrowserFunction_callback_with_javaReturningArray () { AtomicReferenceArray<Object> returnArray = new AtomicReferenceArray<>(3); class JavascriptCallback extends BrowserFunction { JavascriptCallback(Browser browser, String name) { super(browser, name); } @Override public Object function(Object[] arguments) { return new Object[] {"a String", 42, true}; } } class JavascriptCallback_javascriptReceivedJavaArray extends BrowserFunction { JavascriptCallback_javascriptReceivedJavaArray(Browser browser, String name) { super(browser, name); } @Override public Object function(Object[] arguments) { Object[] returnVal = (Object[]) arguments[0]; returnArray.set(0, returnVal[0]); returnArray.set(1, returnVal[1]); returnArray.set(2, returnVal[2]); return null; } } String htmlWithScript = "<html><head>\n" + "<script language=\"JavaScript\">\n" + "function callCustomFunction() {\n" + " document.body.style.backgroundColor = 'red'\n" + " var retVal = jsCallbackToJava()\n" + " document.write(retVal)\n" + " jsSuccess(retVal)\n" + "}" + "</script>\n" + "</head>\n" + "<body> If you see this, javascript did not receive anything from Java. This page should just be '{\"a String\", 42, true}' </body>\n" + "</html>\n"; browser.setText(htmlWithScript); new JavascriptCallback(browser, "jsCallbackToJava"); new JavascriptCallback_javascriptReceivedJavaArray(browser, "jsSuccess"); browser.addProgressListener(callCustomFunctionUponLoad); shell.open(); boolean passed = waitForPassCondition(() -> "a String".equals(returnArray.get(0)) && Double.valueOf(42.0d).equals(returnArray.get(1)) && Boolean.valueOf((boolean) returnArray.get(2)) == true); String message = "Java should have returned something back to javascript. But something went wrong"; assertTrue(message, passed); }