Selenium is an automated web testing framework. Using this we can automate the browser functioning for testing any web application. Using selenium you can run predefined code to navigate between multiple pages and test application with predefined rules. This tutorial will help you to setup Selenium with Firefox on Ubuntu, Debian and LinuxMint systems.

Advertisement

Read This: Setup Selenium with ChromeDriver on Ubuntu

Step 1 – Prerequisites

Execute the following commands to install 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 service.

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

Also, install Java on your system. Use the below command to install the latest available java version.

sudo apt-get install default-jdk 

Step 2 – Install Firefox with Driver

Firefox is available under default apt repositories. You can simply install it by running the following command from the command prompt.

sudo apt-get -y install firefox

Also, download the geckodriver for the firefox.

wget https://github.com/mozilla/geckodriver/releases/download/v0.25.0/geckodriver-v0.25.0-linux64.tar.gz
tar xzf geckodriver-v0.25.0-linux64.tar.gz
sudo mv geckodriver /usr/bin/geckodriver 

Step 3 – Download Selenium Server Jar

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.

mkdir ~/selenium && cd ~/selenium 
wget https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar

Also download the testng-6.5.1.jar file to your system.

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

Step 4 – Start Selenium Server

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

Run Selenium Server

DISPLAY=:1 xvfb-run java -jar ~/selenium/selenium-server-standalone-3.13.0.jar

Your Selenium server is now running with firefox. Use this server to run your test cases written in Selenium using the Firefox web browser.

Step 5 – Sample Java Program (Optional)

This is an optional step. It describes running a single test case using Selenium standalone server and FirefoxDriver. This Java program will open a specified website URL and check if defined string presents 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 file.

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-3.141.59.jar and testng-6.5.1.jar. Then compile the java program and run it.

export CLASSPATH=".:selenium-server-standalone-3.141.59.jar:testng-6.5.1.jar"

Now, compile your Java program and run it.

javac TecAdminSeleniumTest.java
java TecAdminSeleniumTest

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

Share.

6 Comments

  1. Kamalakkannan on

    java TecAdminSeleniumTest
    Error: Could not find or load main class TecAdminSeleniumTest
    Caused by: java.lang.ClassNotFoundException: TecAdminSeleniumTest

  2. At the end you write: “Start the Chrome via standalone selenium server using Xvfb utility.”
    isn’t it for firefox?!

  3. Muhammad hafeez on

    Thanks for your great article

    I’m getting this error

    xvfb-run: error: Xvfb failed to start

    while running following command

    DISPLAY=:1 xvfb-run java -jar ~/selenium/selenium-server-standalone-3.13.0.jar

    • Maybe it’s because you need to find the directory where selenium-server-standalone-3.13.0.jar downloaded. In my directory I found that file in /home/selenium-server-standalone-3.13.0.jar.

Leave A Reply

Exit mobile version