Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brianjbayer/7b5ad7544dd28812cc33a7b80f40c08a to your computer and use it in GitHub Desktop.
Save brianjbayer/7b5ad7544dd28812cc33a7b80f40c08a to your computer and use it in GitHub Desktop.
How to disable the Chrome Controlled by automation banner and those Save address?, Save card?, and Save Password? pop up windows in Selenium Webdriver

Disabling Selenium Chrome Automation Banner and Save address?, Save card?, and Save password? Pop Ups

Pencil Sharpener - Wendy Bayer

Image: Pencil Sharpener by Wendy Bayer


This shows you how to disable those Chrome Save address?, Save card?, and Save Password? pop up windows in Selenium Webdriver projects.

It also shows you how to disable the Chrome is being controlled by automated test software banner.

Besides being distracting, these may shift or cover other elements.

This example is specifically in Ruby RSpec Capybara, but the cited links may have alternative implementations.

This post also includes a sample test project that demonstrates disabling the automation banner and Save address?, and Save Password? pop up. I did not have a test/fake endpoint for credit card.


Disabling Using Selenium Chrome Options

In order to change Chrome behavior like disabling the automation banner and Save popups, you will have to create Selenium Chrome Options in your language's Selenium Webdriver bindings.

In the Capybara browser automation framework using Selenium Webdriver, it looks like this...

chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

Disabling the Chrome is being controlled by automated Banner

Previously, the Chrome is being controlled by automated test software banner was disabled by adding the Chrome argument

chrome_options.add_argument('--disable-infobars')

Here you have to exclude the switch "enable-automation"...

chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

chrome_options.exclude_switches << "enable-automation"

🛡️ Strangely enough, when this automation banner is disabled, I found that the Chrome Save password? pop up started appearing where it did not before. The sample demonstration project should show this on the login page.

🙇 Here is a reference on the deprecation of --disable-infobars in this StackExchange post


Disabling the Chrome Save address? Pop Up

The Chrome Save ? pop ups are all disabled the same way by adding preferences to the Chrome Option.

chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

# Disable Chrome's "Save address?" pop up
chrome_options.add_preference("autofill.profile_enabled", false)

🙇 Here my original reference was in C# Selenium in this Stack Overflow post


Disabling the Chrome Save password? Pop Up

chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

# Disable Chrome's "Save password?" pop up
chrome_options.add_preference("credentials_enable_service", false)
chrome_options.add_preference("profile.password_manager_enabled", false)

🙇 Here my original reference was in Ruby Watir Selenium in this Stack Overflow post


Disabling the Chrome Save card? Pop Up

chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

# Disable Chrome's "Save card?" pop up
chrome_options.add_preference("autofill.credit_card_enabled", false)

This one was tricky and somehow I stumbled across this Chrome Check In which led me to the preference name


Complete Capybara Example

Here is a complete example of creating and configuring a Selenium Webdriver Chrome Browser with the automation banner and Save ? pop ups disabled.

# Create Chrome options
chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

# Disable the "Chrome is being controlled by automated test software" banner
chrome_options.exclude_switches << "enable-automation"

# Disable Chrome's "Save address?" pop up
chrome_options.add_preference("autofill.profile_enabled", false)

# Disable Chrome's "Save password?" pop up
chrome_options.add_preference("credentials_enable_service", false)
chrome_options.add_preference("profile.password_manager_enabled", false)

# Disable Chrome's "Save card?" pop up
chrome_options.add_preference("autofill.credit_card_enabled", false)

# Use the options by registering the driver
Capybara.register_driver :chrome_browser do |app|
  Capybara::Selenium::Driver.new(app,
                                browser: :chrome,
                                options: chrome_options)
end
Capybara.default_driver = :chrome_browser

Demonstration Capybara Project

You should be able to see the disabling of the Chrome automation banner and Save ? pop ups with this demonstration Capybara RSpec project. The tests use sleep statements giving you time to view the page with or without the banner and pop ups.

It includes two Capybara Selenium Chrome tests. One that fills in an address and one that fills in a user name and password. The tests run three times.

The first time the tests run should show the automation banner and the Save address? pop up. This is using the Capybara-defined :selenium_chrome driver which is mostly Chrome defaults.

The second time they run, it should show that the automation banner is gone but the Save password? pop up now appears. This is using a user-defined Capybara driver with the automation banner disabled.

Finally, the third time the tests run should show no automation banner and no Save ? pop ups. This is using a user-defined Capybara driver with the automation banner and all Save ? pop ups disabled.

You will build the RSpec Selenium Capybara project yourself and use the code included here.

Prerequisites Chrome, Ruby, and RSpec

You must have a functioning Ruby environment with Chrome installed

  1. Install the rspec gem
    gem install rspec
    

