CodedUI - Windows Authentication in Chrome Browser

2019-02-21 04:38发布

问题:

I'm using "Cross Browser Selenium Components" plugin to run codedui tests in Chrome browser. When i launch my web application, it needs windows authentication to log in to the website.

How do i pass the username and password along with the URL in coded UI?

Webdriver equivalent code is:

baseUrl=”http://” + username + “:” + password + “@” + url;

driver.get(baseUrl + “/”);

But in codedui, when i execute the below code, authentication window pops up but the control does not get past browser.NavigateToURL and hence i cannot provide username and password.

        BrowserWindow.CurrentBrowser = "chrome"; 
        string URL = "http://servername:portnumber/index.jsp";             
        BrowserWindow browser = BrowserWindow.Launch();
        browser.NavigateToUrl(new Uri(URL));

Any help would be highly appreciated please.

回答1:

As @AdrianHHH suggested, the solution for this is:

string URL = "http://" + username + ":" + password + "@servername:portnumber/index.jsp";

This has been tested and working fine.



回答2:

Answers given above are not wrong but including passwords in your code(or ini or config file for that matter) might not be the best way to go.

Always hide or encrypt your passwords.

You can go through this url on how to do that.