java - 如何在 WebDriver(FirefoxDriver) 测试中关闭或禁用基本身份验证弹出窗口

标签 java integration-testing webdriver selenium-webdriver

我正在使用 WebDriver 测试我的应用程序,但某些页面试图从另一台服务器获取资源,这需要身份验证。我的测试不需要这些资源,而且我目前还没有证书。 当弹出窗口出现时,它会停止测试运​​行。

我尝试使用 webDriver.switchTo().alert().dismiss(); 关闭弹出窗口,但显然它不是警报。

我还尝试使用 firefox 配置文件禁用弹出窗口:

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("capability.policy.policynames", "strict") ;
profile.setPreference("capability.policy.strict.sites",  "http://localhost:9000") ;
profile.setPreference("capability.policy.strict.Window.alert", "noAccess") ;
profile.setPreference("capability.policy.strict.Window.confirm", "noAccess") ;
profile.setPreference("capability.policy.strict.Window.prompt", "noAccess") ;
FirefoxDriver driver = new FirefoxDriver(profile);

但这并没有帮助。

提前致谢。

最佳答案

我认为网络驱动程序的设计并没有考虑到上述意图,而且我也没有看到在不久的将来会提供任何此类 api。他们想要测试其行为是否与人类看到页面的方式完全一致。

话虽如此,您可以控制要针对其运行测试的网站。您不能自己阻止这些资源吗?可能是因为使用了一些配置设置,当配置中的标志设置为 true 时,这些设置不会加载资源。

该设置可能类似于 IsSeleniumInstance。

希望这对您有所帮助。

关于java - 如何在 WebDriver(FirefoxDriver) 测试中关闭或禁用基本身份验证弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8008072/

相关文章:

laravel - 如何为使用 Laravel 5 中存储文件系统的端点编写集成测试?

c# - 使用 selenium、Nunit、Selenium Grid、C#、webdriver/remote control 的自动浏览器测试

c# - 使用 Selenium Webdriver 测试元素是否聚焦

java - 将系统属性设置为文件路径

java - 如何获取JavaParser方法参数解析的原始包名或类

java.io.IOException : Mark has been invalidated when parsing website with jsoup 异常

java - XWPFTable 中的文本方向

testing - Selenium Test Runner 和变量问题

integration-testing - 机器人框架 : assign variable with if-else statement

java - 使用 testNG 将 test 内的数据提供者元素作为数组进行利用