Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Generating a unique number

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
For writing to an XML Data Bank
To generate a unique number so that you may write that number to an XML Data Bank for use within another test you can use the following script. Within a method tool make sure python is the selected language and then enter this script. You can then chain an XML Data Bank to the method tool, which will allow the unique number to be saved and used in another test. You can change the MASK variable to allow you generate a number of whatever length you wish.

CODE
from soaptest.api import *

MASK = 1000

def getURL(input, context):
 # returns a unique number
 num = 1000 + SOAPUtil.getUniqueNumber()
 # returns XML allowing the number to be stored in the XML Data Bank
 return SOAPUtil.getXMLFromString( [ str(num) ] )

def addDataSources(context):
 return "Generated Data Sources"
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Options
    There is a small typo in the last line of the Python script. A corrected version that also prints the generated number to the bottom panel:

    ====================cut here ================================
    from soaptest.api import *
    from com.parasoft.api import Application

    MASK = 1000

    def getURL(input, context):
    # returns a unique number
    num = 1000 + SOAPUtil.getUniqueNumber()
    Application.showMessage(" Unique number: " + str(num))
    # returns XML allowing the number to be stored in the XML Data Bank
    return SOAPUtil.getXMLFromString( [ str(num) ] )

    def addDataSources(context):
    return "Generated Data Source"
    ====================cut here ================================
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Options
    The indentation of the script is gone now... Sorry. Please indent the blocks of code in the methods as above in the original example.
    Good luck,
    Jaap