Forum Discussion

blackchoc's avatar
16 years ago

Scripts per Project

Hello,

I use the Groovy Script Features of SoapUI extensivly. I have read all forum
posts about this topic, so I will try to explain the requirements in a certain test environment. Lets say you have a directory structure like this one:

TestTopic01
  scripts
  testdata

  Test01
      testdata
  Test02
      testdata
      scripts

TestTopic02
  scripts
  testdata

  Test01
      testdata
  Test02
      testdata 
      scripts
...

Every TestTopic is one SoapUI project. Every SoapUI project is probably
used/worked on by a person at any time. But you always have at least
two projects open in SoapUI.

You could fake "local" scriptfolder by dumping everything into a large
top folder with packages "TestTopic01" and so on. This would be usable,
if it  wouldn't require constant changing of the relevant "Topic" subfolder
in the global properties, since you swap often between projects.

But it doesn't solve the problem, that you might need additional, testSuite
specific helper functions, which SHOULD reside in the "subfolder" of the
testSuite. Currently, I use following SetupScript in any project to change the script folder:


def scriptDirectory = context.get('${projectDir}')+"\\scripts"
com.eviware.soapui.SoapUI.settings.setString( "Script Library", scriptDirectory)


This alone doesn't the trick, because if you don't change the timestamps of
files, nothing happens. You have to add (simplified pseudocode)


      for (anyfile in scriptdir incl. subdirs) anyfile.touch()


This wakes up the script-reloader, and then you go. But I find this cumbersome
and error prone. It also requires that the tester/coder runs all tests from the top
and not just the one testSuite he is interrested in. It also makes moving of
testSuites difficult, because you have to rememeber to move specific scripts from
the top folder...you see the point.

I also can't write a EventListener, because this would require a (currently
nonexisting) "ProjectActive" or "ProjectActivated"-Event which reacts on every
project "activation" (or "focus" if you will).

In earlier versions (I think, Pro 2.5.1?), it worked (sometimes) to set the global
script library to something like "${projectDir}\scripts". But this was probably
more a side-effect than a supported feature 

The best solution would be, if it where possible to set special properties
in project, testsuite, testcase like "scriptlibrary.localscriptdir" As soon you
"activate" a project, the scriptloader scans trough all properties and reloades
all scripts found on all levels. (I guess some caching would be useful performancewise).

For a first quick hack, it would be enough to have a "projectActivated" event,
I could do the rest for now

As a sidenote: it would be helpful if there where another way to force
reloading the scripts, something like "ClasspathHacker.purgeScripts()"
instead of cheating timestamps 

thank you for listening
-Igor

14 Replies