Parameterize jython for reuse

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
Hello,

I have jython scripts to randomize words from a string as an input.
I want to store these scripts, say, at the suite level and parameterize them to use in any .tst file in the suite.
How may I do this?

Thanks!
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    There are a couple ways to accomplish this. Please look over both options and apply the steps that best fits your scenario.

    1) If the script needs to run once to retrieve the input for following tests, then I recommend adding an XML Data Bank chained to an Extension tool that will extract the desired value. This XML Data Bank can be referred to in the following tests within the .tst file. I have found a great reference that shows the setup process for this, which can be found in the Parasoft Forum under http://forums.parasoft.com/index.php?showtopic=61.

    2) If the script will be applied repeatedly in the .tst file, then I recommend saving this script as a Python/Jython script in your Hard Drive and then refer this script in your tests. To accomplish this, follow the steps below:

    a) Create a Python/Jython script outside of SOAtest and save it to a location.
    b) In the Preference settings (Parasoft > Preferences), navigate to Parasoft > SOAtest > Scripting, and specify the location (path) where you stored this Python/Jython script under the Jython Path field.
    c) Restart SOAtest so that the Python/Jython files can be compiled before the changes will take effect.
    d) In the .tst file, refer to the Python/Jython script where scripting is allowed.

    Here is a simple example to illustrate the previous steps.

    The script below is a Jython script that we would like to use repeatedly in our .tst file:

    def foo(input, context):
    return input

    Next, we will save this script under the name "Parasoft.py" and save the file on our desktop. Then we will add the location (path) to the desktop in the Preference settings in SOAtest.

    Now, lets refer to this script in our .tst file:

    import Parasoft

    def bar(input, context):
    return Parasoft.foo(input, context)

    Note that the "Parasoft" class (also the name of the Jython script file) is being imported and the "foo" method (noted in the Parasoft.py file) is being applied. If you would like to use the "Parasoft" script again, then add the previous script as many times throughout the .tst file where scripting is allowed.

    Hope you find this information helpful. Please let me know if these steps helps your scenario.
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Hi
    I tried out the second method that you had said. But when i give evaluvate script it is throwing an error module Python not found
    kindly help me out.
    Regards
    APS
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    I'm not sure if this could be causing the behavior you are encountering, but I would like to make one suggestion. When you add the Jython Path under Preferences > Scripting, be sure that you are pointing only to the folder that contains the Jython files. You do not need to specify the Jython file itself in the Jython Path. When you add the Jython folder, it will generate a class against that folder. This then can be accessible in your scripting in SOAtest.

    Please let me know if this works out for you.
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    yeaaa...dat helped.....thanks a lot.......
Sign In or Register to comment.