我想使用量角器和Firefox设置特定的用户代理。如果我在protractor.conf.js上使用directConnect,它将起作用:
//selenium-webdriver is installed via npm
var firefox = require('selenium-webdriver/firefox');
var firefoxProfile = new firefox.Profile();
firefoxProfile.setPreference("general.useragent.override", 'monitoring1152936086');
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'firefox',
'firefox_profile': firefoxProfile
},
...
}
但是,如果我使用seleniumAddress而不是directConnect,则它不起作用。测试工作正常,但未使用用户代理。我需要使用硒服务器。例如:
var firefox = require('selenium-webdriver/firefox');
var firefoxProfile = new firefox.Profile();
firefoxProfile.setPreference("general.useragent.override", 'monitoring1152936086');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'firefox',
'firefox_profile': firefoxProfile
},
...
}
附带说明一下,我无法使用chrome,因为我正在尝试使用Firefox作为不太稳定的量角器和selenium-docker与chrome组合的解决方法(https://github.com/SeleniumHQ/docker-selenium/issues/ 87)。
有任何想法吗?谢谢!
在直接连接的情况下,Protractor会自己创建浏览器,因此可以通过浏览器进行整体配置。在远程情况下,Protractor的控制较少,因为它正在连接到所启动的硒服务器webdriver-manager
。通过Firefox配置文件的正确时间是在webdriver-manager
启动时,但Protractor当前不提供此功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句