Page 1 of 1

Storing and Using Test Files from Project Folder

Posted: Wed Mar 14, 2018 8:23 pm
by karltinsly
I have been searching the forum for a while but haven't been able to find the solution to my problem. Hopefully I can get the answers I need by asking directly.

I have a test that involves logging into an application and uploading a PDF file. I have the PDF file stored in the solution folder, but I run/work on this solution from multiple locations, and each time I have to update the file location to be entered in the application to upload the file. Is there a way to have the path to test file always be the same? I've seen some workarounds that use user code to get the path to the test executable directory - is that still the way to do it? If so, could someone provide a little more explanation of how it's done?

Thanks!

Re: Storing and Using Test Files from Project Folder

Posted: Thu Mar 15, 2018 2:20 pm
by krstcs
First, you should be setting the file to be always copied to the output folder, if you aren't already. This will put it in the same directory as your project's executables, so you can just copy the whole directory where ever you need to run the test.

Then, all you need to do is change your path in your tests to ".\MyPDFFileName.PDF" and the test should find it. The ".\" in Windows means to look in the current directory.

Re: Storing and Using Test Files from Project Folder

Posted: Mon Mar 19, 2018 7:42 pm
by karltinsly
Thanks for your reply. I tried your suggestion, but it didn't work for me. Perhaps with some tweaking? Here's what's happening:

I copied my test document (TestDoc.docx) to the test executable directory. My script opens the application I'm testing and clicks a button to upload a file. This opens a file browser, into which it types the full path and file name. The file browser doesn't recognize .\TestDoc.docx, so the test fails.

Is there a way to get ranorex to evaluate the .\ and enter the actual value in the file browser? Or save the value of .\ as a variable and use that somehow?

Thanks again for your help!

Re: Storing and Using Test Files from Project Folder

Posted: Mon Mar 19, 2018 8:30 pm
by karltinsly
My apologies - your original suggestion does work! I was not seeing what I thought I would see, but it was in fact working.

Thanks again!

Re: Storing and Using Test Files from Project Folder

Posted: Mon Mar 19, 2018 8:47 pm
by krstcs
You're welcome! Glad it helped!