Opening a page that has a setTimeout() call with a string parameter can cause automated tests (ATF) to fail unexpectedly


Tests start to fail due to "TypeError: fn.apply is not a function" or similar javascript error in Step Results after upgrading to Madrid Patch 9 or New York Patch 3. The ATF is unable to process setTimeout function calls with a string parameter.


Steps to Reproduce

1) Enable test running in the Automated Test Framework (ATF) > Properties module.

2) Navigate to the System UI > UI Pages module and click "New":

  Set "Name" to anything;
  Paste the following for "HTML":
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div id="myDiv">This will change in 2 seconds</div>

  Paste the following for "Client script":
setTimeout("gel('myDiv').innerText = 'Hello world!'", 2000);

  Click "Submit".

3) Navigate to the Automated Test Framework (ATF) > Tests module then click "New", input any name and click "Save".
4) Click "Add Test Step", navigate to "Form" and select "Open an Existing Record" and click "Next".
5) Set Table to "UI Page [sys_ui_page]" and Record to the UI page created in steps 1-2 then click "Submit".
6) Click "Add Test Step", navigate to "Form" and select "Click a UI Action" then click "Next".
7) Set the "UI Action" input to "Try it" then click "Submit".
8) Click "Add Test Step", navigate to "Custom UI" and select "Assert Text on Page (Custom UI)" then click "Next".
9) Set "Text" to "Hello world!" then click "Submit".
10) Click "Run Test" then click "Run Test" in the "Pick a Browser" modal.

The test will fail for different reasons depending on the browser, and there is an error in the browser console:
"TypeError: fn.apply is not a function. (In 'fn.apply(this, arguments)', 'fn.apply' is undefined)"

In some browsers like Safari, the error is registered as a client error and ends the test immediately. Other browsers like Chrome are more forgiving of the error, but the test still fails because the text does not change as expected.


This problem has been fixed. There is no workaround available. If you are able to upgrade, review the Fixed In section to determine the latest version with a permanent fix your instance can be upgraded to.

If a workaround is needed, the page author can change the affected page passing functions instead of strings to setTimeout, which accepts functions as parameters since JavaScript 1.2. There are a number of reasons why passing a string argument is poor practice, including that a compiler has to fire up just to process the string input, slowing down the page.


Related Problem: PRB1372491