Storing and Using Test Files from Project Folder

Best practices, code snippets for common functionality, examples, and guidelines.
karltinsly
Posts: 43
Joined: Tue Jun 07, 2016 9:59 pm

Storing and Using Test Files from Project Folder

Post by karltinsly » Wed Mar 14, 2018 8:23 pm

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!

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Storing and Using Test Files from Project Folder

Post by krstcs » Thu Mar 15, 2018 2:20 pm

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.
Shortcuts usually aren't...

karltinsly
Posts: 43
Joined: Tue Jun 07, 2016 9:59 pm

Re: Storing and Using Test Files from Project Folder

Post by karltinsly » Mon Mar 19, 2018 7:42 pm

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!

karltinsly
Posts: 43
Joined: Tue Jun 07, 2016 9:59 pm

Re: Storing and Using Test Files from Project Folder

Post by karltinsly » Mon Mar 19, 2018 8:30 pm

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!

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Storing and Using Test Files from Project Folder

Post by krstcs » Mon Mar 19, 2018 8:47 pm

You're welcome! Glad it helped!
Shortcuts usually aren't...