Chrome is being controlled by automated test software

冷暖自知 提交于 2019-11-30 08:31:19

Add this to the options you pass to the driver:

options.addArguments("disable-infobars");

About the "Chrome is being controlled by automated test software" text pop up : It won't affect your testing. And to handle other things(e.g: save password) you can add below lines to your code.

ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",*path of chromedriver.exe*);
wb = new ChromeDriver(cap);

Hope it would work.

May someone needs this for Capybara, Watir should be like this:

Capybara.register_driver :chrome do |app|
  $driver = Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => [ "--disable-infobars" ]})
end

While the disable-infobars route will work, it will likely suppress the infobar in all cases (as suggested here), not just the case that the OP is referring to. This is overkill at best, and could lead to unexpected and inexplicable behavior in the future if you are not getting some important message.

I think it's better to leverage the provided enable-automation switch by disabling it in the excludeSwitches area of your config/setup while doing nothing with regards to disable-inforbars. The enable-automation switch's description:

Inform users that their browser is being controlled by an automated test.

For nightwatch.conf.js it would look something like this (and worked for me):

desiredCapabilities: {
  ...
  chromeOptions: {
    excludeSwitches: ['enable-automation'],
    ...
  }
}

This should only do what we are after: getting rid of that specific pesky message!

Edit [2017-11-14]: This is now causing an even more annoying Disable Developer Mode Extensions alert/warning. I've tried every relevant-looking flag/switch I could find that might help, but to no avail. I've filed a bug with Chromium, so we'll see and I'll try to swing back through here if I get a resolution.

Rajeev
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));    
WebDriver driver = new ChromeDriver(options);

Use the above codes for latest Chrome drivers.

Map<String, Object> prefs = new HashMap<String, Object>();
//To Turns off multiple download warning
prefs.put("profile.default_content_settings.popups", 0);

prefs.put( "profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1 );

//Turns off download prompt
prefs.put("download.prompt_for_download", false);
                    prefs.put("credentials_enable_service", false);
//To Stop Save password propmts
prefs.put("password_manager_enabled", false);

ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","--disable-extensions");
//To Disable any browser notifications
options.addArguments("--disable-notifications");
//To disable yellow strip info bar which prompts info messages
options.addArguments("disable-infobars");

options.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", "Chromedriver path");
options.addArguments("--test-type");
driver = new ChromeDriver(options);
Log.info("Chrome browser started");

If anyone is using Rails 5.1+, which changed the testing structure a bit and Capybara is configured in this file now for system tests:

application_system_test_case.rb

You can add "args" in the options for driven_by like this:

driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { args: ["--disable-infobars"] }

Protractor solution:

I arrived here searching for a Protractor solution, if useful for anyone I found, with help from the above answers; with Protractor you can add Chrome specific options to the chromeOptions object, within the capabilities object in the protractor.config file, for example to use the disable-infobars option discussed above use the following:

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['disable-infobars']
  }
},

To use the enable-automation also discussed above:

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'excludeSwitches': ['enable-automation']
  }
}

disable-infobars is preferred in my circumstances.

public WebDriver SetupChromeDriver(){
        //Initialize Chrome Driver
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("safebrowsing.enabled", "true"); 
        options.setExperimentalOption("prefs", prefs); 
        options.addArguments("--disable-notifications");
        options.addArguments("--start-maximized");
        options.addArguments("disable-infobars");
        System.setProperty("webdriver.chrome.driver", "E:/Importent Softwares/Chrome Driver/chromedriver_2.37.exe");
        driver = new ChromeDriver(options);
        return driver;
}
Tree Go

It works for me by using addArguments(array("disable-infobars"))

This is for facebook/php-webdriver

$options = new ChromeOptions();
$options->addArguments(array("disable-infobars"));
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$this->driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);

"disable-info" switch is not supported anymore for the latest chromedrivers. (at least 76.0).
@Rajeev's answer works and here I write the counterpart for C#.

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalOption("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("enable-automation");
Driver = new ChromeDriver(chromeOptions);

You may use this

options1.add_argument("--app=https://www.google.com.ph")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!