How to remove the infobar "Microsoft Edge is being controlled by automated test software" in selenium test - selenium

We are using selenium to run test against "Chromium based Edge".
"The Chromium Edge" is downloaded from https://www.microsoftedgeinsider.com/en-us/download and the version is 80.0.334.2 (Official build) dev (64-bit).
We got the matched driver msedgedriver.exe from https://msedgewebdriverstorage.z22.web.core.windows.net/
We add the "C:\Program Files (x86)\Microsoft\Edge Dev\Application" to the environment "PATH" so that the executable "msedge.exe" will be found during the test.
After starting the selenium server with option -Dwebdriver.edge.driver="pathTo\msedgedriver.exe", we can get the test run in the "Chromium Edge" as below:
But there is a infobar "Microsoft Edge is being controlled by automated test software", just like we run test with chrome browser. With chrome, we can remove that infobar by setting the following ExperimentalOption to ChromeOptions
useAutomationExtension=false
excludeSwitches=[enable-automation]
prefs={credentials_enable_service=false, profile={password_manager_enabled=false}}
I tried to set the same options and I got a browser launched without the infobar, but it is a chrome browser NOT the "Chromium Edge".

You could refer to the following code (C# code) to set the chrome options and remove the infobar.
var edgechromiumService = ChromeDriverService.CreateDefaultService(#"E:\edgedriver_win64", "msedgedriver.exe");
// user need to pass the driver path here....
ChromeOptions edgechromeOptions = new ChromeOptions
{
BinaryLocation = #"C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe",
};
edgechromeOptions.AddAdditionalCapability("useAutomationExtension", false);
edgechromeOptions.AddExcludedArgument("enable-automation");
using (IWebDriver driver = new ChromeDriver(edgechromiumService, edgechromeOptions))
{
driver.Navigate().GoToUrl("https://www.bing.com/");
Console.WriteLine(driver.Title.ToString());
//driver.Close();
Console.ReadKey();
}
The result like this:
For Java applications, please try to use the following code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import java.util.*;
public class Edgeauto {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "your\\path\\to\\edge\\webdriver\\msedgedriver.exe");
ChromeOptionschromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);
WebDriver driver = new ChromeDriver(edgeOptions);
driver.get("https://www.google.com/");
}
}

I think that I can explain the all the confusions (perhaps for myself 😊). In the following link Microsoft Chromium Edge
We can find something as below:
If you were previously automating or testing Microsoft Edge (Chromium) by using ChromeDriver and ChromeOptions, your WebDriver code will not run successfully against Microsoft Edge 80 or later. This is a breaking change and Microsoft Edge (Chromium) no longer accepts these commands. You must change your tests to use EdgeOptions and Microsoft Edge Driver.
So we can handle the Chromium-Edge (version is smaller than 80) completely as a chrome browser.
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("http://www.google.com");
driver.close();
For the Chromium-Edge (version 80 or later), we should treat it as an Edge browser, the code is as below:
The problem is that EdgeOptions does NOT provide enough APIs (setBinary, setExperimentalOption) as ChromeOptions ☹.
I checked the selenium’s source code at github and I found that the EdgeOptions has already supported those methods as ChromeOptions. So I downloaded the latest official build whose version is 3.141.59, and it was released this on Dec 20, 2018 and I found out that it doesn’t contain the latest source code ☹.
So I got the alpha release 4.0.0-alpha-4 and it does contain the latest source code.
System.setProperty("webdriver.edge.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
edgeOptions.setExperimentalOption("useAutomationExtension", false);
edgeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
EdgeDriver driver = new EdgeDriver(edgeOptions);
driver.get("http://www.google.com");
driver.close();
Finally I want to thank my comrade comrade Carl, he helped me find the trick.

You saw it right.
As per the article Microsoft’s Edge Chromium browser will launch on January 15th with a new logo Microsoft is planning to release its Edge Chromium browser on January 15th 2020 with availability for Windows 10, Windows 7, Windows 8, and macOS. This came just after Microsoft released the beta version of Edge.
Now, this Beta also means that Microsoft is edging closer to the release stage for its Chromium browser. Microsoft first released its Canary and Developer builds of Edge back in April, and the company has spent the past four months working alongside Google to improve Chromium for Windows. That work also involved Microsoft getting used to the cadence of delivering a Chromium browser.
Hence adding the ExperimentalOption you see the Microsoft’s Edge Chromium browser almost like a Chromium / Chrome browser.

#Zhi Lv - MSFT
What is the browser you are launching? Chrome or Chromium-Edge? I am using selenium java code, if I run the similar java code as below, it will fail with error
The path to the driver executable must be set by the webdriver.chrome.driver system property;
System.setProperty("webdriver.edge.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("http://www.google.com");
If I create an edge capabilities and merge the ChromeOption into it, I can see that "Chromium-Edge" gets started without the "infobar", but it just gets stuck there and fails with an error
unknown error: unrecognized Chrome version: Edg/80.0.361.5
System.setProperty("webdriver.edge.driver", "C:\\SeleniumPlus\\extra\\msedgedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
DesiredCapabilities m_capability = DesiredCapabilities.edge();
m_capability.merge(chromeOptions);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), m_capability);
driver.get("http://www.google.com");
From the "selenium server" console, I can see, the "browserName" is "chrome", I guess that is the reason why chrome's options is working to get rid of the "infobar"
15:37:55.502 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
],
"binary": "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe",
"excludeSwitches": [
"enable-automation"
],
"extensions": [
],
"useAutomationExtension": false
},
"platform": "WINDOWS",
"version": ""
}
If I set the "browserName" to "MicrosoftEdge" after merging the chrome's options as below, it can get the "Chromium-Edge" started, but the chrome's options do not work any more, which means the "infobar" is still there.
m_capability.merge(chromeOptions);
m_capability.setCapability(CapabilityType.BROWSER_NAME, BrowserType.EDGE);

