Forum Discussion

HaroldR's avatar
HaroldR
Contributor
7 years ago
Solved

Populate string inside Excel Data Sink fields from groovy script

Hey, 

Context : Let's say that I have appended a DataSink Teststep manually which I have named "DataSink", feature which is provide naturally in the UI of ReadyAPI.

Now, I would like to get this object instance and feed it regarding my environment execution. I have already known how to get the environment settings so the issue is only how /what are the statements to set DataSink parameters from a groovy script Teststep.


On SoapUiPro documentation, I have found this :
http://www.soapui.org/apidocs/pro/com/eviware/soapui/impl/wsdl/teststeps/datasink/ExcelDataSink.html#setFileName-java.lang.String-


First, I would like to be able to use these metods setFileName(path), setOutFileName(path), setWorksheet(worksheet), setStartCell(startCell) in order to provide the parameters to the DataSink instance.

I also would like loading properties from my first row of the ExcelFile and keep only those I want but in the class

documentation, I do not see any metod to add properties to the DataSink.

Does anyone have an idea of how to achieve both purposes?

Regards,

Harold

  • The first part you can handle by setting up the following groovy script:

     

    def dataSink = context.testCase.testSteps["DataSink"];
    def excel = dataSink.getDataSink();

    You would use the details on the link you posted on the excel variable to adjust the file paths and settings specific to the Excel data source. Example:

     

    excel.setFileName("C:\\temp\\Book1.xlsx");

    You would use the dataSink variable to adjust the actual properties/values of the Data Sink. Example:

    dataSink.setPropertyValue("PropertyName", "This Is My Property Value");

    Hope that helps!

     

2 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    The first part you can handle by setting up the following groovy script:

     

    def dataSink = context.testCase.testSteps["DataSink"];
    def excel = dataSink.getDataSink();

    You would use the details on the link you posted on the excel variable to adjust the file paths and settings specific to the Excel data source. Example:

     

    excel.setFileName("C:\\temp\\Book1.xlsx");

    You would use the dataSink variable to adjust the actual properties/values of the Data Sink. Example:

    dataSink.setPropertyValue("PropertyName", "This Is My Property Value");

    Hope that helps!

     

    • HaroldR's avatar
      HaroldR
      Contributor

      Hello groovyguy,

      That'it, thaks you. 

      Here, I share my script aaccording to my need :

      def dataSink = context.testCase.testSteps["ExcelDataSink"];
      def excel = dataSink.getDataSink();
      
      def environmentName = testRunner.testCase.testSuite.project.activeEnvironment.name;
      
      if (environmentName == "Integration"){
      	excel.setFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\fr-cevia-v2-vs_GenericTable.xls");
      	excel.setOutFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\INT\\CheckSdcAuthorisationTestSuite\\CheckSdcAuthorisationTestCaseResult[INT].xls");
      	excel.setWorksheet("CEVIA_V2");
      	excel.setEvaluateFormulas(false);
      	dataSink.setPropertyValue("CheckSdcAuthorisationTestCaseResult", '${#TestCase#Status}');
      	excel.setStartCell("K2");
      } else if (environmentName == "Recette"){
      	excel.setFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\fr-cevia-v2-vs_GenericTable.xls");
      	excel.setOutFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\REC\\CheckSdcAuthorisationTestSuite\\CheckSdcAuthorisationTestCaseResult[REC].xls");
      	excel.setWorksheet("CEVIA_V2");
      	excel.setEvaluateFormulas(false);
      	dataSink.setPropertyValue("CheckSdcAuthorisationTestCaseResult", '${#TestCase#Status}');
      	excel.setStartCell("K2");
      } else if (environmentName == "PreProd"){
      	excel.setFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\fr-cevia-v2-vs_GenericTable.xls");
      	excel.setOutFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\PP\\CheckSdcAuthorisationTestSuite\\CheckSdcAuthorisationTestCaseResult[PP].xls");
      	excel.setWorksheet("CEVIA_V2");
      	excel.setEvaluateFormulas(false);
      	dataSink.setPropertyValue("CheckSdcAuthorisationTestCaseResult", '${#TestCase#Status}');
      	excel.setStartCell("K2");
      } else if (environmentName == "Prod"){
      	excel.setFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\fr-cevia-v2-vs_GenericTable.xls");
      	excel.setOutFileName("E:\\SoapUi_Workspaces\\ProjectsToDeliver\\fr-cevia-v2-vs\\TestCaseResult\\PROD\\CheckSdcAuthorisationTestSuite\\CheckSdcAuthorisationTestCaseResult[PROD].xls");
      	excel.setWorksheet("CEVIA_V2");
      	excel.setEvaluateFormulas(false);
      	dataSink.setPropertyValue("CheckSdcAuthorisationTestCaseResult", '${#TestCase#Status}');
      	excel.setStartCell("K2");
      } else {
      	log.info("Default Environment");
      }