我正在对mink使用phantomjs:
default:
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
browser: phantomjs
wd_host: http://localhost:8643/wd/hub
capabilities:
webStorageEnabled: true但我需要伪装成最新的chrome。我已经尝试过了:
/**
* @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');
}但我得到了一个例外:
[Behat\Mink\Exception\UnsupportedDriverActionException]
Exception has been thrown in "beforeStep" hook, defined in FeatureContext::masqueradeAsLatestChrome()
Request header is not supported by Behat\Mink\Driver\Selenium2Driverchrome的版本并不重要,但web应用程序一定认为它是在与最新版本的chrome对话。
发布于 2014-08-15 14:42:53
Selenium不提供此功能,因为它不是用户可以执行的操作。建议您使用代理向浏览器生成的请求注入额外的头。
https://code.google.com/p/selenium/issues/detail?id=2047#c1
可悲的是…但是,PhantomJS确实提供了interface for setting the headers。最好的办法是使用它的REST API直接向它发送一个命令。还有一个很酷的PHP wrap library,可以让它变得简单200倍。
发布于 2015-12-29 18:59:15
你应该使用Juan Francisco Calderón Zumba https://github.com/jcalderonzumba制造的新的Behat/Mink驱动程序
下面是到驱动程序https://github.com/jcalderonzumba/MinkPhantomJSDriver的直接链接
此驱动程序允许您指定所需的请求头(它适用于Behat 3.0,但我认为它至少需要PHP 5.4)
发布于 2017-02-21 19:18:22
您可以通过传递selenium2driver中的其他设置
extra_capabilities:所以在你的例子中:
default:
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
browser: phantomjs
wd_host: http://localhost:8643/wd/hub
capabilities:
webStorageEnabled: true
extra_capabilities:
phantomjs.page.settings.userAgent: "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36"https://stackoverflow.com/questions/25319882
复制相似问题