JavaScript random generator functions import

Hello there. Can some one please help me?! I’m currently working on the web project as a QA. And I need to automize my test cases with katalon. I want to create auto test with random generator to the fields (name, ID, age, passwords, Country, Bankaccounts etc.) function when i’m trying to register new user. I have javascript file with all kind of random generators that my lead used in IDE and now he is using it in WebDriver. But I want to execute it on Katalon. Is there is a way to import javascript file to katalon and use random generator functions or copy this functions from the file to katalon when I’m running test case with registration fields?
Thanks for attention! Have a good day!

Hi Mike

It would be great if there was an easy way to do this but as far as I am aware, there is no “import js script” and a system that marshals up its functions. However…

Following is a method I use to wrap JavaScript code using Groovy’s tripple-quoted strings (if nothing else, it makes the script slightly more readable). I’m suggesting you try this with your functions so that you give them a “Groovy Interface”.

But note this: I assume all the JavaScript code is able to work running in a Katalon TestCase environment and knows how to access elements on your AUT page(s).

This example adds 1 to any passed in integer (at least, it’s supposed to - I have NOT tested it!) You can replace the js code with your own:

static int addOne(int x) {
  String js = '''
    var x = arguments[0];
    alert(x);
    x += 1;
    alert(x);
    return x;
  '''
  int result = WebUI.executeJavaScript(js, Arrays.asList(x))
  return result
}

Note: that js variable has THREE SINGLE QUOTES around it.

Let me know how it goes…

Russ