Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium, PHPUnit, and AttachFile()

I am currently running Selenium commands through PHPUnit to a remote server. I've run into a problem where I am trying to upload an image to an input form.

In my PHPUnit, I have the command

$this->attachFile( 'file', 'file://test.png' );

My Selenium server returns an error

PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete().
java.lang.RuntimeException: Output already exists: /tmp/selenium2070373138020433468upload.

My test.png file is currently only located in the folder where I am executing my .php unit tests from.

How can I properly upload a file through PHPUnit and Selenium and get it to not throw an exception?

like image 231
Dan Chan Avatar asked Aug 23 '11 23:08

Dan Chan


People also ask

Can we upload/download file using selenium?

Uploading a File Using SeleniumIt's just a matter of sending the path of the file you want to upload to the text of the file-select input field. Then, you just have to click the Begin Upload button. By inspecting the elements on the page, you can find out that the button has the id js-file-input.


2 Answers

I had same problem. Then I found this article: http://bitsilearn.blogspot.com/2010/03/selenium-upload-files.html

So instead of using $this->attachFile('file', 'file://test.png') i have used:

$this->type('file', '/path/to/file');

and it works! : )

like image 150
Vitek Jezek Avatar answered Sep 27 '22 01:09

Vitek Jezek


My bit of experience: path to file must be prefixed with file:// (used on Windows platform).

like image 40
vojtechdobes Avatar answered Sep 26 '22 01:09

vojtechdobes