Forum Discussion

MikeLoundes's avatar
11 years ago

[R] Cannot invoke method getTestCaseByName() on null object

Hi folks

I've had a search about but cant seem to find the answer for this

in a nutshell I have a soapui project that I use from several other projects, this is due to the reference project containing data extractions that are common to multiple other projects so I've kept them in one place
I've noticed that when running a project that calls the reference project from within the GUI all is well as long as I have the reference project open, if closed I get the cannot invoke method error, this isn't a big issue for me in general but as we are now trying to run tests via CI on the back of a build using maven & Hudson the error crops up and is a more serious issue for us

I've found posts relating to running setup test projects but I've tried to use some of that info as a reference and I'm hitting brick walls

the code snippet below has been truncated with respect to the list of properties I'm getting back from the test case execution

any help is very much appreciated

for ref I get the error on the line -
testCase = testSuite.getTestCaseByName(TargetTestCaseName);

def groovyUtils = new

//get current project/suite/case names
def CurrProjectName =;
def CurrSuiteName =;
def CurrTestCaseName =;
// "CurrProjectName = " +CurrProjectName;
// "CurrSuiteName = "+CurrSuiteName;
// "CurrTestCaseName = "+CurrTestCaseName;

//get vars
def customerReferenceNumber = testRunner.testCase.getPropertyValue( 'customerReferenceNumber' )
def schemaRefName = testRunner.testCase.getPropertyValue( 'schemaRefName' )
def contractReferenceNumber = testRunner.testCase.getPropertyValue( 'contractReferenceNumber' )

//Project and Test Suite References
def TargetProjectName = "DB Ref Data";
def TargetTestSuiteName = "Generic DB Queries reference";
def TargetTestCaseName = "Get Party Details";

//get test case from other project or from the same one
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName(TargetProjectName);
testSuite = project.getTestSuiteByName(TargetTestSuiteName);
testCase = testSuite.getTestCaseByName(TargetTestCaseName);

//set properties
testCase.setPropertyValue('customerReferenceNumber', customerReferenceNumber);
testCase.setPropertyValue('schemaRefName', schemaRefName);
// run test case
runner =, false);

//get property values
def TransproductHoldingRoleType = testCase.getPropertyValue('productHoldingRoleType');
def TranspartyType = testCase.getPropertyValue('partyType');
def TransPartySourceSystemId = testCase.getPropertyValue('PartySourceSystemId');

//reset project refs
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName(CurrProjectName);
testSuite = project.getTestSuiteByName(CurrSuiteName);
testCase = testSuite.getTestCaseByName(CurrTestCaseName);

//update test case properties
testRunner.testCase.setPropertyValue('productHoldingRoleType', TransproductHoldingRoleType);
testRunner.testCase.setPropertyValue('partyType', TranspartyType);
testRunner.testCase.setPropertyValue('PartySourceSystemId', TransPartySourceSystemId);

4 Replies

  • Hi folks

    ok with a lot of support and patience from the support team (thanks, very much appreciated)
    this did cause some head scratching as things would work when running from within the GUI but when running from command line I was getting errors, this is now sorted and running happily

    the issue was that the reference project was unknown in the instance of the current project, to resolve it a workspace is initiated and the reference project imported in

    the following code initiates the workspace and imports in the reference project, following on from that (within the same script) is the action to run the test case within the reference project file

    import com.eviware.soapui.impl.WorkspaceImpl;
    import com.eviware.soapui.model.project.ProjectFactoryRegistry;
    import com.eviware.soapui.impl.wsdl.WsdlProjectFactory;
    def groovyUtils = new;

    print '### Script Workspace Setup ###'

    //set path to reference project file
    def targetDir = new File(groovyUtils.projectPath).parent //<--mod path to point to relevant directory, my ref project lives in the parent directory of the current project
    def targetProjectFile = targetDir+'\\'+'someReferenceProjectFilename.xml'
    def targetWorkspace = targetDir+'\\'+'default-soapui-workspace.xml' //point to whatever workspace file you are using
    def targetProjectWorkspaceName = 'some project name'

    //check to see if project already in workspace and import if not
    def workspace = testRunner.testCase.testSuite.project.workspace
    workspace = new WorkspaceImpl(targetWorkspace, new StringToStringMap());
    def isProjectInWorkspace = workspace.getProjectByName(targetProjectWorkspaceName)
    if (isProjectInWorkspace == null){
    def refProject = workspace.importProject(targetProjectFile.toString())

    //check to see if project is open and open if not
    def testProject = (workspace==null) ?
    ProjectFactoryRegistry.getProjectFactory(WsdlProjectFactory.WSDL_TYPE).createNew(targetDir+".xml") :
    if(! && workspace!=null) {workspace.openProject(testProject)}

    print '### End Workspace Setup Script ###'

    // ...... do some bits then get to invocation of ref test case

    //Project and Test Suite References
    def TargetTestSuiteName = "some test suite name";
    def TargetTestCaseName = "some test case name";

    //get test case from other project or from the same one
    project = workspace.getProjectByName(targetProjectWorkspaceName);
    testSuite = project.getTestSuiteByName(TargetTestSuiteName);
    testCase = testSuite.getTestCaseByName(TargetTestCaseName);

    //set properties
    testCase.setPropertyValue('somePropertyName, propertyValue);

    // run test case
    runner =, false);

  • Hi folks

    has anybody got an idea of how to resolve this, we want to use the tests on the back of the build but I'm currently having to limit what we can actually run because of this issue with the referenced project not being 'open'

  • SmartBear_Suppo's avatar
    SmartBear Alumni (Retired)
    The line you quoted works just fine. It would help the community to understand you issue if you quoted the error you are receiving from "Error log" tab at the bottom.

    Michael Giller
    SmartBear Software
  • microbBO's avatar
    New Contributor

    Hi  community, I've a simmular problem  with getTestStepByName() method, when  I try to call the method from TestCase "setup script" tab. Could you help me resolve it.


    there is "problem row"


    context.getTestCase().getTestStepByName("test case name").getAssertionByName("assertion name").setDisabled(false);