Related

Accept microphone and camera permissions on Edge using selenium

I am running selenium scripts on Edge browser. one of the functionality requires to initiate a audio or video call between two windows. In chrome, we can use 'use-fake-ui-for-media-stream' in chrome options. Is there anything similar for Edge. If there isn't, is there a way to accept these alerts at runtime. I have tried -
driver.switchTo().alert().accept(),
but this also doesn't work, and throws error saying no such alert present
Edited
I am using Edge chromium and java selenium and have set properties as below in code. Still permission pop up shows when script runs
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", fileDownloadLocation);
EdgeOptions options= new EdgeOptions();
options.setCapability("prefs", prefs);
options.setCapability("allow-file-access-from-files", true);
options.setCapability("use-fake-device-for-media-stream", true);
options.setCapability("use-fake-ui-for-media-stream", true);
DesiredCapabilities capabilities = DesiredCapabilities.edge;
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
System.setProperty("webdriver.edge.driver", getDriverPath("EDGE"));
driver = new EdgeDriver(options);
driver.manage().window().maximize();
I suggest you make a test with the sample code below. I tried to test with the Edge Chromium browser and it looks like it is not asking the permission popup.
JAVA code:
public static void main(String[] args)
{
System.setProperty("webdriver.edge.driver","\\msedgedriver.exe");
EdgeOptions op=new EdgeOptions();
op.addArguments("use-fake-device-for-media-stream");
op.addArguments("use-fake-ui-for-media-stream");
WebDriver browser = new EdgeDriver(op);
browser.get("https://your_URL_here...");
}
In Selenium 3.141 Version we dont have addArguments() method but in Selenium 4.0.0 alpha version we have addArguments() method
EdgeOptions edgeOpts = new EdgeOptions();
edgeOpts.addArguments("allow-file-access-from-files");
edgeOpts.addArguments("use-fake-device-for-media-stream");
edgeOpts.addArguments("use-fake-ui-for-media-stream");
edgeOpts.addArguments("--disable-features=EnableEphemeralFlashPermission");
driver = new EdgeDriver(edgeOpts);

Selenium newer Chrome cannot disable browser notification (Tried other solns)

I know this is an old question, and I've tried answers from a few posts such as Disable Chrome notifications (Selenium)
Unfortunately none worked, the browser notification popup still comes and interrupts my simulations.
My Chrome version is 75.0.3770.100 (Official Build) (64-bit), running on MacOS.
Edit:
After this question was marked as a duplicate of How to disable push-notifications using Selenium for Firefox and Chrome?, I've tried the solutions, but it still did not work for me.
String chromePath = "somepath/selenium-2.48.2/chromedriver";
System.setProperty("webdriver.chrome.driver", chromePath);
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
Below are the original solutions I tried.
String chromePath = "somepathto/chromedriver";
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
// Login
try {
driver.get(sometestURL);
driver.manage().window().maximize();
// do some operations
} catch (Exception ex) {
System.out.println(ex);
}
I also tried this:
String chromePath = "somepath/selenium-2.48.2/chromedriver";
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
But the notification still comes "xxxxwebsite wants to show notifications Allow Block" on the upper left of the window.
What I did not do right?
I just tested this on Windows with Chrome 75.0.3770.142 (64 bit) and ChromeDriver 75.0.3770.90 (see log below) against web site https://www.nzz.ch (because it asks for permission to show push notifications). I used Selenium 3.14.0.
08:27:37.184 [main] INFO i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\xxxxx\.m2\repository\webdriver\chromedriver\win32\75.0.3770.90\chromedriver.exe
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 32864
For me the switch also mentioned here and in the linked resources reliably deactivates the popup from being displayed:
options.addArguments("--disable-notifications");
Changing the default setting profile.default_content_setting_values.notifications is not necessary in my case. So if this does not work for you
either you are not setting the option correctly,
you are using a (possibly outdated) ChromeDriver version not supporting it or
for some reason on MacOS the driver does not implement it.
P.S.: In both Firefox and Chrome for me it was not problem to e.g. click links and navigate to other pages even during the notification pop-up was shown. Did you have any problems there or is the pop-up just an annoyance?

