Forum Discussion

SoapUser2012's avatar
SoapUser2012
Occasional Contributor
13 years ago

How do I use a variable in getTestCaseByName()

Hi ,

1.I'm running the test cases in a test suite in a loop and logging the results.

All the test case names are in array. I want to fetch the testcase names in a loop for each iteration and use it in the below call:
varname=testcasenames

//def tc = testRunner.testCase.testSuite.project.testSuites[var name ].getTestCaseByName(varname)


Thanks
  • Hi,

    not sure I understand, but I think you want to do

    for( name in testcasenames )
    {
    testRunner.testCase.testSuite.project.testSuites["name of testsuite"].getTestCaseByName(name)
    }

    or am I misunderstanding?

    /Ole
    SmartBear Software
  • SoapUser2012's avatar
    SoapUser2012
    Occasional Contributor
    Yep , exactly same .

    Need to use the variable name in the getTestCaseByName(name). When i use the variable name i get the 'null pointer exception'.
    Not able to fetch the test case reference .


    Thanks,
  • Hi,

    hmm.. have you initialized your array correctly?

    I'm sorry - help with general groovy scripting is outside the scope of our support offering, head over to the groovy user guide and forums to get help on non-soapUI-API related scripting questions.

    Thanks for your understanding!

    regards,

    /Ole
    SmartBear Software
  • RJanecek's avatar
    RJanecek
    Regular Contributor
    Hi,

    I want to help you but I am not sure If I understand your question. In varname you have name of your testCase right ?

    where you are running your command ?

    When I run this command in testCase setupScript I got whot you want:
    def tc = testRunner.testCase.testSuite.project.testSuites["a"].getTestCaseByName("b") where a is name of my testSuite and b is name of my testCase.
    Can you be more specific where you have NPE ?
  • SoapUser2012's avatar
    SoapUser2012
    Occasional Contributor
    Hi ,

    Thsi is working fine for me as well:

    When I run this command in testCase setupScript I got whot you want:
    def tc = testRunner.testCase.testSuite.project.testSuites["a"].getTestCaseByName("b") where a is name of my testSuite and b is name of my testCase.

    I want to use the variable name in place of "a" /'b" . Say you have array of test case names and want to input arr there in place of test case name in the above . Hope its clear now.

    thanks