chromedriver – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Sat, 17 Dec 2022 10:54:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Setup Selenium with Chrome Driver on Fedora https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/ https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/#comments Mon, 17 Feb 2020 10:26:18 +0000 https://tecadmin.net/?p=20173 This tutorial will help you to set up Selenium with ChromeDriver on Fedora systems. This tutorial also includes an example of a Java program that uses the Selenium standalone server and ChromeDriver and runs a sample test case. This tutorial described how to set up a selenium server with a chrome driver on a Fedora [...]

The post How to Setup Selenium with Chrome Driver on Fedora appeared first on TecAdmin.

]]>
This tutorial will help you to set up Selenium with ChromeDriver on Fedora systems. This tutorial also includes an example of a Java program that uses the Selenium standalone server and ChromeDriver and runs a sample test case.

This tutorial described how to set up a selenium server with a chrome driver on a Fedora system. Also, you will get a sample Java program to run a small test over selenium with a headless chrome driver.

Prerequisites

Login to your Fedora system with Sudo privileged account. Launch a terminal and execute the following commands to install the required packages on your system.

sudo dnf install unzip wget java-11-openjdk java-11-openjdk-devel 

Step 1 – Installing Google Chrome

Enable the Google chrome repository for installing latest versions. Execute the following commands, this will enable google-chrome repo on your Fedora system:

sudo dnf install fedora-workstation-repositories 
sudo dnf config-manager --set-enabled google-chrome 

Next install the Google chrome web browser:

sudo dnf install google-chrome-stable  

Step 2 – Install ChromeDriver

You are also required to set up ChromeDriver on your system. ChromeDriver is a standalone server which implements WebDriver’s wire protocol for Chromium. The WebDriver is an open-source tool for automated testing of web apps across multiple browsers.

wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip 
unzip chromedriver_linux64.zip 

You can find the latest ChromeDriver on its official download page. Now execute below commands to configure ChromeDriver on your system.

sudo mv chromedriver /usr/bin/chromedriver 
sudo chown root:root /usr/bin/chromedriver 
sudo chmod +x /usr/bin/chromedriver 

Step 3 – Download Required Jar Files

The Selenium Server is required to run Remote Selenium WebDrivers. You need to download the Selenium standalone server jar file using the below commands or visit here to find the latest version of Jar file.

wget https://selenium-release.storage.googleapis.com/3.13/selenium-server-standalone-3.13.0.jar 

Also, download the TestNG jar file on your system.

wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip 
unzip testng-6.8.7.jar.zip 

Your Selenium server is now running with Chrome. Use this server to run your test cases written in Selenium using the Google Chrome web browser. The next step is an optional step and doesn’t depend on Step 5.

Step 4 – Testing with Sample Java Application

This is an optional step. It describes running a single test case using the Selenium standalone server and ChromeDriver. Let’s create a Java program using the Selenium server and Chrome Driver. This Java program will open a specified website URL and check if the defined string is present on the webpage or not.

Create a Java program by editing a file in text editor.

vim TecAdminSeleniumTest.java 

Add the below content to the file.

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class TecAdminSeleniumTest {

        public static void main(String[] args) throws IOException, InterruptedException {
                System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--headless");
                chromeOptions.addArguments("--no-sandbox");

                WebDriver driver = new ChromeDriver(chromeOptions);

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

                Thread.sleep(1000);

                if (driver.getPageSource().contains("I'm Feeling Lucky")) {
                        System.out.println("Pass");
                } else {
                        System.out.println("Fail");
                }
                driver.quit();
        }
}

You can change the URL “https://google.com” with any other URL of your choice, Then also change the search string like “I’m Feeling Lucky” used in the above Java program. Save your java program and execute it. First, you need to set the Java CLASSPATH environment variable including the selenium-server-standalone.jar and testng-6.8.7.jar. Then compile the java program and run it.

export CLASSPATH=".:selenium-server-standalone.jar:testng-6.8.7.jar" 
javac TecAdminSeleniumTest.java 

Then run command:

java TecAdminSeleniumTest 
Output
Starting ChromeDriver 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706) on port 10968 Only local connections are allowed. Feb 01, 2020 10:51:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Pass

You will see the results below. If the defined search string is found, You will get the message “Pass” and if the string is not found on the webpage, you will get the “Fail” message on the screen.

Selenium test case results

Conclusion

You have successfully configured Selenium with ChromeDrive on your Fedora system. Now you can automate your test cases and run them periodically. I hope this tutorial contributes a little help to you with the automation testing. Please do not forget to share this tutorial.

