Run Selenium Tests Using Crontab in Ubuntu 14.04

In one of our previous posts, we’d showcased how to run Selenium tests using 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. 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 would also be handling such situations in this post. We would make sure to provide you 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 what 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 all 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 setup Ubuntu for Selenium and run 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 14.04.


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

Step-1: Install <xvfb> on Ubuntu.

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

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

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

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

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


Step-2: Setup a virtual screen using <xvfb>.

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

2.2- Add the following command as your first cronjob.


Step-3: Prepare your Selenium tests to run from command line.

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

Save the above command say <>.


Step-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 would run as root.

4.2- crontab uses the following syntax.

4.3- Add the following entry in the crontab console.

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


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.