为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Selenium WebDriver 处理 Windows NTLM 身份验证

使用 Selenium WebDriver 处理 Windows NTLM 身份验证

ABOUTYOU 2022-06-15 15:18:49
我正在尝试针对使用 NTLM 身份验证协议的 Web 应用程序运行 selenium Web 驱动程序(Firefox)测试用例。我使用 DesiredCapabilities 将“network.automatic-ntlm-auth.trusted-uris”值更新为“ http://localhost:8080 ”以避免显示身份验证窗口。“ network.automatic-ntlm-auth.trusted-uris”值已更新,但在浏览器中仍为空。问题:如何设置“network.automatic-ntlm-auth.trusted-uris”值?解决此问题的最佳方法是什么?请查看屏幕截图和下面的代码以获取更多详细信息。提前致谢。public RemoteWebDriver getWebDriverObject(DesiredCapabilities capabilities) {        String os = SystemUtils.IS_OS_WINDOWS ? "windows" : "linux";        System.setProperty("webdriver.gecko.driver", "target/test-classes/selenium_standalone_binaries/" + os + "/marionette/64bit/geckodriver.exe");        FirefoxOptions options = new FirefoxOptions();        // check the "Network.automatic-ntlm-auth.trusted-uris value before update"        System.out.println("Capability before update >>>>>" + capabilities.getCapability("Network.automatic-ntlm-auth.trusted-uris"));        // update the "Network.automatic-ntlm-auth.trusted-uris value" after update        capabilities.setCapability("Network.automatic-ntlm-auth.trusted-uris", "http://localhost:8080");        // check the "Network.automatic-ntlm-auth.trusted-uris value after update"        System.out.println("Capability after update >>>>>" + capabilities.getCapability("Network.automatic-ntlm-auth.trusted-uris"));        options.merge(capabilities);        options.setHeadless(HEADLESS);        return new FirefoxDriver(options);    }
查看完整描述

1 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

问题已经解决了。我必须使用 FirefoxProfile 来覆盖所有浏览器配置值。


请检查此以获取更多详细信息。


public RemoteWebDriver getWebDriverObject(DesiredCapabilities capabilities) {

        String os = SystemUtils.IS_OS_WINDOWS ? "windows" : "linux";

        System.setProperty("webdriver.gecko.driver", "target/test-classes/selenium_standalone_binaries/" + os + "/marionette/64bit/geckodriver.exe");


        FirefoxOptions options = new FirefoxOptions();

        options.merge(capabilities);

        options.setHeadless(HEADLESS);


        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost:8080");

        profile.setPreference("dom.disable_beforeunload", false);


        options.setProfile(profile);

        options.setLogLevel(FirefoxDriverLogLevel.DEBUG);

        return new FirefoxDriver(options);

    }


查看完整回答
反对 回复 2022-06-15
  • 1 回答
  • 0 关注
  • 272 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号