Customizing Test Cases with JavaScript

Customizing Test Cases with JavaScript Overview

Although Functionize is a no-code solution for test automation, we do support a significant amount of custom code in many areas of the platform in order to do advanced or custom testing.

Custom Javascript Action

An Action Type called Custom Code may be added via the Functionize 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. 

InsertCustomCode.png

Examples of 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 Editor field provided.

CustomCode.png

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]}}}'

Supplying "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 the Outcome Override field under Action Details Settings. For example, you could write custom JavaScript 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.
OutcomeOverrideValue.png

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