The post How to Setup Selenium with Chrome Driver on Fedora appeared first on TecAdmin.

]]>
https://tecadmin.net/setup-selenium-with-chrome-driver-on-fedora/feed/ 3
How to Setup Selenium with ChromeDriver on Debian Linux https://tecadmin.net/setup-selenium-with-chromedriver-on-debian/ https://tecadmin.net/setup-selenium-with-chromedriver-on-debian/#comments Sun, 12 Aug 2018 14:09:17 +0000 https://tecadmin.net/?p=16698 This tutorial will help you to set up Selenium with ChromeDriver on Debian 9 and Debian 8. This tutorial also includes an example of a Java program that uses Selenium standalone server and ChromeDriver and runs a sample test case. Xvfb (X virtual framebuffer) is an in-memory display server for a UNIX-like operating system (e.g., [...]

The post How to Setup Selenium with ChromeDriver on Debian Linux appeared first on TecAdmin.

]]>
This tutorial will help you to set up Selenium with ChromeDriver on Debian 9 and Debian 8. This tutorial also includes an example of a Java program that uses Selenium standalone server and ChromeDriver and runs a sample test case.

Xvfb (X virtual framebuffer) is an in-memory display server for a UNIX-like operating system (e.g., Linux). It implements the X11 display server protocol without any display. This is helpful for CLI applications like CI services.

Step 1 – Prerequisites

Login to your Debian system as sudo privileged user and execute the following commands to install the required packages on your system.

sudo apt-get update
sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4

Also, install Java on your system. Use below command to install OpenJDK on your system, If you like install Oracle Java 8 on your Debian system.

sudo apt-get install default-jdk 

Step 2 – Install Google Chrome

Now install Latest Google chrome on your Debian system using commands below. Google chrome headless feature opens multipe doors for the automation.

sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
sudo echo "deb [arch=amd64]  http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable

Step 3 – Install ChromeDriver

ChromeDriver is a standalone server which implements WebDriver’s wire protocol for Chromium. The WebDriver is an open source tool for automated testing of web apps across multiple browsers.

wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip

You can find the latest ChromeDriver on its official download page. Now execute below commands to configure ChromeDriver on your system.

sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver

Step 4 – Download Required Jar Files

The Selenium Server is required to run Remote Selenium WebDrivers. You need to download the Selenium standalone server jar file using the below commands or visit here to find the latest version of Jar file.

wget https://selenium-release.storage.googleapis.com/3.13/selenium-server-standalone-3.13.0.jar

Also, download the testng-6.8.7.jar file to your system.

wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip
unzip testng-6.8.7.jar.zip

Step 5 – Start Chrome via Selenium Server

Your server setup is ready. Start the Chrome via standalone selenium server using Xvfb utility.

Run Chrome via Selenium Server

xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar selenium-server-standalone.jar

Use -debug option at end of command to start server in debug mode.

You can also Start Headless ChromeDriver by typing the below command on terminal.

chromedriver --url-base=/wd/hub

Your Selenium server is now running with Chrome. Use this server to run your test cases written in Selenium using the Google Chrome web browser. The next step is an optional step and doesn’t depend on Step 5.

Step 6 – Sample Java Program (Optional)

This is an optional step. It describes running a single test case using Selenium standalone server and ChromeDriver. Let’s create a Java program using the Selenium server and Chrome Driver. This Java program will open a specified website URL and check if the defined string is present on the webpage or not.

Create a Java program by editing a file in text editor.

vim TecAdminSeleniumTest.java

Add the below content to the file.

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class TecAdminSeleniumTest {

        public static void main(String[] args) throws IOException, InterruptedException {
                System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--headless");
                chromeOptions.addArguments("--no-sandbox");

                WebDriver driver = new ChromeDriver(chromeOptions);
                driver.get("https://google.com");
                Thread.sleep(1000);

                if (driver.getPageSource().contains("I'm Feeling Lucky")) {
                        System.out.println("Pass");
                } else {
                        System.out.println("Fail");
                }
                driver.quit();
        }
}

You can change the URL “https://google.com” with any other URL of your choice, Then also change the search string like “I’m Feeling Lucky” used in the above Java program. Save your java program and execute it. First, you need to set the Java CLASSPATH environment variable including the selenium-server-standalone.jar and testng-6.8.7.jar. Then compile the java program and run it.

export CLASSPATH=".:selenium-server-standalone.jar:testng-6.8.7.jar"
javac TecAdminSeleniumTest.java
java TecAdminSeleniumTest

You will see the results below. If the defined search string is found, You will get the message “Pass” and if the string is not found on the webpage, you will get the “Fail” message on the screen.

Selenium test case results

The post How to Setup Selenium with ChromeDriver on Debian Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/setup-selenium-with-chromedriver-on-debian/feed/ 2
How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/ https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/#comments Mon, 19 Feb 2018 16:17:20 +0000 https://tecadmin.net/?p=15095 This tutorial will help you to set up Selenium with ChromeDriver on Ubuntu, and LinuxMint systems. This tutorial also includes an example of a Java program that uses a Selenium standalone server and ChromeDriver and runs a sample test case. Read This: Setup Selenium with Firefox on Ubuntu Step 1 – Prerequisites Execute the following [...]

