How to run a front-end test in Ubuntu without a monitor

Source: Internet
Author: User

How to run a front-end test in Ubuntu without a monitor

A long time ago, I also used selenium for automated integration testing, using HtmlUnit webdriver, so no display is needed. However, HtmlUnit is always unsatisfactory. Recently, I found this article in my project to solve my long-standing problem: Running Firefox integration testing on servers without monitors.

Selenium is a web automation testing framework. It can be used for automated web application testing. However, I don't just use it for testing. I also use it to crawl javascript or AJAX content from the sign-in page of an e-commerce website.

As a programmer, I am not satisfied with Using Selenium IDE to record and replay macro records. This is not suitable for deploying on multiple servers. In this case, you need Selenium WebDriver, which is flexible and runs Selenium headless and does not need to display devices on the server.

Why should I run the Headless Selenium test?

When you want to run Robust Automatic operations on the server, and its operations depend on 27X7, you also want it to be stable, selenium is your only choice. However, Selenium needs to run on a browser. So you have to lie to Selenium to make it feel that it is running on a machine with a monitor. In this way, you can run automated tests without losing stability and scalability.

How to run Selenium headless on Ubuntu

This tutorial aims to configure and run selenium headless on ubuntu with Mozilla Firefox as the main browser.

Install Firefox headless

Make sure your ubuntu is installed with the latest Firefox version. I have encountered incompatibility between Selenium and Firefox versions. If you have not installed Firefox or use an earlier version of Firefox, follow these steps to Upgrade Firefox:

Add the following to/etc/apt/sources. list:

Ppa: mozillateam/firefox-stable

Run the following command to upgrade or install Firefox

Sudo apt-get update

Sudo apt-get install firefox

After running successfully, the latest version of Firefox should be installed on ubuntu.

Install Xvfb-an X Virtual framework

This simulation framework uses virtual memory to allow X-Server to run on machines without display devices. In this way, the browser can run. To install xvfb on ubuntu and Debian, run the following command:

Sudo apt-get install xvfb

Now, you can run the xvfb service on a digital display device to prevent conflicts when you add devices in the next stage. In this tutorial, we assign a display device 10.

Sudo Xvfb: 10-ac

-Ac: Disable access control for xvfb. Okay, the server can run.

Start the browser

Before running the browser, you must first set the DISPLAY environment variable to specify the DISPLAY device on which xvfb runs. Before adding environment variables, let's check that all of these are as expected:

Export DISPLAY =: 10

Firefox

If no error is displayed on the terminal (terminal), it means that you have successfully run Firefox on ubuntu without a display device. It runs until you use ctrl + C or other similar methods to stop it. At the same time, it does not have any output.

If you can successfully run the above steps, the next part will be easy. Now we can run selenium on the ubuntu server, just as you are running locally. In the next section of this tutorial, I will show you how to run an independent selenium server and use the PHP selenium webdriver to connect to the server.

Summary

A long time ago, I also used selenium for automated integration testing, using HtmlUnit webdriver, so no display is needed. However, HtmlUnit is always unsatisfactory. Recently, I found this article in my project to solve my long-standing problem: Running Firefox integration testing on servers without monitors.

In this article, I will try to explain it more. Something wrong. Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.