简体   繁体   English

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

[英]Handling Windows NTLM authentication with Selenium WebDriver

I am trying to run selenium web driver(Firefox) test cases against a web application which uses NTLM authentication protocol. 我正在尝试对使用NTLM身份验证协议的Web应用程序运行硒Web驱动程序(Firefox)测试用例。

I used DesiredCapabilities to update the "network.automatic-ntlm-auth.trusted-uris" value with " http://localhost:8080 " in order to avoid the display of the authentication window. 我使用DesiredCapabilities将“ network.automatic-ntlm-auth.trusted-uris”值更新为“ http:// localhost:8080 ”,以避免显示身份验证窗口。

The "network.automatic-ntlm-auth.trusted-uris" value is updated but in browser it is still empty. “ network.automatic-ntlm-auth.trusted-uris”值已更新,但在浏览器中仍然为空。

Questions: 问题:

  1. How can I set the "network.automatic-ntlm-auth.trusted-uris" value? 如何设置“ network.automatic-ntlm-auth.trusted-uris”值?
  2. What is the best way to solve this issue? 解决此问题的最佳方法是什么?

Please check the Screenshot and the Code below for more details. 请查看下面的屏幕截图代码以获取更多详细信息。

Thanks in advance. 提前致谢。

SSO_屏幕截图

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);
    }

The problem is solved. 问题已经解决了。 I have to user FirefoxProfile to overwrite all browser config values. 我必须使用FirefoxProfile覆盖所有浏览器配置值。

Please check this for more details. 请检查以获取更多详细信息。

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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM