Generating a unique number

LegacyForumLegacyForum Posts: 1,669 ✭✭
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

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    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 ================================
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    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
Sign In or Register to comment.