Forum Discussion

Sandia_National's avatar
Sandia_National
Occasional Contributor
12 years ago

Want the name of the file loaded into DataSource.

Hi All,

Newbie here.

I've successfully used a DataSource loaded up with an Excel spreadsheet. Sweet!

Now, down in another Step, I'd like to know the name of that file. Is it stored away in some property? I'm getting the columns of the spreadsheet just fine.

To make sure I've described it: I Browsed to my .xls file in the DataSource. That filename is displayed in the File: textbox of the DataSource editor. I would like, in a subsequent TestStep of the same TestCase, to know that filename.

Cheers,
--Bob

5 Replies

  • Sandia_National's avatar
    Sandia_National
    Occasional Contributor
    Oh. The "subsequent TestStep" is a groovy step, if that matters.
    I looked around in the javadocs for something like a "DataSourceStep" class, but only found stuff about a DataSourceConfig, and couldn't figure out how to use it (nor to get one, even if I knew how to use it).

    BTW, the javadocs were very hard for me to find. Did I just miss the big "API" button somewhere?

    Cheers,
    --Bob
  • Can you please attach your project along with the steps that you are taking to see if we can retrieve the file? Thanks.

    Regards,
    Temil
  • Sandia_National's avatar
    Sandia_National
    Occasional Contributor
    Hi Temil,
    Here's a sample project and a little spreadsheet (Assuming I figure out how to upload them).

    I put some comments into the "Groovy Script" test step, in the "TestCase 1" teardown method, and in the "Groovy Script Lead" test step. These describe what I am hoping to do.

    In short, the DataSource is configured to load the Excel file: C:/Users/bwhiteside/example/Book1.xls. In the TestCase teardown, I'd like to be able to read that filename so I can write a little report right beside the spreadsheet. In C:/Users/bwhiteside/example/Book1.html, for example.

    As a bonus wish, it would be awesome if a test step previous to the DataSource could *write* that filename. I could then write an "outer loop" over spreadsheets.

    Cheers,
    --Bob
  • Sandia_National's avatar
    Sandia_National
    Occasional Contributor
    I did find the filename. I get it from:

    testCase.getTestStepByName("DataSource").datasource.filename


    Part of my confusion arose because the class involved, ExcelDataSource, is not included in the javadocs that I found at http://www.soapui.org/apidocs/index.html
    Is there a better url I should use? Did some packages get intentionally left out of the docs?

    Now that I've found it, I note that there's a setter for the filname. Any chance you could tell me how to use it? I tried just setting the filename, but the it didn't seem to work. There are other methods in that class, like load() for example, that are possibly needed after setting the filename, but I dunno.

    Cheers,
    --Bob
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hey Bob,

    The reason why you didn't find the ExcelDataSource class in the API docs is that you were looking at the SoapUI open source docs and not the SoapUI Pro docs. You can find those here:
    http://www.soapui.org/apidocs/pro/index.html

    Regarding the file name setter, in what way does it not work? Is the actual file name not updated, or is it not updated inside SoapUI? Does the behavior change if you restart the program after setting the file name?

    Regards,

    Arian
    SmartBear Sweden