Forum Discussion

Liberty_Informa's avatar
Liberty_Informa
Regular Contributor
11 years ago

[Resolved] Script Library

Hi

Recently we created one class in groovy script library. We are successfully able to access the class from the soapUI's groovy step.

When I deployed the code into the server where we do automation testing, it is not working. From the log I can make out that, soapUI is looking for the Script file in a folder which is an empty. Please refer below screen shot to understand in detail.



soapUI is looking for Script in the folder "rtc_5451". We create this temporary staging folder for each test run. The folder contains latest source from the source control. We do delete the folder once test execution is completed. Ideally soapUI should look for script library in "rtc_4771" which is directory created for the current test cycle. I do set script library path in the load script. You can notice that statement highlighted in yellow color towards the bottom side.

I think [SoapUIProGroovyScriptEngineFactory] is using older path which has been updated in the soapui-seetings.xml file in the previous run.

Why is this happening? Please guide us how can we update library path in the soapui-settings.xml just at the beginning of the test so that it is picked up correctly?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    The script library can be changed dynamically by using the Setup Script area at the project level. Add the following in the Setup Script area.

    project.scriptLibrary = "C:\\My script folder"


    When running test runner you should then see a message similar to this:

    Wed Jul 02 16:38:00 EDT 2014:INFO:16:38:00,965 INFO [SoapUIProGroovyScriptEngineFactory] Resetting groovy class cache due to 3 modified files
    16:38:00,966 INFO [SoapUIProGroovyScriptEngineFactory] Adding Script Library at [C:\My Script folder]


    Regards,
    Marcus
    SmartBear Support
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    Hi Marcus

    When you say Setup script area at the project level, is it which appears inside the "TestSuites" tab when we open project view?

    I am not sure however when I add following code in that area:

    def text = "~"
    def projectPath = context.expand( '${projectDir}')

    project.scriptLibrary = projectPath + "/../../Setup"
    log.info "${text*5} Project Setup Script -> Script Library path: "+project.scriptLibrary


    The output log is shows incorrect folder as I had explained in the original post. I see the code written in this setup area is getting executed even after project load script.

    This is similar situation. Am I doing anything wrong here?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    When you say Setup script area at the project level, is it which appears inside the "TestSuites" tab when we open project view?


    Correct.

    The project.scriptLibrary call is working for me to set the script library path, you may need to use an absolute path (one without the /../ in it) for the library path to be set correctly. Also, in your "Project Load Script", how is this being executed? Is this a script that is in an event handler?


    Regards,
    Marcus
    SmartBear Support
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    Absolute path will not be possible as base path can not be determined at each developers machine. I think absolute path should not be an issue because I use it in load script and groovy steps to read test data which works OK.

    I was setting up script path (at the preference level) in the load script as below. When you told about Project setup script, I commented it out in the load script and added new code in the setup script.

    // Setting Script Library
    String scriptPath = projectPath + "/../../Setup"
    SoapUI.settings.setString( SoapUIProSettings.SCRIPT_LIBRARY, scriptPath )
    log.info "${text*10} Script Library: " + SoapUI.settings.getString( SoapUIProSettings.SCRIPT_LIBRARY, "Script Library")


    The output log after adding code in setup script is much same.



    I expect soapUi to use path circled in green however it sets up path circled in red. I am sure soapUI is reading this from the soapui-setting.xml. It will have always entry of a path just one older to current run.
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    One thing I noticed that after I commented code in the load script and added new script in the Setup script, soapui.settings.xml file has not been updated. Every time soapUI is looking for script library in the older path. I am not sure the code added in Setup Script which file it updates. I checked settings.xml at the project level however could not find anything related to the library path in that file.
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    Now my next experiment is in the project load script to clear out global script library path before setting it up again fresh. This is done because in each run the folder structure will be dynamic. I read on one of the other threads that it has helped few folks.

    Now the code in the load script is like this:

    //Make sure global setting is cleared
    log.info "${text*10} Clearing global script library..."
    com.eviware.soapui.SoapUI.settings.setString( "Script Library", "");
    log.info "${text*10} Global script Library : '"+com.eviware.soapui.SoapUI.settings.getString( "Script Library","default")+"'"

    // Setting Script Library
    SoapUI.settings.setString( SoapUIProSettings.SCRIPT_LIBRARY, projectPath + "/../../Setup/Scripts" )
    log.info "${text*10} Script Library: " + SoapUI.settings.getString( SoapUIProSettings.SCRIPT_LIBRARY, "Script Library")


    The log statement that I see is as below:



    Again same behavior. The script path is correctly set by the statements in load script however soapUI picks up old path entry from the soapui-settings.xml file before statements in load script which sets up the library path are executed. As I can see soapUIProGroovyScriptEngine class picks up the old path. Can you explain us how can we solve so that soapUI will always pick up latest path?

    Again to reiterate I am running automated tests headless and not in the GUI client.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    This sounds like a feature request to me. If I got this right, you are trying to overwrite the script library path in preferences?

    Regards,
    Temil
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    This is not a feature request. Could you revisit my posts and let me know if something is unclear to you.
  • Liberty_Informa's avatar
    Liberty_Informa
    Regular Contributor
    This has solved for me by not using global script library path rather using project level library path.
    • pejut's avatar
      pejut
      Occasional Visitor

      This seems to be still an issue with SoapUI Pro 5.1.2. When running with SoapUIPro plugin in Jenkins the script library path is not set correctly.