Adding Browser Extentions with Selenium WebDriver

When Selenium WebDriver launch a browser , it creates a new profile or options set with browser’s default features.This launched browser does not contain addons or extentions.In everytime we need to add on , which addon or extention we want to use.

Chrome

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addExtensions( new File( "/path/to/extension.crx" )) ;
driver = new ChromeDriver(chromeOptions);

Firefox

FirefoxProfile profile = new FirefoxProfile() ; 
profile.addExtension( new File( "/path/to/addon.xpi" )) ; 
FirefoxOptions firefoxOptions = new FirefoxOptions() ; 
firefoxOptions.setProfile(profile) ; 
FirefoxDriver driver = new FirefoxDriver(firefoxOptions) ;

What's happening inside of WebDriver's engine bonnet ?

To drive a car , you need to have a licence plate.Nobody wants to mechanical engineering deggree or asks diffucult questions about how engine works ? However , if you want to create admirable test automations , you need to understand what’s happening behind the scene.

Selenium Web Driver briefly working with 3 steps.

  • Using JSON Wire Protocol(also known as Client API) takes our commands and sends them to browser specific drivers(GeckoDriver , ChromeDriver etc.).
  • These commands converting to browser’s native API and sending HTTP request
  • Then driver listens commands results from HTTP server and sends them back to Selenium

Install All Selenium WebDrivers with One Command

Did you ever want to install or upgrade all Selenium WebDrivers using one line commmand? On windows you can do it with a Chocolately.Chocolatey is a package manager for windows and yummy way to software installation.

Firstly , you need to install chocolately.To do it , open command prompt as an administrator then write this lines.

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

If installation is success , now you can install drivers

choco install selenium-all-drivers 

List of installed Web Drivers

  • selenium-opera-driver
  • selenium-ie-driver
  • selenium-edge-driver
  • selenium-all-drivers
  • selenium-gecko-driver
  • selenium-chrome-driver

All Selenium Web Drivers will be installed on under “C:\tools\selenium” directory.Don’t forget to add this path as “System Environments Variable”

Upgrade

Upgrading is similar to installation , just change the install variable as upgrade.

choco upgrade selenium-all-drivers
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×