You can use parameters in any custom JavaScript step: 

  • Custom Action
  • Custom Validation
  • Custom Wait-for 
  • Custom Condition

There are 2 types of parameters: 

  • HTML: Allows you to refer to HTML Elements in your app.
  • JS (JavaScript): Allow you do define any JS expression.

Custom Action example

In this example, we'll create a custom action that will click a button to demonstrate the use of the HTML parameter

  1. Go to https://www.testim.io/ in the browser and start a new test.
  2. Scroll the page down until the Twitter buttons appear.
  3. Go to Testim editor.
  4. Use ‘+’ menu ⇒ 'Add Custom Action'.
  5. In the properties click under 'Shared Step Name' and rename it from 'Untitled validation' to 'Click'.

Adding HTML param

  1. Click on the '+' icon to the left under Params and choose HTML:

2. Select the Twitter icon at the bottom of our website.
3. The icon is now added to the list of Params.
4. Double-click on the name and change it to "element".
    The name of every parameter is just above it. 

5. Now type under the function on the left:

JavaScript

 element.click()

6. Go back to the test and run it.
7.  You can see that the element was clicked.

Note:  in order do use Jquery in your custom validations and actions, your site needs to have Jquery installed.

Reuse and pass different parameters

We made a step in our test that clicks on the Twitter icon.

Next, let's reuse this step in another page and this time we will click on the LinkedIn button. Do we need to make another custom action? No!

  1. Use ‘+’ menu ⇒ choose 'Click'. This action is the action we created before. 
  2. In the Params section click on the 'Assign now' and then 'HTML'.
  3. Choose the LinkedIn icon.
  • Run the test and see that both buttons were clicked. 

Adding JavaScript parameter

JavaScript parameters are commonly used for constants and variables.
We will mainly use those when we want to forward values to a group or to other reusable steps.
You can find examples for using JS params here.

Did this answer your question?