EN
language & localization

Cypress end-to-end tests on a Magento store: how we test Carré Blanc before every release

What is Cypress, why use it and where does it stop? A clear answer first, then a real case: the end-to-end tests that check the Carré Blanc purchase journey before every release.

Hands typing on a laptop, banner for Cypress testing services

Cypress is a free, open-source tool for testing websites in a real browser. You write a scenario in JavaScript (“open a product page, add it to the cart, go to checkout”), and Cypress plays it like a visitor would, then tells you which step failed and why. We use it on our e-commerce projects to check the journeys that bring in money before every release.

This article answers the general question first: what Cypress is, why teams use it and where it stops. Then it shows how we use it on a real Magento store, the one we built for Carré Blanc.

What is Cypress?

The Cypress documentation describes the Cypress App as “a free, open source, locally installed app for writing and running tests”. It was first designed for end-to-end tests, meaning tests that drive the whole site from the outside, through the browser, as a customer would. It also runs component tests and can call an API directly (the cy.request command). A paid service, Cypress Cloud, records runs and shows results to the team; you do not need it to start.

A Cypress test is a short script. It visits a page, finds elements (a button, a field, a price), acts on them and checks the result. Cypress waits for each element on its own, so you do not fill your tests with fixed pauses. While a test runs, you watch it in the browser and can go back to any step to see what the page looked like at that moment.

Why use Cypress, and when not to

What our developers like about it:

  • it finds a broken journey in minutes, instead of a customer finding it on a Saturday;
  • a developer new to automated tests can write a useful test quickly, because the commands read like the steps of a journey;
  • you see the test run in a real browser, which makes debugging much easier;
  • tests are written in JavaScript, the language front-end developers already use;
  • it runs the same way on a laptop, on a test server or in a deployment pipeline.

It also has limits, and the Cypress trade-offs page lists them openly. Cypress is “not a general purpose automation tool”: it is not made for load or performance testing, or for scripting third-party sites. JavaScript is the only language for tests. It drives one browser at a time, and each test is bound to one domain, unless you use the cy.origin command to move to another one (for example, a payment page). It runs in Chrome-family browsers, Edge and Firefox; WebKit support, the engine behind Safari, is experimental.

The usual alternative is Selenium. It supports more browsers and lets you write tests in Java, C#, Python, Ruby or JavaScript. In our experience it takes longer to set up and runs slower. For e-commerce journeys on Chrome, Edge and Firefox, Cypress is the simpler choice, and that is why we use it.

The real cost is maintenance: every time a page changes, the tests that use it must change too. It still pays off, because nobody has to retest the whole site by hand after each deployment.

Three ways we run Cypress

  1. On demand, by the project manager. Before a delivery, the project manager starts the suite instead of clicking through every journey by hand.
  2. On a schedule, as monitoring. The suite runs at regular intervals. It records how long the pages take during the run and sends an email alert when a step fails. This is a warning signal, not a performance test.
  3. After each deployment. When new code reaches the test server, the suite runs on its own. A bug introduced by the new code shows up before the release, not after it.

The Carré Blanc suite

Carré Blanc is a French household linen brand with more than 110 shops in France. We moved its store from Magento 1 to Magento 2 with a Hyvä front end, and our ETL connects the site to the brand’s ERP, PIM and order management system. The store has features that a generic test would miss: click and collect, store locator, embroidery, payment in instalments. The whole project is in the Carré Blanc case study.

The Cypress suite follows the path of a real customer:

  • browse a category page and its product list;
  • open a product page;
  • add the product to the cart;
  • go through checkout to the end of the purchase.

What it catches: a step of the purchase journey that no longer works after a change. A button that does nothing, a cart that stays empty, a checkout step that fails: these are the bugs that cost sales, and the suite finds them before customers do.

What it does not catch: a layout that looks wrong but still works, a typo, a wrong price coming from the ERP, or a page that is slow under real traffic. Forms protected by a captcha also block automated tests, which is one reason we run the suite on development and test servers, not on the live store. Cypress checks that the journey works; people still check that it looks right and that the data is right.

How the suite fits into a release

A test is code, so it follows the same path as the feature it covers. The developer who changes a page updates the tests for that page in the same change. After deployment to the test server, the suite runs. The project manager reads the result, checks by hand what a test cannot see, and only then agrees to the release to production.

Our team works from Lyon and Hanoi, five or six hours apart depending on the season. A suite that runs at the end of the day in Hanoi gives a result that is ready when Lyon starts its morning. We describe how this one-team, two-office organisation works in practice in One team, two continents.

What a Cypress suite costs

We do not publish a fixed price, because the budget depends on a few clear factors:

  • the number of journeys to cover (the four steps above are the minimum for a store);
  • the special features of your checkout: click and collect, B2B approval, several payment methods;
  • test data: products, customer accounts and stock that stay stable on the test server;
  • maintenance: how often your pages change, since each change means updating tests.

The best start is small: cover the purchase journey first, run it after each deployment, then add journeys where bugs have already hurt.

Testing your own store

If you run a Magento store, or a Sylius or Symfony application, and each release still depends on manual checks, we can write and maintain the suite with your team. See our Cypress testing services, or our Magento maintenance and support offer, where the tests run with every update.

Share

LinkedIn Facebook X
Tanguy Rambaud

About the author

Tanguy Rambaud

Co-founder, consultant

Co-founder of Sutunam, Tanguy opened the first office in Hanoi in 2010 and advises executives on strategy and technology choices.