Geb: How to use Marionette instead of selenium Webdriver?

It is known issue that, Firefox version 47.0.1 is not compatible with Selenium latest version. Even Firefox is announcing to use Marionette instead. Can someone give some details instruction on how to use Marionette with Geb?
As a maven project, I tried all the version of Selenium with Geb but could not be successfull. I tried the following versions;
2.50.0
2.50.1
2.51.0
2.52.0
2.53.0
2.53.1
2.6.0
2.7.0
2.8.0
2.9.0
If this is not the right place to ask this, please guide me.
I have the next configuration in GebConfig.groovy:
firefox {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
driver = {new MarionetteDriver()}
}
I am using selenium 3.0.1 and I using the -Dgeb.env=firefox system property in order to make sure it takes my Firefox configuration and it working fine for me
Regards
Download the latest version of selenium standard version 2.53.1 from selenium.hq.org.downloads and try to use the newest version of the Firefox.
With version 48 of Firefox, it looks like the only solution is using marionnette, however I have not been able to get this to work in Geb yet.
This is what I have tried in GebConfig.groovy:
environments {
firefox {
driver = {
DesiredCapabilities dc = DesiredCapabilities.firefox();
LoggingPreferences prefs = new LoggingPreferences();
prefs.enable(LogType.BROWSER, Level.WARNING);
dc.setCapability(CapabilityType.LOGGING_PREFS, prefs);
dc.setCapability("marionette", true);
String currentDir = System.getProperty("user.dir");
String marionetteDriverLocation = currentDir + "/WebDriver/wires";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
FirefoxProfile p = new FirefoxProfile();
p.setPreference("webdriver.gecko.driver", marionetteDriverLocation);
p.setPreference("webdriver.log.file", "/tmp/firefox_console");
p.setPreference("toolkit.telemetry.enabled", false);
p.setPreference("geo.enabled", false);
p.setPreference("plugins.update.notifyUser", false);
p.setPreference("datareporting.healthreport.service.enabled", false);
p.setPreference("datareporting.healthreport.uploadEnabled", false);
p.setPreference("datareporting.policy.dataSubmissionEnabled",false);
p.setPreference("datareporting.healthreport.service.firstRun", false);
p.setPreference("datareporting.healthreport.logging.consoleEnabled", false);
p.setPreference("reader.parse-on-load.enabled", false);
dc.setCapability(FirefoxDriver.PROFILE, p);
def driver = new FirefoxDriver(dc)
driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS)
return driver
}
It should work with any of the late Selenium versions. (everything > 2.50 not sure for earlier versions)
Marionette is an external driver, it's not included in the Selenium packages (yet?)
You need to Download the gecko driver here https://github.com/mozilla/geckodriver/releases
then point selenium to the location of the geckodriver.exe
You can do that as Nelson said before in GebConfig with:
import org.openqa.selenium.firefox.MarionetteDriver
driver = {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
new MarionetteDriver()
}
to make that work you will need some dependencies in your buildscript, I'm working with gradle, yours might look different, just look into what yours need to look like on maven central
compile('info.novatec.testit:webtester-support-marionette:2.0.4') { transitive = false }
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
(selenium support might not be necessary for you)
If you need more help, a more specific description of where you are failing would be helpful, you can also look here for a working project (with maven):
http://seleniumsimplified.com/2016/04/how-to-use-the-firefox-marionette-driver/
public class Driver {
public FirefoxDriver getFirefoxDriver(){
System.setProperty("webdriver.gecko.driver", "./geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
return new FirefoxDriver(options);
}
}

How to disable 'This type of file can harm your computer' pop up

I'm using selenium chromedriver for automating web application.
In my application, I need to download xml files. But when I download xml file, I get 'This type of file can harm your computer' pop up. I want to disable this pop up using selenium chromedriver and I want these type of files to be downloaded always. How can this be done?
Selenium version : 2.47.1
Chromedriver version : 2.19
UPDATE it's long standing Chrome bug from 2012.
The problem with XML files started to happen to me as of Chrome 47.0.2526.80 m.
After spending maybe 6 hours trying to turn off every possible security option I tried a different approach.
Ironically, it seems that turning on the Chrome option "Protect you and your device from dangerous sites" removes the message "This type of file can harm your computer. Do you want to keep file.xml anyway?"
I am using 'Ruby' with 'Watir-Webdriver' where the code looks like this:
prefs = {
'safebrowsing' => {
'enabled' => true,
}
}
b = Watir::Browser.new :chrome, :prefs => prefs
Starting the browser like this, with safebrowsing option enabled, downloads the xml files without the message warning. The principle should be the same for Selenium with any programming language.
#####
Edited: 13-04-2017
In latest version of Google Chrome the above solution is not enough. Additionally, it is necessary to start the browser with the following switch:
--safebrowsing-disable-download-protection
Now, the code for starting the browser would look something like this:
b = Watir::Browser.new :chrome, :prefs => prefs, :switches => %w[--safebrowsing-disable-download-protection]))
I am posting below the complete code that got file download working for me:
Hope it helps :-) I am using Java-Selenium
System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
String downloadFilepath = "D:/MyDeskDownload";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("safebrowsing.enabled", "true");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
Following Python code works for me
chromeOptions = webdriver.ChromeOptions()
prefs = {'safebrowsing.enabled': 'false'}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)
The accepted answer stopped working after a recent update of Chrome. Now you need to use the --safebrowsing-disable-extension-blacklist and --safebrowsing-disable-download-protection command-line switches. This is the WebdriverIO config that works for me:
var driver = require('webdriverio');
var client = driver.remote({
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'disable-extensions',
'safebrowsing-disable-extension-blacklist',
'safebrowsing-disable-download-protection'
],
prefs: {
'safebrowsing.enabled': true
}
}
}
});
Note that I am also disabling extensions, because they generally interfere with automated testing, but this is not strictly needed to fix the problem with downloading XML and JavaScript files.
I found these switches by reading through this list. You can also see them in the Chromium source.
I came across this recently, using Katalon Studio, Chrome version 88.
Thankfully just the enabling safebrowsing did the trick. You access the settings via "Project Settings" and you navigate to "Desired Capabilities" -> "Web UI" -> "Chrome".
If you don't have a "prefs" setting add it and set the type to Dictionary. Then in the Value add a boolean named "safebrowsing.enabled" and set the value to "true".
Result might look like:
(And you can the default directory setting has nothing to do with this example).
I used all of suggested chrome options in C# and only when my internet connected worked for me but when internet disconnected none of them work for me.
(I'm not sure.may be chrome safebrowsing need to internet connection)
By using older version of chrome(version71) and chromedriver(version 2.46) and after downloading,i saw downloaded XML file name constains 'Unconfirmed' with 'crdownload' extension
and parsing XML file wouldn't work properly.
Finally, creating wait with Thread.Sleep(1000) solved my problem.
IWebDriver Driver;
//chromedriver.exe version2.46 path
string path = #"C:\cd71";
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(path, "chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// options.AddArgument("headless");
options.AddArgument("--window-position=-32000,-32000");
options.AddUserProfilePreference("download.default_directory", #"c:\xmlFiles");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddUserProfilePreference("safebrowsing.enabled", "true");
Driver = new ChromeDriver(driverService, options);
try
{
Driver.Navigate().GoToUrl(url);
Thread.Sleep(1000);
//other works like: XML parse
}
catch
{
}
For context, I had a .csv with a list of .swf flash documents and their respective urls. Since the files could only be accessed after a valid login, I couldn't use a simple requests based solution.
Just like .xml, downloading a .swf triggers a similar prompt.
None of the answers worked for me.
So I stripped away all the extra arguments and settings the above answers proposed and just made the chrome instance headless.
options.add_argument("--headless")
prefs = {
"download.default_directory": "C:\LOL\Flash",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
}
options.add_experimental_option("prefs",prefs)
The only workaround that works for me:
Use argument with path to chrome profile
chromeOptions.add_argument(chrome_profile_path)
Search for file download_file_types.pb in chrome profile folder.
In my case ..chromedriver\my_profile\FileTypePolicies\36\download_file_types.pb
Backup this file and then open with any hexeditor (you can use oline).
Search for the filetype you want to download, i.e. xml and change it to anything i.e. xxx
Im using Google Version 80.0.3987.122 (Official Build) (32-bit) and ChromeDriver 80.0.3987.106. Getting the same error even after adding the below while downloading a .xml file.
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.AddArguments(#(
"--disable-extensions",
"--ignore-certificate-errors"))
$download = "C:\temp\download"
$ChromeOptions.AddUserProfilePreference("safebrowsing.enabled", "true");
$ChromeOptions.AddUserProfilePreference("download.default_directory", $download);
$ChromeOptions.AddUserProfilePreference("download.prompt_for_download", "false");
$ChromeOptions.AddUserProfilePreference("download.directory_upgrade", "true");
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.