Run selenium cases in linux server using Chrome Browser

December 07, 2022 ・0 comments

In this article we will see How to run selenium cases in linux server using Chrome Browser in Headless Mode.

Detailed Steps:

[root@localhost ~]# yum-config-manager --enable ol7_optional_latest

[root@localhost ~]# wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm


[root@localhost ~]# yum -y install redhat-lsb libXScrnSaver

[root@localhost ~]# yum -y install google-chrome-stable_current_x86_64.rpm

 Install xvfb as root:

[root@localhost ~]# yum install xorg-x11-server-Xvfb


Start display:

[root@localhost ~]# Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99


Test The Code:

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.setHeadless(true);

System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/linux/chromedriver");

WebDriver driver = new ChromeDriver(chromeOptions);

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.get("https://demo.example.com/admin");

Trobuleshoot:

1.If the driver is not executable: Copy chromedriver and give 777 permission

2.unknown error: cannot find Chrome binary - Install chrome browser

3.unknown error: Chrome failed to start: crashed. - Run in headless mode 

Post a Comment

If you can't commemt, try using Chrome instead.