我正在使用protractor,当我指定chrome作为浏览器类型时,它就可以工作了。我正在寻找一个无头浏览器示例代码,我已经寻找了phantomJs,但我不能运行它们中的任何一个。有没有另一种无头浏览器的工作样本?
发布于 2014-10-14 21:13:43
除了PhantomJS之外,没有其他的无头浏览器,而后者是Protractor的死胡同。
您可以尝试使用docker-selenium,或者,如果您不喜欢Docker,也可以使用ubuntu-headless sample自己完成。这两种解决方案都通过使用Xvfb提供Chrome和Firefox,即使没有真正的显示。
Xvfbupdate2似乎可以在OSX中运行:http://xquartz.macosforge.org/landing/
更新1 Mac无头解决方案:
启用对OSX计算机的多用户远程桌面访问
所以可以在mac上测试selenium无头。实际上不是无头的,而是作为另一个用户,这样它就不会干扰当前用户的显示。为此,您需要kickstart:http://support.apple.com/en-us/HT201710开始使用kickstart实用程序
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent激活远程桌面共享,为所有用户启用访问权限并重新启动ARD代理:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all 仅Apple Remote Desktop 3.2或更高版本
允许所有用户访问并为所有用户提供完全访问权限
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -allKickstart帮助命令
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help发布于 2015-03-21 01:46:42
在某些网站上,如果有一个PhantomJS,它是固定的并且总是可见的(由于https://github.com/ariya/phantomjs/issues/11637),那么它就是一个带有量角器的死胡同。否则,您可以让它工作:
使用phantomjs:~1.9.0和量角器:~1.8.0
在量角器配置文件寄存器函数内部:
onPrepare : function() {
var minWindowWidth = 1024,
minWindowHeight = 768,
browserName,
platform,
window = browser.manage().window();
browser.getCapabilities().then(function (capabilities) {
browserName = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function getCurrentWindowSize() {
return window.getSize();
}).then(function setWindowSize(dimensions) {
var windowWidth = Math.max(dimensions.width, minWindowWidth),
windowHeight = Math.max(dimensions.height, minWindowHeight);
return window.setSize(windowWidth, windowHeight);
}).then(function getUpdatedWindowSize() {
return window.getSize();
}).then(function showWindowSize(dimensions) {
console.log('Browser:', browserName, 'on', platform, 'at', dimensions.width + 'x' + dimensions.height);
console.log("Running e2e tests...");
});
},https://stackoverflow.com/questions/26360592
复制相似问题