具有基本身份验证的无头浏览器

时间:2015-11-10 02:18:11

标签: java selenium basic-authentication headless-browser

我想使用无头浏览器测试内部网络中的网站。该网站使用基本身份验证而不是登录页面,所以我到目前为止使用https://username:password@testsite.com之类的东西来使用我的脚本访问该网站。

我试过看,但是有没有无头浏览器支持使用像这样的URL吗?

我目前正在使用HlenUnitDriver和Selenium,但似乎无法正常工作。使用Firefox驱动程序时,我可以正常登录,但当我尝试使用HtmlUnitDriver时,我显然得到了401 - Unauthorized: Access is denied due to invalid credentials

作为参考,我只是使用一个简单的driver.get(url)来打开页面。

HtmlUnitDriver driver = new HtmlUnitDriver();
String url = "https://"+ uName + ":" + uPassword + "@" + testEnvironment;
driver.get(url);
System.out.println(driver.getTitle());

2 个答案:

答案 0 :(得分:0)

我为无头浏览器测试做了这个锅炉板,它实际上使用伊斯坦布尔覆盖,套装和业力与业力酱油。

https://github.com/jotaoncode/web-istanbul

但是如果你使用的是Ecma6,它使用的是javascript Ecma5而不是6你需要去做babelify。 作为无头浏览器,它使用的是PhantomJs2。这是PhantomJS2的兼容性表

http://kangax.github.io/compat-table/es5/#phantom

我需要有关此问题的更多信息才能重现案例。

答案 1 :(得分:0)

我相信木偶戏和噩梦都允许你使用基本身份验证甚至代理。我会给出任何一个镜头

相关问题