Forum Discussion

harir12's avatar
harir12
New Contributor
7 years ago

Running soapui groovy test step via Java

I am using soapui open source and am trying to run a soapui groovy script  test step via Java.  The groovy script opens a file to read data and then the appropriate test cases run. When i call this test step from Java, the call is successful, however the groovy script fails to read the file data and i am not able to run the test cases properly.

 

Could anyone please suggest a solution for this?

 

This is my java code :

 

WsdlProject project = new WsdlProject("Path to project");
WsdlTestCase testCase = project.getTestSuiteByName("<testsuite>").getTestCaseByName("<testCase>");
WsdlTestStep testStep = testCase.getTestStepByName("<Script name>");
WsdlTestCaseRunner runner = new WsdlTestCaseRunner(testCase, new StringToObjectMap());
runner.runTestStep(testStep);

  • JHunt's avatar
    JHunt
    Community Hero

    Can you confirm that your Groovy script works in SoapUI?

     

    Can you post your Groovy script?

     

    Are there any errors visible in the SoapUI.log?

  • harir12's avatar
    harir12
    New Contributor

    It is working when i run the script directly in soapUI. I checked the soapui.log file as well but was unable to see any errors come up there.

     

    I have added apache poi to soapui's ext folder and have imported POI classes for use in my script as well; here's the groovy code snippet to open and read the file.

     

    prj = testRunner.testCase.testSuite.project.workspace.getProjectByName("<project>");

    dataPath = prj.getPropertyValue("<dataPath>");

    FileInputStream xl = new FileInputStream(new File("<datatPath>"));

    Workbook workbook = new XSSFWorkbook(xl);

    Sheet dataSheet = workbook.getSheetAt(0);

    Row row = dataSheet.getRow(0);

    Cell data1Cell = row.getCell(0);

    data1 = data1Cell.getStringCellValue().trim();

     

    When i run the code listed in my previous thread in java, i see the following exception :

     

    org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA

     

    I understand that this comes up when it tries to run/parse the response which in turn tells me that the request is not getting updated correctly based on the file data.

     

    The file contains the data which needs to be updated into project properties. Once these properties get updated, the script uses the runner to run the request.

     

    thanks.