Selenium, PHPUnit, and AttachFile()

拜拜、爱过 提交于 2020-01-02 05:05:34

问题


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?


回答1:


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! : )




回答2:


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




回答3:


The code below works. Give it a try.

$this->byName('Name Locator')->value('/home/img/Desert.jpg');
$this->byName()->submit();
sleep(1);


来源:https://stackoverflow.com/questions/7168604/selenium-phpunit-and-attachfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!