How to use relative path for file uploads

1,575 views
Skip to first unread message

Larry

unread,
Sep 3, 2013, 10:46:30 AM9/3/13
to seleniu...@googlegroups.com
I am trying to upload a file to the web app under test (easy enough to do).
However.. I would like to use a relative path (e.g. the path where my selenium TestScripts are run from), and not have to hardcode the path in my scripts.
How can I retrieve the path of my TestScript to possibly store into a variable and pass that?

Is it possible

Larry

p.s. Appologies if this has aleady been answered somewhere else, but I am new to selenium and this forum.

Hanish Jadala

unread,
Sep 3, 2013, 11:21:29 AM9/3/13
to seleniu...@googlegroups.com
Hi Larray

I understand your query this way you want to upload a file and and you can not able to do that if that is your query .
Solution is uploading is a desktop component so go for sikuli then you can achieve it.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f8cc5b53-1ea0-474f-b41a-592a70a0af26%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David

unread,
Sep 3, 2013, 1:47:16 PM9/3/13
to seleniu...@googlegroups.com
Well, you do know that you can write code to figure out what is your relative working directory of code/tests being executed right? The return value of such code can then be the relative path that you desire (e.g. the relative base path) that you then append to with the file you want to upload.

The exact code differs based on your programming language used. Search for get current working directory for your given language.

Larry

unread,
Sep 4, 2013, 5:01:19 AM9/4/13
to seleniu...@googlegroups.com
I have tried various code snippets (javascript) that I even copied from the web, to attempt to retrieve the FilePath of the Current Working Directory etc and I always get "null" as a result.
What would be useful is a means to find the path of my current Selenium Test Suite or Test Case that is being run, as this is the same path as my test document that I try to upload.

When submitting the filename and path together then the file is correctly uploaded however I want the test suite / scripts to be kept as a bundle that can be moved from one environment to another without concern about the path being exactly the same.
If I try without the path e.g. just filename or with .\<filename> etc then the primaryFile is not populated, hence no file uploaded.

Prasad Bodke

unread,
Sep 4, 2013, 5:45:58 AM9/4/13
to seleniu...@googlegroups.com
Hi
I am using this way.

String projectPath = null;
String filepath = null;

projectPath = System.getProperty("user.dir");
filepath = projectPath+"\\testdata\\SyxTestData.xls";


Regards
Prasad Bodke


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Prasad Bodke
9320675131

David Lai

unread,
Sep 4, 2013, 11:07:11 AM9/4/13
to seleniu...@googlegroups.com
For my tests, I created a class called, AssetManager.

What the AssetManager does is just fetch the path of a filename in my ProjectDir/assets folder.  This way I have a consistent way of fetching any file under /assets, no matter who checks it out and which OS it's checked out on.

David

unread,
Sep 4, 2013, 5:19:47 PM9/4/13
to seleniu...@googlegroups.com
Larry, unless your test suite / Selenium tests are written in Javascript, you're copying the wrong code snippets for current working directory. It should be more likely in Java, .NET, Python, Ruby, etc.

Also, if you combine the paths incorrectly, then it will of course be an invalid path. You can dump out the combined path string to command line/console to verify if path is correct.
Reply all
Reply to author
Forward
0 new messages