robotframework / OldSeleniumLibrary

Deprecated Selenium library for Robot Framework
Apache License 2.0
13 stars 3 forks source link

Support for using remote files with `Choose File` #108

Closed spooning closed 9 years ago

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 29 Mar 2010

Testing file upload on a local machine is easy with "Choose File" keyword which types the file name on Firefox only directly to the upload field. But testing uploads on a remote Selenium machine is only possible using attach_file method, which is currently not available in selenium robot library.

For those who want to test file uploads and are using remote Selenium RC servers (or Sauce Labs OnDemand) this new keyword will make a lot of sense and will add value.

The usage is nicely explained here: http://saucelabs.com/blog/index.php/2009/11/selenium-tip-of-the-week-upload-files-on-browsers-running-over-remote-machines/

Shortly, uploading works only with Firefox, the file must placed on a public http server in the top level directory.

Example use: | Attach File | css=input#upload-form | http://10.1.1.1/filetoupload.csv |

Code change to create the keyword is trivial - expose a function already available in selenium.py.

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 29 Mar 2010

Looks good. Can you Radek take care of adding the keyword with adequate documentation? Adding an acceptance test to this keyword is probably not worth the effort, especially because the keyword would just expose a function in the Selenium API.

Notice also that before this keyword is implemented, it's possible to use Call Selenium API keyword [1]. If this usage is "hidden" behind a user keyword, it's easy to replace it later when the new keyword is available.

[1] http://robotframework-seleniumlibrary.googlecode.com/svn/tags/robotframework-seleniumlibrary-2.3/doc/SeleniumLibrary.html#Call%20Selenium%20Api

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 1 Apr 2010

Keyword is available in revision 467

spooning commented 9 years ago

Originally submitted to Google Code by Andreas.EbbertKarroum on 2 May 2010

I have to admit, that I neither understand the documentation of the SeleniumLibrary keyword nor the original documentation:

http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/java/com/thoughtworks/selenium/Selenium.html#attachFile%28java.lang.String,%20java.lang.String%29

Is it just me? Maybe an example would help :)

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 3 May 2010

If I got it right, the idea of this keyword is to upload files when Selenium Server is running on a remote machine. When the server is running locally, it's possible to use old Choose File. Wouldn't it actually be better to enhance Choose File so that when the server is running on a remote machine it uses selenium.attach_file and otherwise it works as before?

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 3 May 2010

Good idea with merging it with Choose File. I can update the the code and write a better doc for it with an example.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 3 May 2010

But what if some one who already uses selenium library decided to upload the file to the remote selenium host using SSH? Choose File will work fine in that case.

Making the behavior of Choose File depend on the host might affect some users. We just don't know how are users using this keyword.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 3 May 2010

Maybe a good solution will be renaming Attach File to Choose Remote File and explaining the use. I'm rewriting the documentation in the meantime.

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 3 May 2010

Renaming this keyword to Choose Remote File is a good idea.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 3 May 2010

Renamed the keyword and updated the doc.

Revision: 32fe977421

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 3 May 2010

Autolinking in the previous comment didn't work. Revision 32fe977421 ought to work better.

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 3 May 2010

I was reviewing the doc when I realized that adding this functionality to Choose File keyword is probably still better than adding new keyword. We could simply look does the file_path given to Choose File start with http:// or https:// and use selenium.attach_file in that case. That would make documenting this new keyword easier too.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 3 May 2010

Sounds great. I will make a change tomorrow morning.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 4 May 2010

I merged both functions. Revision f9181bdc0d

I saw a note in the documentation for Choose File that from version 2.2.2 the existence of the file_path will not be checked. The code does check the file:

if not os.path.isfile(file_path):
    self._info("The path '%s' does not exists in local file system." % file_path)
spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 4 May 2010

I simplified the documentation in revision e5348dfb07. Do you Radek think that's enough?

I removed the comment about SeLib 2.2.2 because we are already in 2.3 (and the next release could actually be 2.4). In older versions this keyword failed when the file didn't exist on the local machine. When that limitation was removed ( issue 56 ) we decided to write a message when the file doesn't exist to make debugging easier in case the path is invalid.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 4 May 2010

I think that is better. Thanx!

spooning commented 9 years ago

Originally submitted to Google Code by @pekkaklarck on 4 May 2010

I added some more info to the doc in revision 5d3dba9878.

I also generated the doc and the latest version is available at: http://robotframework-seleniumlibrary.googlecode.com/hg/doc/SeleniumLibrary.html#Choose%20File

Radek, please change the status to Done if you don't have anything more to add and are happy with the implementation. Btw, have you tested this in real environment? As we discussed earlier, adding automated tests for this isn't worth the effort.

spooning commented 9 years ago

Originally submitted to Google Code by radekw13 on 4 May 2010

Yes, I tested it before committing. Closing the issue...

spooning commented 9 years ago

Originally submitted to Google Code by @yanne on 27 May 2010

Major improvements warrant a major version