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 optionsswitch (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","").area51Test Source: d:\workbench\git\CompanyName ProductName\CAT\CompanyName.ProductName.Selenium.Test\SmokeTest_Remote.cs : line 170Test Outcome: FailedTest Duration: 0:00:20.009
Result Message: System.InvalidOperationException : Session terminatedTearDown : System.ArgumentException : The SearchContext of the locator object cannot be nullParameter name: locatorResult 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
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);