Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attachFile does not work with PhantomJS #1823

Closed
schmitzc opened this issue Mar 31, 2015 · 23 comments
Closed

attachFile does not work with PhantomJS #1823

schmitzc opened this issue Mar 31, 2015 · 23 comments

Comments

@schmitzc
Copy link

@schmitzc schmitzc commented Mar 31, 2015

I've tracked down the issue to this line in the WebDriver module:

$el->setFileDetector(new \LocalFileDetector);

If I remove this line, attachFile works in PhantomJS. Is this something that only works in Selenium?

@schmitzc schmitzc changed the title attachFile does not work with PhatomJS attachFile does not work with PhantomJS Apr 1, 2015
@Jaironlanda
Copy link

@Jaironlanda Jaironlanda commented Sep 29, 2015

How to fix it?

@natenolting
Copy link

@natenolting natenolting commented Sep 29, 2015

@schmitzc what's the error your getting? I'm running PhantomJs also. Mine is:

 [Facebook\WebDriver\Exception\WebDriverException] JSON decoding of remote response failed.
Error code: 4
The response: 'Error - incompatible type of argument(s) in call to _uploadFile(); candidates were
    _uploadFile(QString,QStringList)’

$I->attachFile({"name”:"file_field"},”image.png”)
@friparia
Copy link

@friparia friparia commented Nov 18, 2015

I meet this error too. I found it a bug in phantomjs 2.0, but my version is 2.0.1-development, still have this problem

@natenolting
Copy link

@natenolting natenolting commented Nov 18, 2015

@friparia I had to switch to Selenium to make file uploads work, no way around it I could see.

@friparia
Copy link

@friparia friparia commented Nov 19, 2015

@natenolting thanks, but my test environment doesn't have graphic interface, so i find no way to install firefox or chrome..

@natenolting
Copy link

@natenolting natenolting commented Nov 19, 2015

@friparia you can run Selenium headless, I set Selenium and Firefox up it inside a vagrant box with this script https://gist.github.com/natenolting/ed2bf2abfe444776aad4

@friparia
Copy link

@friparia friparia commented Nov 20, 2015

@natenolting it works! thanks!

@natenolting
Copy link

@natenolting natenolting commented Nov 20, 2015

Great!

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Jan 24, 2016

It was an issue of PhantomJS and it appears to be fixed in PhantomJS 2.1.0

@Naktibalda Naktibalda closed this Jan 24, 2016
@agarzon
Copy link
Contributor

@agarzon agarzon commented Jan 29, 2016

I'm running PhantomJS version 2.1.1 and the issue with codeception still existing. Not able to use attachFile.

@Naktibalda Naktibalda reopened this Jan 29, 2016
@agarzon
Copy link
Contributor

@agarzon agarzon commented Jan 29, 2016

Thank you @Naktibalda .

In order to provide more info:

  [Facebook\WebDriver\Exception\WebDriverException] JSON decoding of remote response failed.
Error code: 4
The response: 'Error - incompatible type of argument(s) in call to _uploadFile(); candidates were
    _uploadFile(QString,QStringList)'

Going back for Selenium, yes it works... but that does fix the issue with PhantomJS.

@pivulic
Copy link

@pivulic pivulic commented Jan 30, 2016

I have the same problem as @natenolting and @agarzon, even after updating to 2.1.1.

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Jan 30, 2016

ariya/phantomjs#13302 (comment)
There is another suggestion to use UselessFileDetector instead of LocalFileDetector.

Could you modify attachFile method and see if it solves the issue?

@pivulic
Copy link

@pivulic pivulic commented Jan 31, 2016

@Naktibalda, thanks, that solves my problem :) But will this be changed in Codeception so that one doesn't have to patch this file manually?

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Jan 31, 2016

@DavertMik @zbateson

When LocalFileDetector is used, WebDriver uploads file to remote instance of Selenium or PhantomJS,
When UselessFileDetector is used, WebDriver does not upload the file, so it only works when Selenium or PhantomJs is running on the same server as Codeception.

File upload to PhantomJS is broken, so we have to use UselessFileDetector,
but some of our users need LocalFileDetector, because they are using remote Selenium servers.

Codecetion doesn't know if remote instance is PhantomJS so we can't do something like if (isPhantom).

The simplest solution I can image is

if ($this->config['host'] === '127.0.0.1' || $this->config['host'] === 'localhost') {
    $el->setFileDetector(new UselessFileDetector);
} else {
    $el->setFileDetector(new LocalFileDetector);
}

Have you got any better ideas?

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Feb 3, 2016

Codecetion doesn't know if remote instance is PhantomJS so we can't do something like if (isPhantom)

Actually, we can do it like:

if ($this->config['browser'] == 'phantomjs')

I think we need to have such detection, probably there will be a need for other phantom-specific patches.

@DavertMik DavertMik closed this in d45244c Feb 5, 2016
@pivulic
Copy link

@pivulic pivulic commented Feb 5, 2016

Thanks @DavertMik for fixing this, but can you release a new tag, i.e. 2.1.6, where this fix is included?

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Feb 5, 2016

I haven't had time to test it, but I want to make a note that browser setting has no effect on phantomjs, so the users will have to set it specifically to avoid this file upload issue.

When I tested phantomjs, I ran tests with browser: firefox

WebDriver module documentation does not tell to set browser: phantomjs.
@DavertMik Please update documentation, if you think that this issue can be solved by configuration.

@Naktibalda Naktibalda reopened this Feb 5, 2016
@paulsheldrake
Copy link

@paulsheldrake paulsheldrake commented Feb 6, 2016

I tested what @Naktibalda suggested by changing the browser to firefox and that didn't work

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Feb 7, 2016

Thanks @DavertMik for fixing this, but can you release a new tag, i.e. 2.1.6, where this fix is included?

Yes, that's what I'm aiming for at the moment. I will also need to update docs.

I tested what @Naktibalda suggested by changing the browser to firefox and that didn't work

That's not what he suggested. Please get the latest release from 2.1 branch and change your browser to phantomjs to get a hotfix.

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Feb 7, 2016

Updated docs, and more importantly added PhantomJS to our CI suite! https://semaphoreci.com/codeception/codeception/branches/2-1

  • Chrome tests as well )

Looks almost ready for a new release

@DavertMik DavertMik closed this Feb 7, 2016
@paulsheldrake
Copy link

@paulsheldrake paulsheldrake commented Feb 10, 2016

@pivulic This has been release in 2.1.6

@acidjazz
Copy link

@acidjazz acidjazz commented Mar 9, 2017

anyone looking to do this in Laravel Dusk

$file_input = $browser->driver->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('.input-image > input'));
$file_input->setFileDetector(new \Facebook\WebDriver\Remote\LocalFileDetector());
$file_input->sendKeys(__DIR__.'/images/logo.png');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants
You can’t perform that action at this time.