Request for help disabling Chrome password manager via profile preference in DesiredCapabilities

484 views
Skip to first unread message

Mike Long

unread,
Dec 10, 2015, 4:14:50 AM12/10/15
to Selenium Users

I have encountered an issue with simple login/logout test for our application that is being caused by the “Do you want Google Chrome to save your password for this site?” dialog as it blocks the logout link of our application. I have been trying to figure out how to prevent this pop up from occurring. After a little online research I believe our best option would be to disable the password manager via the Chrome specific profile preference to disable the password manager. Unfortunately I can’t quite get it to work and am running into an error while trying to instantiate the remote webdriver with a DesiredCapabilities configured with the Chrome specific profile setting defined.

 


// Set the desired capabilities for the remote web driver common to all browser types
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.user", Constants.REMOTE_DRIVER_USER_ID);
caps.SetCapability("browserstack.key", Constants.REMOTE_DRIVER_KEY);
caps.SetCapability("browserstack.debug", false);
caps.SetCapability("browserstack.selenium_version", Constants.REMOTE_DRIVER_SELENIUM_VERSION);
caps.SetCapability("browserstack.video", Constants.REMOTE_DRIVER_RECORD_VIDEO);
caps.SetCapability("os", os);
caps.SetCapability("os_version", os_version);
caps.SetCapability("browser", browser);
caps.SetCapability("browser_version", browser_version);
caps.SetCapability("resolution", Constants.REMOTE_DRIVER_RESOLUTION);
caps.SetCapability("build", string.Format("{0}{1}", buildNum, gitCommit));
caps.SetCapability("project", jenkinsJob);
caps.SetCapability("name", TestContext.CurrentContext.Test.Name);
caps.SetCapability("customData", JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(buildInfoJson));
 
// Set browser specific options
switch (browser.ToLower())
{
    case "chrome":
        ChromeOptions browserSpecificOptions = new ChromeOptions();
        browserSpecificOptions.AddUserProfilePreference("password_manager_enabled", false);
        caps.SetCapability(ChromeOptions.Capability, browserSpecificOptions);
        break;
}
 
webDriver = new RemoteWebDriver(commandUri, caps);

 

We are receiving the following error from the RemoteWebDriver constructor during the NUnit test setup method which instantiates the webdriver:



Test Name: area51
Test FullName: CompanyName.ProductName.Selenium.Tests.SmokeTest_Remote("Windows","10","Chrome","").area51
Test Source: d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Test\SmokeTest_Remote.cs : line 170
Test Outcome: Failed
Test Duration: 0:00:20.009

Result Message:
System.InvalidOperationException : Session terminated
TearDown : System.ArgumentException : The SearchContext of the locator object cannot be null
Parameter name: locator
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
   at CompanyName.ProductName.Selenium.Framework.Browser.InitializeRemoteDriver(String os, String os_version, String browser, String browser_version, String buildInfoJson) in d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Framework\Browser.cs:line 102
   at CompanyName.ProductName.Selenium.Framework.BaseTest_Remote.SetUp() in d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Framework\BaseTest_Remote.cs:line 66
--TearDown
   at OpenQA.Selenium.Support.PageObjects.PageFactory.InitElements(Object page, IElementLocator locator, IPageObjectMemberDecorator decorator)
   at OpenQA.Selenium.Support.PageObjects.PageFactory.InitElements(ISearchContext driver, Object page)
   at CompanyName.ProductName.Selenium.Framework.Pages.Pages.GetPage[T]() in d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Framework\Pages\pages.cs:line 11
   at CompanyName.ProductName.Selenium.Framework.Pages.Pages.get_ConfirmCancelDlg() in d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Framework\Pages\pages.cs:line 120
   at CompanyName.ProductName.Selenium.Framework.BaseTest_Remote.TearDown() in d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Framework\BaseTest_Remote.cs:line 78


If we comment out the switch to add the browser specific options to the desired capabilities the remote web driver session starts up fine. Can anyone provide any insight into what might be going wrong or do you have any suggestions on other solutions for preventing the “Save Password” dialog from being presented?

 

Thanks for your time and consideration,

Mike Long

Zahi Zilberman

unread,
Dec 10, 2015, 4:54:35 AM12/10/15
to Selenium Users
can you add the snippet for your InitializeRemoteDriver?

Mike Long

unread,
Dec 10, 2015, 11:36:37 AM12/10/15
to Selenium Users
Hello Zahi,

The code snippet in my original post is essentially the bulk of the desired capabilities configuration and webdriver instantiation from the InitializeRemoteDriver function seen in the stack trace. After some further reading and tinkering a managed to at least get the Chrome specific options into the desired capabilities and successfully instantiate web driver. So the original error is no longer occurring. The modifications look like:

DesiredCapabilities caps;

            switch (browser.ToLower())
            {
                case "chrome":
                    ChromeOptions browserSpecificOptions = new ChromeOptions();
                    //browserSpecificOptions.AddUserProfilePreference("password_manager_enabled", "false");
                    browserSpecificOptions.AddArgument("--disable-save-password-bubble");
                    caps = (DesiredCapabilities)browserSpecificOptions.ToCapabilities();
                    break;
                default:
                    caps = new DesiredCapabilities();
                    break;
            }

            // Set the desired capabilities for the remote web driver
            caps.SetCapability("browserstack.user", Constants.REMOTE_DRIVER_USER_ID);
            caps.SetCapability("browserstack.key", Constants.REMOTE_DRIVER_KEY);
            caps.SetCapability("browserstack.debug", false);
            caps.SetCapability("browserstack.selenium_version", Constants.REMOTE_DRIVER_SELENIUM_VERSION);
            caps.SetCapability("browserstack.video", Constants.REMOTE_DRIVER_RECORD_VIDEO);
            caps.SetCapability("os", os);
            caps.SetCapability("os_version", os_version);
            caps.SetCapability("browser", browser);
            caps.SetCapability("browser_version", browser_version);
            caps.SetCapability("resolution", Constants.REMOTE_DRIVER_RESOLUTION);
            caps.SetCapability("build", string.Format("{0}{1}", buildNum, gitCommit));
            caps.SetCapability("project", jenkinsJob);
            caps.SetCapability("name", TestContext.CurrentContext.Test.Name);
            caps.SetCapability("customData", JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(buildInfoJson));

            webDriver = new RemoteWebDriverExtended(commandUri, caps);


Unfortunately, while this avoids the original error and allows the RemoteWebDriver to start the browser and proceed with testing, the "save password" dialog is still being presented.

Mike Long

unread,
Dec 10, 2015, 2:38:47 PM12/10/15
to Selenium Users
Well it looks like my second attempt to add Chrome specific options to my desired capabilities for the RemoteWebDriver works properly and avoids the original error I was encountering due to the crappy code of my first attempt. Unfortunately the timing of this coincides with the fact that Chrome 47 (just released at the beginning of Dec) stopped respecting the --disable-save-password-bubble command line switch. The working code snippet to instantiate the RemoteWebDriver does result in the save password dialog being suppressed in Chrome versions 40 through 46, it just doesn't work with Chrome 47. Other Chrome specific options added to the desired capabilities this way (like --start-maximized) do work as expected. Issue 568681 was logged with the Chromium project in this regard.
Reply all
Reply to author
Forward
0 new messages