How To Run Selenium Tests In Brave Browser Using ChromeDriver?
Selenium Tests in Brave Browser? This question seems hideous to you but this is possible and quite easy if you know how to launch Chrome Browser through Selenium. But before moving ahead why not we talk about Brave Browser.
What is Brave Browser ?
Brave Browser is an open-source browser from Brave Software, Inc and this browser is based on Chromium project. Chrome Browser also use the chromium project…It means both browsers are distant siblings.
Currently, brave browser is available for Windows, Mac, Linux, iOS and Android. But this not the USP of the Browser. Its USP is fast and ads free browsing experience.
In 2021, Privacy is major concern across the world. More People are searching for safe browsing. Due to this, people are going for either tor browsers or moving towards Brave Browser. Brave browser also supports Tor and for this user can click on hamburger menu on the top right corner of the browser.
How Selenium WebDriver communicates with Brave Browser?
Like Chrome Browser, Brave Browser also needs one driver which establishes the communication between Selenium WebDriver and Brave Browser. This is possible through ChromeDriver executable.. Here you will be thinking we are talking about Brave but Why we are talking about ChromeDriver. This is because, Brave Browser uses Chromium platform. For all chromium platform browsers, chromedriver executable driver is must for the communication between Selenium WebDriver and Browser. ChromeDriver acts as bridge between Selenium & Browser to run Selenium Test in Brave Browser.
So lets talk about ChromeDriver Executable Driver.
What is ChromeDriver ?
ChromeDriver is a medium between Selenium WebDriver and Brave Browser or Chrome Browser for communication between Selenium WebDriver Scripts and Browser. This ChromeDriver acts as a standalone server which implements webdriver wire protocol for Chromium for informing browser to perform certain actions.
Without this driver, we could not launch Chrome or Brave Browser Using Selenium.
What are the Steps to run Selenium Tests In Brave Browser ?
Nothing extra stuff is needed to run your Selenium Tests in Brave Browser, If you have already written code to support Selenium Tests in Chrome. Same code can be used with one additional step.
So let’s learn to run Selenium WebDriver Scripts In Brave Browser.
1- Since brave web browser is based on chromium project. We need selenium chromedriver executable and which can be downloaded from official chromium project. For this executable, I will suggest you to download the latest version because version on brave goes hand to hand with Chrome Browser.
Steps to download ChromeDriver On WIndows:
a) Navigate to https://www.selenium.dev/downloads/
b) Scroll down to Browser Section and Under Chrome Label, Click on documentation.
c) Now on Chromium Official WebPage, Navigate to All versions available in Downloads label like this and Click on ChromeDriver<version>
This version might change when you would be reading this post.So always pick the version which is coming after the text Latest stable release :
d) Now download the driver from here by clicking on chromedriver_win32.zip
e) Unzip the zip file downloaded and copy the path. In my case, Path on my machine is D:\selenium\chromedriver_win32\chromedriver.exe
2- Brave Binary path: This is the path where brave browser exe is present on local machine. So in general path for brave will be like this ( For Windows)C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
3- Now is the time to call ChromeOptions class to inform ChromeDriver about chromium binary path. ChromeDriver asks this binary path during initialization of Chrome/Brave instance from some custom location otherwise it will pick the default path of chrome browser exe. This time, in place of Chrome binary we will provide path of Brave Browser Binary path. So that ChromeOptions could pass information to ChromeDriver session to run Selenium Scripts On Brave Browser.
If you think, what is ChromeOptions?, then let me tell you in 2-3 lines about ChromeOptions
Chrome Options in Selenium WebDriver is a class which have convenient methods which can change ChromeDriver Sessions by passing capabilities.
So lets see the ChromeOptions initialization.
ChromeOptions options = new ChromeOptions(); options.setBinary("/path/to/other/chrome/binary"); WebDriver driver = new ChromeDriver(options);
first two lines are for setting binary path, and third line is for initializing the brave browser using ChromeDriver Class.
So lets take one scenario:
1- launch Brave browser
2- Open https://abodeqa.com
3- Click on Contact Us Menu link.
4- Close Brave Browser.
package webdriverExample;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class RunSeleniumScriptInBraveBrowserClass {
public static void main(String[] args) {
// setting chromedriver system classpath
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
//Initializing ChromeOptions Object
ChromeOptions options = new ChromeOptions();
//Setting Binary Path of Brave Browser in options object.
options.setBinary("C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe");
//Initializing Chrome Browser Instance
WebDriver driver = new ChromeDriver(options);
//Maximizing Browser
driver.manage().window().maximize();
//Launching https://abodeqa.com
driver.get("https://abodeqa.com");
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[text()='Contact Us']")).click();
driver.quit();
}
}
So above code will run Selenium Scripts In Brave Browser.
But If you want to remove System Properties and wants to manage ChromeDriver automatically in your script in that case, you need to add WebDriverManager in Our Script. This will automatically download all the latest version and will manage the version of Brave Browser and ChromeDriver.exe
Hope you have enjoyed this post, So please share it with your friends to read or share on social media.
Thanks
This is a fantastic blog from which people can learn a lot. It is very informative and is explained in…
Thanks for sharing such knowledgeable Content on Automation testing, to know how to enhance the performance of ERP's like Oracle…
Thanks.. this list is much needed.
This one is also good to use. Thanks for sharing this.. Might be we can also add it in list…
How about youtube-dl?