cancel
Showing results for 
Search instead for 
Did you mean: 

run testcase from different testsuite from CLI

SOLVED
Highlighted
Contributor

run testcase from different testsuite from CLI

I have a test suite that contains a testcase called Send Results.  It sends the results of the test case that calls it and write those results into our test case repo execution cycle.  All the testsuite/cases live in the same project.  When I run this in readyAPI it works fine.  When I run it via the CLI I get a null pointer exection on the getProjectByName().

ERROR [SoapUI] An error occurred [Cannot invoke method getProjectByName() on null object], see error log for details
ERROR [errorlog] An error occurred in the script of the Groovy Script test step [Send Result]:
ERROR [errorlog] java.lang.NullPointerException: Cannot invoke method getProjectByName() on null object

 

I understand why I get this error when running via the CLI but I don't understand how to correct it.  How can I make it so that the testcases can call the getProjectByName and access the desired testcase.

 

Code for calling the testcase:

testCase = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("EL-Web").getTestSuiteByName("Zephyr").getTestCaseByName("Set-TestCaseStatus")

def runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

hello bpistole,

 

here is sample code on how I call another testcase in a different suite.  I just ran it from cli and it works from there.  I am setting a property in the test suite i am calling with the testcase name that invoked it.  It might just be some small differences that are causing the issue that I cannot really say are the reason for your issue.  Anyway, working sample follows:

 

//
// Invoke a global test case that will invoke a compare process based on the given test case name being sent to it.
//
def invokeTestSuiteName = 'Common Code';
def invokeTestCaseName = 'Global Processing For DDL';
def properties = new com.eviware.soapui.support.types.StringToObjectMap();
def async = false;
testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).setPropertyValue(invokeTestSuiteName.replaceAll('\\s', '') + "testCaseName", testRunner.testCase.name);
def result = testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).getTestCaseByName(invokeTestCaseName).run (properties, async);
if (result.status.toString() == 'FINISHED' || result.status.toString() == 'PASS') {
// do nothing
}
else {
assert false, "There are differences between what business has requested and the actual database implementation. See 'difference' output file";
};

log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';

 

.

.

.

From within the called testcase I grab the testcase name that invoked it...

def testSuiteReference = testRunner.testCase.testSuite; // log.info "testSuiteReference is:" + testSuiteReference;
def testSuiteName = testSuiteReference.getName(); // log.info "testSuiteName is:" + testSuiteName;
def calledFromTestCaseName = testRunner.testCase.testSuite.getPropertyValue( testSuiteName.replaceAll('\\s', '') + "testCaseName"); //log.info 'calledFromTestCaseName=' + calledFromTestCaseName;
def tcNameList = calledFromTestCaseName.split('"').toList(); //log.info 'tcNameList=' + tcNameList;
def testableName = tcNameList[1].toLowerCase(); //log.info 'testableName=' + testableName;
testableName = testableName.replaceAll(' ', '');
log.info '########################### testableName=' + testableName;

View solution in original post

3 REPLIES 3
Highlighted
Contributor

hello bpistole,

 

here is sample code on how I call another testcase in a different suite.  I just ran it from cli and it works from there.  I am setting a property in the test suite i am calling with the testcase name that invoked it.  It might just be some small differences that are causing the issue that I cannot really say are the reason for your issue.  Anyway, working sample follows:

 

//
// Invoke a global test case that will invoke a compare process based on the given test case name being sent to it.
//
def invokeTestSuiteName = 'Common Code';
def invokeTestCaseName = 'Global Processing For DDL';
def properties = new com.eviware.soapui.support.types.StringToObjectMap();
def async = false;
testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).setPropertyValue(invokeTestSuiteName.replaceAll('\\s', '') + "testCaseName", testRunner.testCase.name);
def result = testRunner.testCase.testSuite.project.getTestSuiteByName(invokeTestSuiteName).getTestCaseByName(invokeTestCaseName).run (properties, async);
if (result.status.toString() == 'FINISHED' || result.status.toString() == 'PASS') {
// do nothing
}
else {
assert false, "There are differences between what business has requested and the actual database implementation. See 'difference' output file";
};

log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';

 

.

.

.

From within the called testcase I grab the testcase name that invoked it...

def testSuiteReference = testRunner.testCase.testSuite; // log.info "testSuiteReference is:" + testSuiteReference;
def testSuiteName = testSuiteReference.getName(); // log.info "testSuiteName is:" + testSuiteName;
def calledFromTestCaseName = testRunner.testCase.testSuite.getPropertyValue( testSuiteName.replaceAll('\\s', '') + "testCaseName"); //log.info 'calledFromTestCaseName=' + calledFromTestCaseName;
def tcNameList = calledFromTestCaseName.split('"').toList(); //log.info 'tcNameList=' + tcNameList;
def testableName = tcNameList[1].toLowerCase(); //log.info 'testableName=' + testableName;
testableName = testableName.replaceAll(' ', '');
log.info '########################### testableName=' + testableName;

View solution in original post

Highlighted
Contributor

Thanks, I will give this a try.

Highlighted
Contributor

Thank you so much!

This avoids having to get the workspace which is what the problem was.

Works great!

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors