[英]Selenium - set headers in headless browser
I'm trying to run a simple test on a headless browser. 我正在尝试在无头浏览器上运行一个简单的测试。 In my sample test when I take a screenshot I just get a blank screen when accessing my staging website, but production websites such as http://www.google.co.uk work correctly.
在我的示例测试中,当我截取屏幕截图时,访问登台网站时只会出现空白屏幕,但是生产网站(例如http://www.google.co.uk)可以正常工作。 So I guess we need to set headers in order to access our staging?
所以我想我们需要设置标题以便访问我们的暂存区吗?
Does anyone know how to do this on selenium for a headless browser? 有谁知道如何针对无头浏览器在硒上执行此操作?
The code I have is: 我的代码是:
public void testPhantom() throws IOException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs");
Webdriver driver = new PhantomJSDriver(caps);
open("https://mywebsite.staging.com/");
takeAScreenshot("Website");
}
================================================== ==================================================
UPDATE 更新
Found the solution by reading this post: PhantomJSDriver works for HTTP but not for HTTPS 通过阅读这篇文章找到了解决方案: PhantomJSDriver适用于HTTP但不适用于HTTPS
I have not tested this personally, but the GhostDriver documentation has the following at https://github.com/detro/ghostdriver#what-extra-webdriver-capabilities-ghostdriver-offers 我没有亲自测试过,但是GhostDriver文档在https://github.com/detro/ghostdriver#what-extra-webdriver-capabilities-ghostdriver-offers中具有以下内容
phantomjs.page.customHeaders.HEADER = VALUE - Add extra HTTP Headers when loading a URL
phantomjs.page.customHeaders.HEADER = VALUE-加载URL时添加额外的HTTP标头
And from the PR: https://github.com/detro/ghostdriver/pull/229 : 从PR: https : //github.com/detro/ghostdriver/pull/229 :
PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX = "phantomjs.page.customHeaders."; //< notice the dot at the end
capabilities.setCapability(PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "it-IT");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.