4

Is it possible to run a Selenium test in Chromium Browser (not Google Chrome Browser)?

My GoogleDrive location: GoogleDrive location

My Chromium location: Chromium location

FYI: I am using Java

My code ( for the moment I am run FirefoxDriver(gecko):

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MainClass {

public static void main (String[] args){
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get ("https://www.seleniumhq.org/");
   }
} 

I thought that this code would help but without success. Runs Google Chrome, not Chromium:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Chromium {

public static void main (String[] args){
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\chromedriver.exe");
    System.setProperty("webdriver.chrome.binary", "C:\\Users\\User\\Downloads\\chrome-win\\chrome-win\\chrome.exe");
    WebDriver driver = new ChromeDriver();
    driver.get ("https://www.seleniumhq.org/");
   }
} 

What could be the problem? How can this question be resolved?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • As per docs [here](https://www.seleniumhq.org/docs/01_introducing_selenium.jsp#supported-browsers-and-platforms), chromium is not supported. – Kamal Feb 07 '19 at 07:25
  • @Kamal by the way recently I saw programmers run autotests on Chromium using JavaScript and Selenium. I can't remember where I saw it – Nikita Milaserdov Feb 07 '19 at 07:33
  • Please check https://stackoverflow.com/questions/5731953/use-selenium-with-chromium-browser – Kamal Feb 07 '19 at 07:39

2 Answers2

6

Chromium Browser have different version as follows:

  • Chrome Canary
  • Chrome from Dev Channel
  • Raw build of Chromium for Windows x64

Not sure which Chromium Browser version you are trying to use.

However to use Chrome Canary version you can use the ChromeOptions and setBinary() method to set the absolute path of the Chrome Canary binary and you can use the following solution:

  • Code Block:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    
    public class A_Chrome_Canary {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions opt = new ChromeOptions();
            opt.setBinary("C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe");
            WebDriver driver = new ChromeDriver(opt);
            driver.get("https://www.google.com/");
            System.out.println(driver.getTitle());
        }
    }
    
  • Console Output:

    Google
    
  • Browser Snapshot:

Chrome_Canary


Update

Not clear from your comments but you need to download the latest Chromium binary from either of the official repositories:

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
2

With the help of DebanjanB's answer, I developed the following code that can run on Chromium:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class A_Chrome_Canary {

    public static void main (String[] args){

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\IdeaProjects\\testselenium\\drivers\\chromedriver.exe");

    ChromeOptions opt = new ChromeOptions();

    opt.setBinary("C:\\Users\\User\\Downloads\\chrome-win\\chrome-win\\chrome.exe");

    WebDriver driver = new ChromeDriver(opt);

    driver.get("https://www.google.com/");

    System.out.println(driver.getTitle());

    }
}
Cody Gray
  • 222,280
  • 47
  • 466
  • 543