Forum Discussion

Clear_Capital__'s avatar
Clear_Capital__
Contributor
11 years ago

[Rs]DataSource -> Directory : need access to the file name i

I am looping through and read xml files using DataSource -> Directory feature. I have a need to access the xml file name for a given loop iteration in the groovy script test step, either just the xml file name or the full path . How do I do that ?

Thank you

8 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    There's a special workaround for this case. If you define the property "Filename" (note the lower case n!), you will get the relative file name there.

    To get the file name, use the code

    testRunner.testCase.getTestStepByName("YourDataSource").getProperty("Filename").value

    ... where "YourDataSource" is the name of your data source.

    Hope this helps!

    Manne, SoapUI developer
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can access the filename with this script,

    def name = testRunner.testCase.getTestStepByName("DataSource").getDataSource().getFileName()
    log.info name


    Thanks,
    Jeshtha
  • For the the response Jeshtha

    This gives me the directory/folder path name to the file, without the file name.

    gives me
    ..../xmlfolder/

    what I want is

    .../xmlfolder/myFile.xml
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    I am sorry but this will fetch the filename,

    def val = testRunner.testCase.getTestStepByName("DataSource").getDataSource().getFilter()
    log.info val


    Thanks,
    Jeshtha
  • its fetching literally the filter, not the filename. Here is its output.

    Thu Feb 27 14:22:17 PST 2014:INFO:*.xml

    As you would see in the screen shot earlier, *.xml is the filter I am using to look for just xml file.
  • Manne,

    This worked. It answers my questions. Just curious if there is way to get the full path instead of just file name. I suspect I may need this in near future.

    Thank you

    Jignesh
  • Never mind, you had already replied on how to get the path in the first reply

    def name = testRunner.testCase.getTestStepByName("DataSource").getDataSource().getFileName()

    I am all good now.
    Thanks again.
  • Manne,

    When I renamed

    DataSource -> FileContent property to
    DataSource -> Filename

    Filename property now had data source file name (say myXYZ.xml ) . So the problem with that is, I am losing the content of myXYZ.xml . To fix that , I created two properties, with same DataSource configuration (Directory / Filename Filter)

    DataSource -> FileContent to read the content of myXYZ.xml
    DataSource -> Filename to get the name of myXYZ.xml

    SoapUI does not name these names, there seems to be some conflicts. So my soap request started failing.

    To fix this, I renamed the one of the properties

    DataSource -> xmlContent to read the content of myXYZ.xml
    DataSource -> Filename to get the name of myXYZ.xml

    and this works now.

    Just letting you know. Seems like the features of "Directory" datasource are not fully tested and baked in.

    Thanks

    Jignesh