Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] A custom script to run a custom JS code from a git repo (Github) in specific branch #2

Open
nivpenso opened this issue Aug 11, 2021 · 1 comment

Comments

@nivpenso
Copy link

Dear Testim custom actions team.

[Problem]
Maintaining custom JS actions in Testim is not convenient for us for several reasons:

  1. changes can't be tracked
  2. anyone can change it
  3. code doesn't go through the standard development cycle

[Suggestion]
have a private repo of custom steps, that we can run and manage - sort of this repo, but private, separately for each account.
To do so we suggest creating a custom action that reads JS code from a private git repo and executes it.

Thoughts?

@barrysolomon
Copy link
Collaborator

barrysolomon commented Aug 11, 2021

Great idea!

I doubt that we would host such private repos, but that does not prevent you from doing this against your own repository.

To make sure this was doable before answering (and it intrigued me as well):

I created a js file on my local server (http://localhost:8081/scripts/myscript.js)

  var my_message = (typeof customStepParam !== 'undefined') ? customStepParam : "Default message";
  
  function myFunction(message) {
      console.log("myFunction('" + message +"') called");
      return "myFunction received input: " + message;
  }
  
  let response = myFunction(my_message);
  console.log("myFunction's response was '" + response + "'");

I then created a custom step in Testim with the following body and JS parameter "customStepParam":

    let src = "http://localhost:8081/scripts/myscript.js";
    let myScript = document.createElement("script");
    myScript.setAttribute("src", src);
    document.head.appendChild(myScript);
    
    var message = (typeof customStepParam !== 'undefined') ? customStepParam : "Default message";
    let response = myFunction(message);
    console.log("myFunction's response was '" + response + "'");

I ran the test and my remote JS file function was called. Once when loaded as the script itself calls the function and once by Testim in the custom step with the test user defined parameter (customStepParam) as seen in the webpage's console log:

     myFunction('Default message') called
     VM98 myscript.js:11 myFunction's response was 'myFunction received input: Default message'
     VM98 myscript.js:6 myFunction('YO YO YO!') called
     VM103:15 myFunction's response was 'myFunction received input: YO YO YO!

Note:
You will want to wrap the step's logic in a function and then call the function with the test parameters in the custom step itself and not the remote JS.

Also, if you want to make it so nobody messes with the custom step you can always obfuscate it with a site like https://obfuscator.io/

Hope this helps and is what you are looking for.

Barry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants