Forum Discussion

Ryan_Moran's avatar
Ryan_Moran
Valued Contributor
5 years ago

importing function from javascript to keyword test

Attempting to use 

require("MyCommonUnit").myFunction("someparameter")

within a keyword test statement such as Set Variable Value 

Seems like this should work, but returns an error:

Unable to evaluate the operation's "NewValue" parameter. Error: Error: Unable to find the specified module
 
In my script I have the following:
// [MyCommonUnit]
module.exports.myFunction = some_function; 

function some_function() {
//does stuff
return someValue; }
Anyone have an idea why this doesn't work or perhaps an alternate method to use?
  • You can... if the function returns something, you can still use the Set Variable value after the script function call and set the "mode" of the set variable to "Last Operation Result".  This will take whatever the result is of the function call and assign it to the variable value.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Just an idea to check:

    What if you wrap the Value with the eval/evaluate function?

    I.e.:

    evaluate(require(...).myFunction(...))

     

    In case of success this will make it possible to use just one operation instead of two...

     

    • Ryan_Moran's avatar
      Ryan_Moran
      Valued Contributor

      More specifically, trying to return the result of that function.

      I suppose I could just set a project level variable within that function, but I was hoping for a more dynamic solution.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You can... if the function returns something, you can still use the Set Variable value after the script function call and set the "mode" of the set variable to "Last Operation Result".  This will take whatever the result is of the function call and assign it to the variable value.