Forum Discussion

d82ej9dut's avatar
d82ej9dut
Occasional Contributor
8 years ago

Outbounde Exception the second time that I try to read an Excel with SoapUI

Hello everybody.

 

I'm trying to read the datas of an excel with the objects

 

wb = Workbook.getWorkbook(new File('C:/Users/Franciscog/Desktop/papageno1.xls')) 

 

It works fine the first time that I use, but the second time, I get this message:

java.lang.ArrayIndexOutOfBound.Exception:0error at line: 12

 

I have to add new rows and columns to the excel in order to make it works again. Any idea of why is it?

 

Thanks a lot in advance

  • Hello again.

     

    Really, I would not need anything of xml, it is just the code that I found for reading datas from an Excel. Now I got this new one that is better.  

     

    I need this because I should send messages of vehicles that has some of their fields with just some allowed values, for example, odometer unit: Milles, Hours or Kilometres. Then, I would like to put all those values in an excel and take them for each message (I should send the same number of messages as possible values).

     

    Thanks you and best regards.

     

     

  • nmrao's avatar
    nmrao
    8 years ago

    d82ej9dut,

     

    There is simple way to achieve the same differently.

     

    Create a .csv file for valid values for odometer as shown below:

     

    odometer.csv - contents of the file

     

    odometer
    Miles
    Hours
    Kilometres

     

    Download xlson library and its dependency  

    For more details about xlson library, visit github

     

    Here is the script which reads the above csv file and selects one of values randomly

    import static com.xlson.groovycsv.CsvParser.parseCsv
    //Provide the file path of odometer csv 
    def data = parseCsv(new File('/tmp/odometer.csv').text)
    def odometerUnits = data*.values.flatten()
    //Randomly selects
    def selectedValue = odometerUnits[new Random().nextInt(odometerUnits.size())]
    log.info "Current selection: $selectedValue"

     

  • sanj's avatar
    sanj
    Super Contributor

    Just an thought

    may you need to initialize where you starting from.

    just a thought I got no clue what you trying to do

     

    • groovyguy's avatar
      groovyguy
      Community Hero

      If you could provide more details and/or your groovy script, it would help to troubleshoot. 

  • d82ej9dut's avatar
    d82ej9dut
    Occasional Contributor

    Thanks for your answer.

     

    I'm trying to read the datas from an excel. I have tried with this code that I found in Internet, but it is quite strange, because when I execute it for the first time, it works fine, but the second time, I get the error and the creation of the 'getWorkbook' line. However, if I add another row or column to the excel, it works again the first time but in the second fails again.

     

    I have attached the code and the excel (97), I hope it is going to help.

     

    Thanks a lot again.

  • d82ej9dut's avatar
    d82ej9dut
    Occasional Contributor

    The idea would be to take the datas from the excel in order to put it as the values of different fields for a testing of "allowed values". I'm looking for a way to do that and I found this code.

     

    Thanks in advance.

     

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      No, i was not asking for that.

      You also have some xml, I was not sure why was that.

      Have you tried data driven test?

      How are you going to use the data that is read? (otherwise you do not do this exercise right?) That would help understand the use case.
  • d82ej9dut's avatar
    d82ej9dut
    Occasional Contributor

    Hello again.

     

    Really, I would not need anything of xml, it is just the code that I found for reading datas from an Excel. Now I got this new one that is better.  

     

    I need this because I should send messages of vehicles that has some of their fields with just some allowed values, for example, odometer unit: Milles, Hours or Kilometres. Then, I would like to put all those values in an excel and take them for each message (I should send the same number of messages as possible values).

     

    Thanks you and best regards.

     

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      Is the above mentioned exception gone with this attached code?
  • d82ej9dut's avatar
    d82ej9dut
    Occasional Contributor

    Hello Rao.

     

    Yes, with the last code that I have attached, I had no problem anymore.

     

    Thanks a lots and best regards. 

    • nmrao's avatar
      nmrao
      Champion Level 3

      d82ej9dut,

       

      There is simple way to achieve the same differently.

       

      Create a .csv file for valid values for odometer as shown below:

       

      odometer.csv - contents of the file

       

      odometer
      Miles
      Hours
      Kilometres

       

      Download xlson library and its dependency  

      For more details about xlson library, visit github

       

      Here is the script which reads the above csv file and selects one of values randomly

      import static com.xlson.groovycsv.CsvParser.parseCsv
      //Provide the file path of odometer csv 
      def data = parseCsv(new File('/tmp/odometer.csv').text)
      def odometerUnits = data*.values.flatten()
      //Randomly selects
      def selectedValue = odometerUnits[new Random().nextInt(odometerUnits.size())]
      log.info "Current selection: $selectedValue"