Q:

Mink + PhantomJS: How do I set the user agent?

I am using phantomjs with mink:
default:
  extensions:
    Behat\MinkExtension\Extension:
      goutte: ~
      selenium2:
        browser: phantomjs
        wd_host: http://localhost:8643/wd/hub
        capabilities:
           webStorageEnabled: true

But I need to masquerade as the latest chrome. I have tried this:
    /**
     * @BeforeStep
     */
    public function masqueradeAsLatestChrome(StepEvent $event)
    {
        $this->getSession()->setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36');
    }

But I get the exception:
[Behat\Mink\Exception\UnsupportedDriverActionException]                                                
Exception has been thrown in "beforeStep" hook, defined in FeatureContext::masqueradeAsLatestChrome()  
Request header is not supported by Behat\Mink\Driver\Selenium2Driver

The version of chrome isn't critical but the web application must think its talking to a very recent version of chrome.

A:

Selenium does not provide this capability, as it is not something a
  user can do. It's recommended you use a proxy to inject additional
  headers to the requests generated by the browser.

https://code.google.com/p/selenium/issues/detail?id=2047#c1
Sadly… However, the PhantomJS does provide an interface for setting the headers. Your best shot would be to send a direct command to it using it's REST API. There's also a cool PHP wrap library that would make it 200 times easier.

A:

You should use the new Behat/Mink driver made by Juan Francisco Calderón Zumba
https://github.com/jcalderonzumba
Here is a direct link to the driver https://github.com/jcalderonzumba/MinkPhantomJSDriver
This driver allows you to specify the request headers that you need
(It works with Behat 3.0 but I think it requires at least PHP 5.4)

