Testsuitename dynamically
Comments
-
There is no variable that has the name. However, you can retrieve it in a script. Here is an example script that allows you to get the test name or test suite name in an Extension Tool using groovy:
import com.parasoft.api.* void test(Object input, ScriptingContext context) { Application.showMessage(input.toString()) Application.showMessage("test: " + context.getParentContext().getContextName()) Application.showMessage("test suite: " + context.getParentContext().getParentContext().getContextName()) }
You could add additional "getParentContext()" calls to get parent test suites if you have a lot of nested test suites.
0 -
Yes, created an Extension Tool, with the above Groovy Script but unfortunately not getting the Name of TestSuite like (GetGeoLocationAPI).
---------- Test 1: Extension Tool ----------
test: Extension Tool
test suite: Test Suite0 -
Your script actually did get the name of the test suite - your test suite still has the default name of "Test Suite". Instead of the name of the test suite, are you looking for the name of the .tst file?
0 -
Thanks that worked. Sorry about that. But if I were to do a Jython equivalent of that, and with a Data Generator Tool with a string will it not work.
from java.text import *
from java.util import *
def getmyID():
# Get an instance of the calendar calendar = Calendar.getInstance() # Set the hour in the calendar hour = calendar.get(Calendar.HOUR_OF_DAY) calendar.set(Calendar.HOUR_OF_DAY, hour) # Retrieve the date from the calendar date = calendar.getTime() # Create the date formatter myFormat ="yyyyMMddHHmmssSSS" formatter = SimpleDateFormat(myFormat) # Create the date and time stamp, and print and return the name value timestamp = formatter.format(date) name ="{Auditing}{" + context.getParentContext().getContextName() +"}{" + timestamp + "}" print name return name
0 -
Currently your method declaration looks like this:
def getmyID():
Instead it should look like this:
def getmyID(input, context):
I'm not sure what error you get when you run, but I suspect the code is failing when trying to reference the context variable since you didn't declare it as input to your script.
0 -
from java.text import *
from java.util import *
from com.parasoft.api import *
def getmyID(input, context):
# Get an instance of the calendar calendar = Calendar.getInstance() # Set the hour in the calendar hour = calendar.get(Calendar.HOUR_OF_DAY) calendar.set(Calendar.HOUR_OF_DAY, hour) # Retrieve the date from the calendar date = calendar.getTime() # Create the date formatter myFormat ="yyyyMMddHHmmssSSS" formatter = SimpleDateFormat(myFormat) # Create the date and time stamp, and print and return the name value timestamp = formatter.format(date) apiname = context.getParentContext().getParentContext().getContextName() name ="{Auditing}{" + apiname + "}{" + timestamp + "}"
print name
return namereturns an Error Message "Unable to invoke user method getmyID(). Argument count should be 0 or 1 instead of 2."
0 -
Then change the signature to def getmyID(context) and try again.
0 -
from java.text import *
from java.util import *
from com.parasoft.api import *def getMyID(context):
# Get an instance of the calendar calendar = Calendar.getInstance() # Set the hour in the calendar hour = calendar.get(Calendar.HOUR_OF_DAY) calendar.set(Calendar.HOUR_OF_DAY, hour) # Retrieve the date from the calendar date = calendar.getTime() # Create the date formatter myFormat ="yyyyMMddHHmmssSSS" formatter = SimpleDateFormat(myFormat) # Create the date and time stamp, and print and return the name value timestamp = formatter.format(date) apiname = context.getParentContext().getParentContext().getContextName() name = apiname print name return name
File "", line 43, in getMyID
AttributeError: 'NoneType' object has no attribute 'getContextName'0 -
It appears that you are not running this script from an Extension Tool. Where are you inputting this script? It may need to be adjusted based on where it is running.
0