Test step to import file, partial file name is known
Hey all, I'm a beginner at this so bear with me ...
I am trying to import a file from a specific Windows folder that is created with a unique file name by my API that includes a reference number that I sent.
A request is sent POST to the REST API with 16 digit reference number that I generate randomly for the request. The API I am testing responds to the POST with an Initial Response and creating a file using the reference number along with specific text, and at the end a date/time stamp (to maintain a unique file name) so the file looks something like this ...
response_1234567890123456_0122123526.xml
After nearly a minute, the API creates another file intended as the final response with data the API requested from the service. The file name used contains the same text and the reference number except the time stamp is new AND is located in a "FinalResp" folder. looks like this ...
response_1234567890123456_0122123641.xml
I researched several different ways to select this specific file to use its contents for validation, but the problem is I dont know what the actual file name is ...
I tried in Groovy to copy the response_1234567890123456 using the "*" wildcard to a different folder, unsuccessful ... I dont think Groovy has a method to copy files using wildcards.
I tried to use a wildcard in a property and transfered the property into a file wait test step, but the step failed as it doesnt like the wildcard.
I know the text and reference number, but I dont know what the stamp will be...
I am thinking that if I could use Groovy script to create an Array from the contents of the "FinalResp" folder, I can search the array using "Contains" for the reference number, then I will have the full file name to import the contents of the XML for validation.
I do NOT have any idea how to do this in Groovy. Ideas? someone have a useful snippet?
Please? and thanks
Some of these examples might help to find files by name.
http://www.javaworld.com/article/2073169/finding-files-by-name-with-groovy.html
http://docs.groovy-lang.org/2.4.7/html/gapi/groovy/util/FileNameFinder.html