The post How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 appeared first on TecAdmin.

]]>
This tutorial will help you to set up Selenium with ChromeDriver on Ubuntu, and LinuxMint systems. This tutorial also includes an example of a Java program that uses a Selenium standalone server and ChromeDriver and runs a sample test case.

Read This: Setup Selenium with Firefox on Ubuntu

Step 1 – Prerequisites

Execute the following commands to install the required packages on your system. Here Xvfb (X virtual framebuffer) is an in-memory display server for a UNIX-like operating system (e.g., Linux). It implements the X11 display server protocol without any display. This is helpful for CLI applications like CI services.

sudo apt update 
sudo apt install -y unzip xvfb libxi6 libgconf-2-4 

Also, install Java on your system. Let’s install Oracle Java 8 on your system or use the below command to install OpenJDK.

sudo apt install default-jdk 

Step 2 – Install Google Chrome

Now install Latest Google chrome package on your system using the below list commands. Google chrome headless feature opens multipe doors for the automation.

sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add 
sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" 
sudo apt -y update 
sudo apt -y install google-chrome-stable 

Step 3 – Installing ChromeDriver

You are also required to set up ChromeDriver on your system. ChromeDriver is a standalone server that implements WebDriver’s wire protocol for Chromium. The WebDriver is an open-source tool for the automated testing of web apps across multiple browsers.

Find out the Google chrome version installed on your system.

google-chrome --version 
Output
Google Chrome 94.0.4606.71

Next, visit the Chromedriver download page and download the matching version of chromedriver on your system.

In my case, Google Chrome 94 is running on my system. So download the following file. You must make sure to download the correct version of a file:

wget https://chromedriver.storage.googleapis.com/94.0.4606.61/chromedriver_linux64.zip 
unzip chromedriver_linux64.zip 

You can find the latest ChromeDriver on its official download page. Now execute below commands to configure ChromeDriver on your system.

sudo mv chromedriver /usr/bin/chromedriver 
sudo chown root:root /usr/bin/chromedriver 
sudo chmod +x /usr/bin/chromedriver 

Step 4 – Download Required Jar Files

The Selenium Server is required to run Remote Selenium WebDrivers. You need to download the Selenium standalone server jar file using the below commands or visit here to find the latest version of Jar file.

wget https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar 
mv selenium-server-standalone-3.141.59.jar selenium-server-standalone.jar 

Also, download the testng-6.8.7.jar file to your system.

wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip 
unzip testng-6.8.7.jar.zip 

Step 5 – Start Chrome via Selenium Server

Your server setup is ready. Start Chrome via a standalone selenium server using the Xvfb utility.

Run Chrome via Selenium Server

xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar selenium-server-standalone.jar 

Use -debug option at end of the command to start the server in debug mode.

You can also Start Headless ChromeDriver by typing the below command on the terminal.

chromedriver --url-base=/wd/hub 

Your Selenium server is now running with Chrome. Use this server to run your test cases written in Selenium using the Google Chrome web browser. The next step is an optional step and doesn’t depend on Step 5.

Step 6 – Sample Java Program (Optional)

This is an optional step. It describes running a single test case using a Selenium standalone server and ChromeDriver. Let’s create a Java program using the Selenium server and Chrome Driver. This Java program will open a specified website URL and check if a defined string is present on the webpage or not.

Create a Java program by editing a file in a text editor.

vim TecAdminSeleniumTest.java 

Add the below content to the file.

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class TecAdminSeleniumTest {

        public static void main(String[] args) throws IOException, InterruptedException {
                System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--headless");
                chromeOptions.addArguments("--no-sandbox");

                WebDriver driver = new ChromeDriver(chromeOptions);

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

                Thread.sleep(1000);

                if (driver.getPageSource().contains("I'm Feeling Lucky")) {
                        System.out.println("Pass");
                } else {
                        System.out.println("Fail");
                }
                driver.quit();
        }
}

You can change the URL “https://google.com” with any other URL of your choice, Then also change the search string like “I’m Feeling Lucky” used in the above Java program. Save your java program and execute it. First, you need to set the Java CLASSPATH environment variable including the selenium-server-standalone.jar and testng-6.8.7.jar. Then compile the java program and run it.

export CLASSPATH=".:selenium-server-standalone.jar:testng-6.8.7.jar" 
javac TecAdminSeleniumTest.java 
java TecAdminSeleniumTest 

You will see the results below. If the defined search string is found, You will get the message “Pass” and if the string is not found on the webpage, you will get the “Fail” message on the screen.

Selenium test case results

The post How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/setup-selenium-chromedriver-on-ubuntu/feed/ 42