Create the RSpec Project

Here you create a new RSpec project called demo.

  1. Make a demo directory

    mkdir demo
  2. Change directory to your demo directory

    cd demo
  3. Initialize a project with RSpec

    rspec --init

Add Your Files

All file paths shown are relative to the project root (i.e. demo) directory.

File Gemfile

In Gemfile...

source 'https://rubygems.org'

gem 'capybara'
gem 'rspec'
gem 'selenium-webdriver'
gem 'webdrivers'

File .rspec

In .rspec...

--require spec_helper
--format documentation
--color

File spec/features/demonstrate_disable_banner_and_save_popups_spec.rb

This is the demonstration with the two tests (shared_examples) that run three times using different Capybara driver configurations.

First you need to create the spec/features directory in your project...

  1. Create the spec/features directory
mkdir -p spec/features

Then in file spec/features/demonstrate_disable_banner_and_save_popups_spec.rb...

require 'capybara/rspec'
require 'selenium/webdriver'
require 'webdrivers/chromedriver'

RSpec.shared_examples 'Banner and Save ? popup situations' do

  it 'Fills in an address' do
    visit 'https://parabank.parasoft.com/parabank/register.htm'

    within('#customerForm') do
      fill_in 'customer.firstName', with: 'Bob'
      fill_in 'customer.lastName', with: 'Dobbs'
      fill_in 'customer.address.street', with: '123 Dobbstown Rd.'
      fill_in 'customer.address.city', with: 'Dobbstown'
      fill_in 'customer.address.state', with: 'Iowa'
      fill_in 'customer.address.zipCode', with: '43435'
      fill_in 'customer.ssn', with: '123-45-6789'
      fill_in 'customer.username', with: 'bobdobbs'
      fill_in 'customer.password', with: '1234567890'
      fill_in 'repeatedPassword', with: '1234567890'

      click_button 'Register'
    end
    # Allow to time to observe the behavior
    sleep 8
  end

  it 'Fills in a username and password' do
    visit 'https://the-internet.herokuapp.com/login'

    fill_in 'username', with: 'tomsmith'
    fill_in 'password', with: 'SuperSecretPassword!'

    click_button 'Login'
    # Allow to time to observe the behavior
    sleep 9
  end
end

describe 'Demonstrating Disabling Chrome Banner and Save ? Popups' do
  after do
    # Quit browser (session) to not cache the registered driver
    Capybara.current_session.quit
  end

  describe 'when nothing is disabled, there is a banner and Save address? popup', type: :feature do
    before :each do
      # --- Default Capybara Chrome ---
      Capybara.default_driver = :selenium_chrome
    end

    include_examples 'Banner and Save ? popup situations'
  end

  describe 'when just banner is disabled, Save password? now appears', type: :feature do
    before :each do
      # --- Registering your own chrome with options to disable banner ---
      # Create Chrome options
      chrome_options = ::Selenium::WebDriver::Chrome::Options.new()
      # Disable the "Chrome is being controlled by automated test software" banner
      chrome_options.exclude_switches << "enable-automation"

      # Use the options by registering the driver
      Capybara.register_driver :capy_browser do |app|
        Capybara::Selenium::Driver.new(app,
                                      browser: :chrome,
                                      options: chrome_options)
      end
      Capybara.default_driver = :capy_browser
    end

    include_examples 'Banner and Save ? popup situations'
  end

  describe 'when banner and Save ? popups are all disabled', type: :feature do
    before :each do
      # --- Registering your own chrome with options to disable banner and Save popups---
      # Create Chrome options
      chrome_options = ::Selenium::WebDriver::Chrome::Options.new()

      # Disable the "Chrome is being controlled by automated test software" banner
      chrome_options.exclude_switches << "enable-automation"

      # Disable Chrome's "Save address?" pop up
      chrome_options.add_preference("autofill.profile_enabled", false)

      # Disable Chrome's "Save password?" pop up
      chrome_options.add_preference("credentials_enable_service", false)
      chrome_options.add_preference("profile.password_manager_enabled", false)

      # Disable Chrome's "Save card?" pop up
      chrome_options.add_preference("autofill.credit_card_enabled", false)

      # Use the options by registering the driver
      Capybara.register_driver :chrome_browser do |app|
        Capybara::Selenium::Driver.new(app,
                                      browser: :chrome,
                                      options: chrome_options)
      end
      Capybara.default_driver = :chrome_browser
    end

    include_examples 'Banner and Save ? popup situations'
  end
end

Build and Run

To build and run the demonstration...

  1. Build the project

    bundle install
    
  2. Run the demonstration

    bundle exec rspec
    

You should see the tests run three different times demonstrating disabling the automation banner and Save ? pop ups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment