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

Comments

Projects
None yet
10 participants
@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 from attachFile does not work with PhatomJS to attachFile does not work with PhantomJS Apr 1, 2015

@Jaironlanda

This comment has been minimized.

Show comment
Hide comment
@Jaironlanda

Jaironlanda Sep 29, 2015

How to fix it?

Jaironlanda commented Sep 29, 2015

How to fix it?

@natenolting

This comment has been minimized.

Show comment
Hide comment
@natenolting

natenolting 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”)

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

This comment has been minimized.

Show comment
Hide comment
@friparia

friparia 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

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

This comment has been minimized.

Show comment
Hide comment
@natenolting

natenolting Nov 18, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@friparia

friparia Nov 19, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@natenolting

natenolting 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

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

This comment has been minimized.

Show comment
Hide comment
@friparia

friparia Nov 20, 2015

@natenolting it works! thanks!

friparia commented Nov 20, 2015

@natenolting it works! thanks!

@natenolting

This comment has been minimized.

Show comment
Hide comment
@natenolting

natenolting commented Nov 20, 2015

Great!

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 24, 2016

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@agarzon

agarzon Jan 29, 2016

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@agarzon

agarzon Jan 29, 2016

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@pivulic

pivulic Jan 30, 2016

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

pivulic commented Jan 30, 2016

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

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 30, 2016

Member

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?

Member

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

This comment has been minimized.

Show comment
Hide comment
@pivulic

pivulic 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?

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

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 31, 2016

Member

@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?

Member

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

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 3, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@pivulic

pivulic 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?

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

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Feb 5, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@paulsheldrake

paulsheldrake Feb 6, 2016

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

paulsheldrake commented Feb 6, 2016

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

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 7, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 7, 2016

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@paulsheldrake

paulsheldrake Feb 10, 2016

@pivulic This has been release in 2.1.6

paulsheldrake commented Feb 10, 2016

@pivulic This has been release in 2.1.6

@acidjazz

This comment has been minimized.

Show comment
Hide comment
@acidjazz

acidjazz 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');

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