Customizing Test Cases with Javascript

Although Functionize is a no code solution to test automation, we do support a significant amount of custom code in many areas in order to do more advanced or custom tests.

Custom Javascript Action

An Action called Custom Code may be added via Architect, the Slider View, or the Test Detail page. This allows the user to write Javascript that may interact with the browser in any way. The Javascript function that is added should return a boolean (true/false) value and the Action will pass or fail according to the value returned. 


Examples for when you might use Custom Code:

  • Verifying that the correct number of blog entries appear on the page
  • Verifying all ads got loaded from the correct website
  • Verifying the order in which certain information is presented to the user

See Video: Custom JS Example

If you are using an asynchronous function such as making an API call or map, for example, you will need to make a callback to Functionize when the call is complete. You can do this with functionizeAsyncCallback.

functionizeAsyncCallback(boolean result)

Custom Code Actions may be edited in the Action Settings on the Test Detail page or Slider View. Edit the code in the Javascript Verification field provided.


Customizing the Result Message

You can customize what the result message will show for Custom Code Actions by supplying the return value with parameters "result" and "message" like this:

return '{ "result": false, "message": "This step is failing for XYZ reason"}'

You can customize results further using Functionize variables in the response:

return '{ "result": false, "message": {{fze.local.errorMsgs[2]}}}'

"result" should be a boolean value, while "message" should be a string containing the reason the step failed.

Outcome Override

Similar to a Custom Code Action, a user can override an Action's Pass/Fail state with Outcome Override. For example, you could write custom JS code to loop through all cells of a table evaluating the contents to find a specific value. The Action will pass or fail based on the conditions specified. 

Outcome Override is available via the Action Settings on the Test Detail page or Slider View.

Also see Customizing Tests Using Selectors for additional information on Selector Overrides.