giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
600 stars 271 forks source link

Support for :sessionId/file #245

Open chr0n1x opened 11 years ago

chr0n1x commented 11 years ago

Something like this

I wouldn't mind making a PR but I kind of don't know where to start.

giorgiosironi commented 11 years ago

This seem to be an undocumented feature of Selenium (no trace of :sessionId/file at http://code.google.com/p/selenium/wiki/JsonWireProtocol). Do you know where we can find some info on how does that work (e.g. what to do after uploading)?

chr0n1x commented 11 years ago

That was in my PR to the facebook guys.

Forgive me if the following details are wrong, I just got it to work a few months back and haven't had the time to fully investigate since haha

From what I can tell it transfers the file, which apparently must be a ZIP archive, to the remote RC. The remote RC then unpacks it into a session workspace (where the standalone RC is running from I think) and returns JSON with a value attribute that is the unpacked file's path on the remote machine, which can then be used for file uploads.

I'm not sure if they planned to support this in the long run since, as you pointed out, it's not in the JsonWireProtocol wiki.

giorgiosironi commented 11 years ago

If you want to make a PR, I will accept it and mark the method as @deprecated to mark its lack of official support. For the PR, you should create a new Command object under Selenium2TestCase/SessionCommand. The test should be put inside Tests/Selenium2TestCase/ but it has a problem as currently the selenium-1-tests file with fixtures is static and does not allow .php files. A dynamic script accepting a file upload would be needed.

Giorgio Sironi (@giorgiosironi) http://giorgiosironi.com http://giorgiosironi.blogspot.com/

chr0n1x commented 11 years ago

Ok, I'll give it a shot at some point. Thanks!

chr0n1x commented 11 years ago

@giorgiosironi here's what I've changed / added. Please let me know if you have any concerns with the format of the code or what it does. I've tweaked the code so that when $this->getSession()->file( $file ); is called, it returns the FQ path to the transferred file on the remote machine.

I'm not totally sure how to begin testing though. What are the standards of the test directory? Do I just add test cases into the various files? Or should I just make a new test class and put all cases in there just for this new class? I'm kind of at a loss as to how it works.

EDIT: and because I don't really understand how the tests operate, I have no idea where to begin with the dynamic script.

Should I just...stub out that functionality?

chr0n1x commented 11 years ago

Also, for your convenience: https://github.com/sebastianbergmann/phpunit-selenium/pull/248

chr0n1x commented 11 years ago

@giorgiosironi ping. I've been trying to write tests but no luck, not even with running them. I'm on CentOS, and...am just plain lost.

giorgiosironi commented 11 years ago

The biggest problem is the fixture folder selenium-1-tests currently is served with Python, so we can't put a .php there. I will take a look at serving it with PHP own's web server on version 5.4 so that a script receiving the file via POST can be put there.

chr0n1x commented 11 years ago

@giorgiosironi thank you! Let me know when that's ready.

Also, would you like me to re-open the PR to your forked repo? I just realized that the README says to direct it at giorgiosironi/phpunit-selenium. Sorry about that!

giorgiosironi commented 11 years ago

No worries for this particular PR, it can be merged here; direct to my repository for future ones. With https://github.com/giorgiosironi/phpunit-selenium/commit/f659676d98297cc2d57934c0a7e27e7278d7b02b I've added the possibility to run a PHP 5.4 web server and a sandbox named file_upload.php. If you are on PHP 5.4, you can run before_script.sh to setup the server and use that for running a test of the upload command. The sandbox has a 'file' input and a submit button, and displays the file name and size after upload for assertions; use a small file size due to limitations in php.ini and Selenium itself.

chr0n1x commented 11 years ago

@giorgiosironi Excellent! Thank you for doing that, I'll be looking at it today :)