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.

Passing arguments to a Python script

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
I have a Python script which is run as an output to an External Tool (note that this External Tool is run multiple times within a test scenario so this same type of script also appears multiple times). The only lines of code that change are for the Environment variable, assignmentSQL, and the file to read, ASSIGNMENT.txt; both of these items are shown below. I would like to "parameterize" both of them by passing in arguments so I can reuse the same script but I cannot figure out a way to do it. Any suggestions?

CODE
from com.parasoft.api import *
from soaptest.api import *
from java.util import *
from java.text import *
from java.lang import *
from com.parasoft.api import IOUtil
from java.io import File

def main(input, context):
   # myVarTSV is a member of the TestSuiteVariable class
   mySqlTSV = context.getVariable("assignmentSQL")

   # getValue() always returns a string
   mySql = mySqlTSV.getValue()

   # Create java.io.File
   file = File("C:/Temp/SQLqueries/ASSIGNMENT.txt")
   mySql = IOUtil.readTextFile(file)

   # Store myVar to use later in the test run
   mySqlTSV.setValue(mySql)

def addDataSources(context):
   # DataSourceName is name of the data source
   ds = ArrayList()
   ds.add("Generated Data Source")
   return ds
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    I figured out how to do it as follows.

    I changed my External Tool to write out the information I wanted to parameterize to the command line (StdOut). I then chained an Extension Tool to the External Tool and split the input into separate variables - one for the Test Suite Variable and one for the SQL insert. I then saved the SQL insert to the Test Suite Variable.

    CODE
    from com.parasoft.api import *
    from soaptest.api import *
    from java.util import *
    from java.text import *
    from java.lang import *

    def showMe(input, context):
        value = input.split("----------")
        
        mySqlTSV = context.getVariable(value[0])

        # getValue() always returns a string
        mySql = mySqlTSV.getValue()

        # Store myVar to use later in the test run
        mySqlTSV.setValue(value[1])
        
        # Application.showMessage(str(mySqlTSV.getValue()))
        
    def addDataSources(context):
       # DataSourceName is name of the data source
       ds = ArrayList()
       ds.add("Generated Data Source")
       return ds

Tagged