Install cypress.io dependencies on Amazon Linux AMI ec2 instance

This post is only focused on how to install dependencies required by cypress.io front-end testing tool on Amazon Linux AMI EC2 instance. To setup cypress tool for testing, please refer their official documentation. If you’re just interested to get the dependencies installed on amazon ec2 with AMI (rather then reading the explanation), then jump to this automation part directly!

We recently changed our front end testing tool from Casper to cypress. Check out the features that why we chose cypress!

SIDE NOTE

This post was originally written when I was trying to deal with this problem with version of Cypress 1.4.1. As of version 3.0 they changed the binary folder path (see the details), downloads the matching version binary to the global system cache, so that the binary can be shared between projects. If you haven’t upgrade it then you should do it to the latest version (as of writing this, it’s 3.0.1) and also checkout the change log to see the coolest update they made.

When I did set up the cypress.io tool (version: 3.0.1) on our build machine which runs on Amazon Linux AMI, I just tried to run it in headless mode. It was griping about one of the missing dependencies XVFB (X virtual framebuffer).

XVFB missing while running test cases using cypress tool

I also checked out the official doc to get work around with the dependencies, but that was not enough. Later I did some search on the web and I found this post which had the similar problem. I took the same approach to resolve the dependencies by using ldd program.

The ldd(list dynamic dependencies) can be used to show you the shared libraries required by any given program.

I already did the set up for the kitchensink example project in the home directory with its dependencies.please update the package.json with latest cypress version in devDependenciesbefore doing npm install. As of writing this, package.json still has old version (2.1.0) of cypress in devDependencies.

As I mentioned earlier in SIDE NOTE that as of version 3.0, Cypress downloads the matching Cypress binary to the global system cache and that default location for Linux is ~/.cache/Cypress.

So, you will see which shared libraries are required by Cypress binary when you hit the command ldd ~/.cache/Cypress/3.0.1/Cypress/Cypress, but we’re interested to cover only missing libraries. So we will pipe the command grepwith the command lddto find out not found libraries and the command is ldd ~/.cache/Cypress/3.0.1/Cypress/Cypress | grep 'not found'.

$ ldd ~/.cache/Cypress/3.0.1/Cypress/Cypress | grep 'not found' libgtk-x11-2.0.so.0 => not found libgdk-x11-2.0.so.0 => not found libatk-1.0.so.0 => not found libpangocairo-1.0.so.0 => not found libgdk_pixbuf-2.0.so.0 => not found libcairo.so.2 => not found libpango-1.0.so.0 => not found libXcursor.so.1 => not found libXdamage.so.1 => not found libXrandr.so.2 => not found libXfixes.so.3 => not found libXss.so.1 => not found libgconf-2.so.4 => not found libcups.so.2 => not found

As you can see, it’s not just XVFB, but there are 14 shared libraries as per the above output which are required by Cypress. Let’s cover those first, which are easily available on Amazon Linux AMI.

So, let’s install that first, as XVFB easily available on Amazon Linux.

yum -y install Xvfb

After this, If you check again the missing libraries using ldd command:

$ ldd ~/.cache/Cypress/3.0.1/Cypress/Cypress | grep 'not found' libgtk-x11-2.0.so.0 => not found libgdk-x11-2.0.so.0 => not found libatk-1.0.so.0 => not found libpangocairo-1.0.so.0 => not found libgdk_pixbuf-2.0.so.0 => not found libcairo.so.2 => not found libpango-1.0.so.0 => not found libXcursor.so.1 => not found libXrandr.so.2 => not found libXss.so.1 => not found libgconf-2.so.4 => not found libcups.so.2 => not found

If you give attention closely in the above output, you will notice there are only 12 shared libraries missing now, as XVFB installation step covered two libraries which are libXdamage and libXfixes.

In next step, we will install pango, libXrandr, libXcursor, libcups. (libcups.so.2 is provided by package cups-libs, see this thread!)

You can check the missing libraries at this step with ldd command (ldd ~/.cache/Cypress/3.0.1/Cypress/Cypress | grep 'not found'). But I will just move forward to target libXss. libXss is X11 Screen Saver extension library which is available for rpm based system under the different name libXScrnSaver. This we need to install from centos mirror. To install libXss,

Verification

Now, Let’s verify that cypress is working or not. First, start the server from the directory of cypress-example-kitchensink with command npm start. From another ssh session, go to the directory cypress-example-kitchensink and hit the command cypress run. You should see the output as per the following image nearly at the end of the test.

Cypress kitchen sink example test

Automation

I already made a script to automate these installation steps and here it is:

cypress tool dependencies installation script

Put proper version in CYPRESS_EXECUTABLE_FOLDER in above script! If you’re using custom location using CYPRESS_CACHE_FOLDER then please update the variable CYPRESS_EXECUTABLE_FOLDER path value according to it.

I hope sharing this would help so that someone does not have to search and go through the dependencies installation steps. Thanks!