TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Run Selenium Tests Using Crontab in Ubuntu
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Selenium Tutorial

Run Selenium Tests Using Crontab in Ubuntu

Last updated: Feb 25, 2024 10:42 am
By Meenakshi Agarwal
Share
6 Min Read
Run Selenium Tests Using Crontab in Ubuntu 14.04
Run Selenium Tests Using Crontab in Ubuntu 14.04.
SHARE

In one of our previous posts, we showcased how to run Selenium tests using a task scheduler in Windows 7. Today, we’ll show how you can run Selenium tests using crontab in Ubuntu. It’s a built-in Linux command to schedule your routine tasks such as automation.

Contents
1. Install <xvfb> on Ubuntu2. Setup a virtual screen using <xvfb>3. Prepare your Selenium tests to run from the command line4. Time to run Selenium tests using crontab

An important point which you should note that there may not be any desktop session open while running the Selenium tests on Ubuntu. So, we will also be handling such situations in this post. We will make sure to provide you with all the script code to take care of such use cases.

You might be wondering why didn’t we write a post on using Jenkins or Bamboo to schedule these tests. It’s because both of these tools internally use the same way that crontab already does. So you should prefer using the CI tools only if you need deployment and installation as well.

Because crontab won’t help you there. For our readers, we’ll surely do a detailed blog post on how to run Selenium tests using Jenkins. Let’s now begin to understand what you need to run Selenium tests using crontab in Ubuntu.

Run Selenium Tests Using Crontab in Ubuntu 14.04

We’ll walk you through all the steps you can use to run Selenium tests on Ubuntu. We’ve tested all these steps on a Ubuntu 14.04 test bed. Though, they’ll run on other platforms too except few of the installation steps.

The scope of this post is limited to setting up Ubuntu for Selenium and running tests. So, we won’t be telling you how to create a Selenium project in Eclipse or write your first test case using TestNG in Eclipse. 🙂

But you are welcome to follow the links provided in line with the above text if you wish to learn Selenium Webdriver from scratch. We do have some advanced Selenium Webdriver tutorials on our blog so you may even refer them as well.

Run Selenium Tests Using Crontab in Ubuntu 14.04
Run Selenium Tests Using Crontab in Ubuntu

Let’s now run through the steps. We suggest you try these steps on your system as we go along with this post.

1. Install <xvfb> on Ubuntu

1.1- First, update the Ubuntu, and then go on installing the headless Firefox with <xvfb>.

apt-get update
apt-get install xvfb

Note: For RHEL based system, you need to use the <yum> command instead of the <apt-get> command in Ubuntu.

# In RHEL, use this command.
yum install Xvfb firefox

1.2- If you don’t have <firefox>, then install it as well.

apt-get install firefox

1.3- Make sure, you’ve <java> installed. Run the below command.

java -version

If <java> is not available, then download and install it.

# It'll install <jre> to run your java program.
sudo apt-get install default-jre

# It'll install <jdk> to build your java program.
sudo apt-get install default-jdk

2. Setup a virtual screen using <xvfb>

2.1- Run the below command on the console. You need to run crontab as <sudo (root)>.

sudo crontab -e

2.2- Add the following command as your first cronjob.

@reboot sh -c 'Xvfb :99 -ac -screen 0 1024x768x8 > /tmp/xvfbmsg.log 2>&1 &'

3. Prepare your Selenium tests to run from the command line

For example, if you are using a Selenium TestNG project, then use the below command to run the tests.

#!/bin/bash

# make sure the xvfb service is running.
# run the following to be on safe side.
Xvfb :99 -ac &
export DISPLAY=:99

java -cp "path/to/testng.jar:path/to/testClass" org.testng.TestNG testng.xml

Save the above command say <seleniumtests.sh>.

4. Time to run Selenium tests using crontab

4.1- Run the below command on the console. You need to run crontab as <sudo (root)> so that your tests will run as root.

crontab -e

4.2- crontab uses the following syntax.

minute hour * * * command

4.3- Add the following entry in the crontab console.

0 22 * * * seleniumtests.sh

4.4- Alternatively you can try the following crontab option. It’s equivalent to the <0 0 * * *>.

@daily seleniumtests.sh

Now we are at the end of this blog post and hope you would now be ready to run Selenium tests using crontab on your test system. This blog post is our second submission to the series of Selenium testing tutorials that we recently started. Be ready for more such scintillating stuff. Till then, do something like this.

Get a tool, set up a lab, and start an experiment.

Best,

TechBeamers

You Might Also Like

20 Demo Sites for Automation Testing

Page Object Model (POM) and Page Factory Guide in Selenium Java

Selenium 4 With Python Guide

Selenium 4 Relative Locators Guide

Selenium Version 4 Features – What’s New?

TAGGED:Selenium Testing in Linux
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Run Selenium Tests Using Task Scheduler in Windows 7 Run Selenium Tests Using Task Scheduler – Windows 7
Next Article Selenium Webdriver Coding Tips to Improve Quality Selenium Webdriver Coding Tips for 2024

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x