Setting a unique text value to an input field

Many times you need to enter a unique text value to an input field, for example when you want to test your new user registration. Here is how to do it with Testim with only 2 lines of code.

First, you need to create a custom action, as described in the page about JavaScript Validations and Actions:

Now add an HTML parameter - select the input field you wish to set, and set its name to input_email (see how to add parameters).

Now just use these two lines of code here, where we first generate a unique string using the current time (you can replace with your own logic), and then set the field's value:


var userName = "testim_user+" + new Date().toJSON().slice(0,19).replace(/:/g,'-') + "";
input_email.value = userName;

And that's it! the email field will get a unique new value with every run.

Create a generic "wait" step

Sometimes you just need to wait a few seconds between steps. But let's do it right and create a generic "wait" step, that takes the duration (number of milliseconds) to wait, so it can be reused again and again without writing more code. This is how to do it:

First, add a custom action like in the previous example. Now, add a new parameter of type JavaScript ("JS"):

Name it duration (note that naming in JavaScript is case-sensitive). In this example we set it to 3000 milliseconds (3 seconds):

Copy and paste this code into the editor:


return new Promise(function(resolve) {
  setTimeout(resolve, duration);

Set its "Shared Step Name" to "wait", and click OK.
To use it just add the new wait step wherever you need it (don't forget to set its duration):

Did this answer your question?