• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A community-driven Cypress testing suite for Magento 2

elgentos/magento2-cypress-testing-suite

A community-driven Cypress testing suite for Magento 2

This testing suite was announced in Peter Jaap his talk about Cypress testing in Magento 2 at Reacticon 4. Watch the talk for more information about Cypress testing.

image

A successful Cypress run which tests the store at https://hyva-demo.elgentos.io

image

homepage.spec.js tests running on https://hyva-demo.elgentos.io

You can see all runs of this testing suite in the public Cypress Dashboard for this project. See for example this succesfull run.

Table of Contents

Prerequisites

  • Magento 2.3.x / 2.4.x
  • Hyvä (1.1.17) or Luma-based theme
  • npm
  • An admin bearer token (see Setup)

Assumptions & limitations

Assumptions

  • Magento 2 runs in Single Store Mode

  • Default language is English

  • Viewport is 1920x1280, with support for mobile viewports

  • Sample Data is installed

  • Multi Source Inventory is not used

Not plug & play

This test suite is not plug & play for your store. A number of tests rely on Magento's default sample data. These tests will fail when you don't have the sample data. It is up to you to change the fixtures/selectors/tests to make them pass for your store.

Open source-only right now

We don't do Commerce builds over at elgentos, so we haven't spent time creating tests for Commerce-only functionality.

No 100% test coverage

We do not particularly strive for 100% test coverage. We have identified the most common and most revenue-dependent scenarios. For example, we do test viewing products, filtering categories, adding products to the cart etc, but we (currently) do not test the Email a Friend or Compare Products feature since these are rarely used in an average Magento store. We are perfectly willing to merge a PR with these tests of course.

No extensibility / inheritance of tests

You need to copy the whole suite into your project. We are open to suggestions on how to solve this, see Discussions.

The Hyvä checkout tests assume the React Checkout is used

The Hyvä checkout tests assume the Hyvä React Checkout. To skip checkout related Hyvä tests, set the environment variable CYPRESS_MAGENTO2_SKIP_CHECKOUT.
PR's are definitely welcome to improve the checkout related tests.

Progress

We are at 80%; 69 out of the proposed 86 tests are done.

Wording & naming are subject to change.

Spec file Group Test
account.spec.js Account test creation ✔️ it can create an account to log in with
Account activities ✔️ it creates an account to log in with and use for further testing
✔️ it can log out
✔️ it can show the account information page and display the name of the customer
✔️ it can change the password
✔️ it can change the name of the customer on the account information page
✔️ it can navigate to all customer account pages and displays the correct titles
✔️ it can navigate to order history and displays that there are no placed orders
✔️ it can add a new address
✔️ it can change an existing address
✔️ it can remove an address
✔️ it subscribe through the newsletter subscription page
✔️ it can add an address automatically when an order is placed
✔️ it can add a product to the wishlist of the logged in customer on a productpage and store it
✔️ it can edit the wishlist on the wishlist page
🔲 it can reset the password when it is forgotten
Do not login before these tests ✔️ it can login from cart without making changes to the cart
✔️ it can login from checkout
product-searches.spec.js Perform searches ✔️ it can perform search with multiple hits
✔️ it can find a single product
✔️ it can show a page for no search results when the searchterm cannot give any results
✔️ it can show suggestions when entering search terms
category.spec.js Category page tests ✔️ it can navigate to the category page and filter products on the color red
✔️ it can sort the products on price from lowest to highest
✔️ it can change the number of products to be displayed
✔️ it checks if the breadcrumb is displayed correctly
✔️ it checks if the pagination is working
✔️ it can switch from list to grid view
homepage.spec.js Home page tests ✔️ it can navigate to the homepage
✔️ it can perform search from homepage
✔️ it can open a category
✔️ it can show the header correctly and all links work
✔️ it can show the footer correctly and all links work
🔲 it can show the main section of the homepage correctly and all links work
✔️ it can subscribe to the newsletter
✔️ it can add products shown on the homepage to the cart when an add to cart button is present
🔲 it shows the cookie banner when cookies are not accepted yet (Vanilla Hyvä shows no cookie banner)
checkout.spec.js Checkout tests (guest) 🔲 it shows the correct products and quantities previously added to the cart
✔️ it shows correct prices like subtotal, VAT, shipping costs and total
✔️ it can see coupon discount in checkout
🔲 it can properly choose and use all listed payment methods
🔲 it can properly choose and use all listed shipping methods
🔲 it a conformation mail is send to the customer after placing the order
🔲 it an invoice is created and sent to the customer after placing the order
✔️ it after placing the order it is properly processed in the backend'
Checkout tests (logged in) 🔲 it can automatically fill in the name and address of the customer
✔️ it can find and order in the customer order history after having placed an order
cart.spec.js Cart tests ✔️ it can add a product to the cart
✔️ it can change the quantity in the cart
✔️ it can remove a product from the cart
✔️ it can add a coupon to the cart
✔️ it can delete an added coupon from the cart
✔️ it cannot add a non existing coupon
✔️ it displays the correct product prices and totals
🔲 it merges an already existing cart when a customer logs in
minicart.spec.js Minicart tests ✔️ it can open the cart slider by clicking on the cart icon in the header
✔️ it checks if the items and prices in the slider are displayed correctly
✔️ it can delete an item in the cart slider
✔️ it can change the quantity of an item in the cart slider
✔️ it can navigate to the cart with a link in the slider
✔️ it can navigate to the checkout with a link in the slider
product-page.spec.js Product page tests ✔️ it can display the title and image of the product
✔️ it shows the product price
✔️ it can configure the product when it is an configurable product
✔️ it can add the product to the cart
✔️ it can't add the product to the cart if it is a configurable product and no options are selected
✔️ it can add the product to the wishlist
✔️ it shows the correct breadcrumb
✔️ it can show reviews made by logged in customers
✔️ it can add a review when logged in
✔️ it can indicate if a product is in stock
✔️ it can't add a product to the cart when the product is out of stock (commented out, needs admin token in the cypress.env.json)
Bundle products test ✔️ it can render the product name
✔️ it can set the price to zero when every associated product qty is zero
✔️ it can calculate the price based on selected options
✔️ it can display selection quantities
✔️ it can add a bundled product to the cart
cms-page.spec.js CMS page tests 🔲 it shows the default 404 page on an non-existent route
🔲 it can open the default CMS page correctly
contact-form.spec.js Contact form tests ✔️ it shows the contact form correctly
🔲 it cannot submit a form when no valid email address is entered
✔️ it can submit the form when all validation passes
back-end.spec.js Back-end tests 🔲 it can login on the administration panel of the magento environment
🔲 it can show customer data
🔲 it processes orders and invoices correctly
🔲 it can edit an order

Installation

First, install Cypress and the dependencies in the root of your Magento 2 project:

npm ci

The easiest way to install the tests is to clone this repository and move the cypress folder into your project. As of right now, we do not provide a fallback mechanism for customizations to the tests, see Limitations.

git clone [email protected]:elgentos/magento2-cypress-testing-suite.git
mv magento2-cypress-testing-suite/cypress .
mv magento2-cypress-testing-suite/cypress.config.js .
rm -rf magento2-cypress-testing-suite
npm install cypress:^12.2.0 cypress-localstorage-commands:^2.2.2 cypress-tags:^1.1.2 typescript:^4.8.3

If you only need the Hyvä tests:

rm -rf cypress/{fixtures,page-objects,integration}/luma

If you only need the Luma tests;

rm -rf cypress/{fixtures,page-objects,integration}/hyva

Then edit the cypress.config.js file in the root of your project to update your baseUrl and possibly some other defaults we've set:

const baseUrl =
  process.env.NODE_ENV === "develop"
    ? "http://cypress.magento2.localhost"
    : "https://example.com/";

Also add these lines to your .gitignore to avoid cluttering your Git repo;

node_modules
cypress/screenshots
cypress/videos
cypress.env.json

Setup

Some tests are dependent on making changes in the database. This is done through the Magento 2 REST API. You will need to create an admin token for these tests. This is easily done using magerun2.

Get a list of all the admin users: magerun2 admin:user:list

If you don't have any admin users, create one; magerun2 admin:user:create --admin-user=john --admin-firstname=John --admin-lastname=Doe --admin-password=JohnDoe123 --admin-email="[email protected]"

Then create a token: magerun2 admin:token:create username_goes_here

You then can add the token to cypress.env.json as an environment variable:

{
  "MAGENTO2_ADMIN_TOKEN": "token_goes_here"
}

Overwrite the base url

{
  "MAGENTO2_BASE_URL": "https://demoshops.splendid-internet.de/magento/demoshop-magento2-daily"
}

Alternatively you can set it in your CI/CD variables by prefixing the environment variable name with CYPRESS_: CYPRESS_MAGENTO2_ADMIN_TOKEN: <token_goes_here>.

Tags

We use tags to discern between hot tests and cold tests. If you followed the installation instructions above the cypress-tags module is already installed.
Note: it is used in the cypress.config.js file in the setupNodeEvents callback.

Running

npx cypress run
# npx cypress open # if you want to use the GUI

Individual specs can be run using the following command:

npx cypress run --spec ./cypress/integration/path/to/some.spec.js

Hot and cold tests based on tags can be run using the following command:

CYPRESS_INCLUDE_TAGS=hot npx cypress run

Running against local environment

Set up your local base URL in cypress.config.js, or export CYPRESS_MAGENTO2_BASE_URL.
Then run Cypress with NODE_ENV=develop; npx cypress run.

Environment variables

Even though the test suite is intended to become part of a project, it is possible to change some behavior using environment variables.
This is useful for running the suite in different environments, for example, development, CI, or against production.

  • NODE_ENV if set to develop the development base URL configured in cypress.config.js will be used, and the default timeout is set to 10 seconds
  • CYPRESS_MAGENTO2_BASE_URL If set, this value will be used as the Magento 2 base_url. Otherwise, the base URL from cypress.config.js will be used.
  • CYPRESS_MAGENTO2_SPEC_PATTERN If set, only tests matching this glob pattern will be executed. Otherwise, the tests configured in cypress.config.js will be used.
  • CYPRESS_MAGENTO2_EXPORT_PATTERN If set, tests matching this glob pattern will be excluded.
  • CYPRESS_MAGENTO2_DEFAULT_TIMEOUT If set, used as the default timeout. Otherwise, the timeout defaults to 10 seconds if NODE_ENV is set to develop, or 4 seconds otherwise.
  • CYPRESS_MAGENTO2_ADMIN_TOKEN Used to authenticate against the Magento 2 API for setting up test fixtures.
  • CYPRESS_MAGENTO2_SKIP_CHECKOUT Set to a truthy value to skip any Hyvä tests that assume a Checkout is installed.
  • CYPRESS_MAGENTO2_SPEC_SUITE Set the test suite to run, if not set defaults to luma or hyva depending on response headers.

Any of these can also be configured in a cypress.env.json file without the CYPRESS_ prefix.

Running tests from modules

Spec files in extensions will be found by the default spec pattern at

  • app/code/**/Test/Cypress/hyva/**/*.spec.js or app/code/**/Test/Cypress/luma/**/*.spec.js
  • vendor/**/Test/Cypress/hyva/**/*.spec.js or vendor/**/Test/Cypress/luma/**/*.spec.js

Tests for different frontends can be supplied by using a different folder in Test/Cypress and setting the MAGENTO2_SPEC_SUITE config to that name. For example: app/code/Example/Module/Test/Cypress/vue/user/account.spec.js would be found by

CYPRESS_MAGENTO2_SPEC_SUITE=vue npx cypress run

If you do not want all tests to be run, regardless of the folder names, set MAGENTO2_SPEC_SUITE to an empty string.

Videos

homepage.spec.js.mp4

homepage.spec.js tests running on https://hyva-demo.elgentos.io

product.spec.js.mp4

product.spec.js tests running on https://hyva-demo.elgentos.io

category.spec.js.mp4

category.spec.js tests running on https://hyva-demo.elgentos.io

product-searches.spec.js.mp4

product-searches.spec.js tests running on https://hyva-demo.elgentos.io

Contributing

We are very open to contributions! We would love to have mobile viewport support for Hyvä, tests for Commerce functionality, additional tests, code improvements, a fallback mechanism, etcetera etcetera. See the Issues tab for issues to pick up.

We will be updating this readme soon with extensive contribution guidelines, but here is a short summary:

  • Avoid creating global cy functions (Custom Commands), instead put functions in utils/helpers and import them
  • Avoid creating aliases that are only used once
  • Use cy.get() as much as possible, only use cy.contains() in specific cases - try to avoid it
  • Do not add assertions to page objects, move those to the spec files. Red flag; should() in a page object
  • Every test (an it() function) has to be able to run stand-alone; it should not depend on any other test. You can test this by add .only (see Cypress docs).

More Repositories

1

magento2-regenerate-catalog-urls

This extension adds console commands to be able to regenerate; a product rewrite URL based on its url path; a category rewrite URL based on its url path; a category URL path based on its URL key and its parent categories.
PHP
264
star
2

masquerade

Faker-driven, configuration-based, platform-agnostic, locale-compatible data faker tool
PHP
237
star
3

awesome-shopware6

Awesome Shopware 6 plugins, resources, themes, etc
179
star
4

magento2-upgrade-gui

Magento 2 Upgrade GUI
Vue
110
star
5

magento2-php8-cc

Magento 2 PHP 8.x compatibility checker
PHP
95
star
6

LargeConfigProducts

Large Configurable Products workaround for Magento 2
PHP
91
star
7

magento2-serversideanalytics

Server side analytics for Magento 2
PHP
64
star
8

magento2-lightspeed

Magento 2 - Lightspeed for Google Lighthouse optimizations
PHP
63
star
9

magento2-prismicio

Magento 2 Prismic integration
PHP
38
star
10

magerun2-addons

Addon modules for n98-magerun2
PHP
29
star
11

magento2-composer-quality-patches

elgentos/magento2-composer-quality-patches
PHP
22
star
12

CategoryTiling

Adds tiling display option to categories for showing sub-categories as tiles
PHP
20
star
13

magento2-gallery-replacement

Simple Magento 2 gallery replacement
HTML
20
star
14

shopware-seo-canonical-url

Use parent product canonical URL for SEO for product variants
Twig
17
star
15

magento2-backend-launcher

PHP
17
star
16

magento2-product-duplicate-images-remove

Magento 2 extension to remove duplicate product images
PHP
16
star
17

magento2-imgix

Imgix extension for Magento 2 - automatically optimize your images
PHP
16
star
18

http-statuscode-checker

CLI HTTP statuscode checker
PHP
15
star
19

magento2-structured-data

PHP
14
star
20

frontend2fa

Magento 2 module for 2FA on the frontend
PHP
14
star
21

EasyAttributes

Batch add attribute options and drag & drop to rearrange their order!
HTML
13
star
22

magento2-consentmode-v2

HTML
13
star
23

Mailcheck

Magento implementation of Mailcheck
PHP
12
star
24

magento2-hyva-checkout-ab-test

Set up an A/B test with different available Hyvä and Luma checkouts
PHP
12
star
25

GoogleTagManager

Inserts Google Tag Manager script in header.
PHP
12
star
26

TableRates

Table rates generator for Magento
JavaScript
12
star
27

shopware-total-qty-in-cart-rule

Adds a Total Quantity In Cart Rule to the Rule Builder
PHP
12
star
28

magento2-clientside-cache

Clientside Cache
HTML
11
star
29

shopware-dutch-email-templates

Dutch email templates for Shopware 6
Twig
10
star
30

hyva-vat-switcher

PHP
10
star
31

magento2-filtered-product-list-noindex

PHP
10
star
32

magento2-baseurlpath

Allow Magento config to have a base url path instead of root without moving Magento 2 into a subdirectory
PHP
10
star
33

magento2-review-reminder

Send out review reminder mails X days after shipment has been made
PHP
10
star
34

magento2-rumvision

Frontend implementation for https://www.rumvision.com/
PHP
9
star
35

AutoInvoice

Automatically invoice some/specific orders.
PHP
8
star
36

TurpentineExtended

Extension to the excellent Nexcess Turpentine extension with shotgun mode
PHP
8
star
37

magento2-eu-tax-rates

Import EU VAT tax rates into Magento 2 with a simple console command
PHP
8
star
38

magento2-link-guest-orders-to-customer

Link existing guest orders to newly created or existing customer based on e-mail address
PHP
7
star
39

magento2-apicacheindexmanagement

Extension to invalidate caches and reindex indexers through the REST API.
PHP
7
star
40

MyFavorites

This extension shows a 'MyFavorites' block in the 'My Account' page with the most ordered products for that customer.
PHP
7
star
41

shopware-default-sort-order

Set the default sort order for category listings
PHP
6
star
42

testing-suite

6
star
43

magento2-secondaryemailaddress

B2B extension to enter secondary email address for logging in, order confirmation, invoice, etc
PHP
6
star
44

CodebaseExceptions

Magento Exceptions to Codebase
PHP
6
star
45

Automanufacturers

Create a category with the manufacturers name after saving a product.
PHP
6
star
46

FalconMollie

Mollie implementation for Deity Falcon
PHP
6
star
47

ServerSideAnalytics

This extension aims to solve the problem of discrepancies between Magento revenue reports and the revenue reports in Google Analytics.
PHP
6
star
48

LocalStorageVersioning

Highly experimental extension to clear localStorage along with Magento 2's static versioning
JavaScript
6
star
49

magento2-hyva-cro-semi-sticky-header

Changes the Hyvä header to a semi-sticky header (dissapears down and reappears up)
HTML
5
star
50

magento2-alternate-urls

PHP
5
star
51

Magento-VR

JavaScript
5
star
52

Tierpercentages

Elgentos Tierpercentages - this module allows you to fill out percentages in the Tier pricing part under Prices
PHP
5
star
53

AddressWithEmail

PHP
5
star
54

CustomDiscount

Set a custom price for a customer on request (sort of quotation)
PHP
5
star
55

magento2-mollie-hide-payment-by-category

JavaScript
5
star
56

AutoConnect

Automatically create the opposite upsell, cross-sell and related products connection when a connection is made
PHP
5
star
57

prismic-importer

Transforms & bundles (Gatsby) Markdown files into Prismic.io JSON files
PHP
5
star
58

magento2-hyva-cro-purchasing-confidence

Magento 2 Hyva CRO extension for increasing the purchasing confidence
PHP
4
star
59

BlockIP

This extension allows the shop administrator to block certain IP's from accessing the shop.
PHP
4
star
60

Openkvk

OpenKvK extension for Magento
JavaScript
4
star
61

GrouponCoupons

Easily import Groupon Coupon codes into your installation (also works for other coupons)
PHP
4
star
62

magento2-algolia-performance

Magento 2 module that makes it possible to set a debounce and a minimum character amount for Algolia Autocomplete
PHP
4
star
63

RelatedBundles

This extension creates a new product relation type, Related Bundles.
PHP
4
star
64

ExtendedAoeJsCssTstamp

Extends Aoe_JsCssTstamp to also version JS files that were included with addJs instead of addItem
PHP
4
star
65

magento2-kiyoh

Magento 2 extension for Kiyoh
PHP
3
star
66

parser

Use this library to turn your day-to-day configurations into usable arrays/objects.
PHP
3
star
67

ClientLog

Enable client side Javascript error logging through Mage::log
JavaScript
3
star
68

magento2-vurbis-punchout

Unofficial version of the Vurbis Magento 2 connector
PHP
3
star
69

Quickadd

Provides a rewritable configurable link to directly add products into the shopping cart
PHP
3
star
70

magento2-varnish-extended

This extension extends the built-in Varnish functionalities
PHP
3
star
71

magento2-react

Magento 2 module to add React to Knockout-driven frontend
JavaScript
2
star
72

module-feedbackcompany-magento2

PHP
2
star
73

HidePaymentMethod

Hide banktransfer payment method in the frontend while keeping it enabled for the backend
PHP
2
star
74

hypernode-api-cli

PHAR distribution of the hypernode-api-php client library for stand-alone use
PHP
2
star
75

magetitans

HTML
2
star
76

setup

Makefile
2
star
77

CustomFields

Add custom fields to registration page
PHP
2
star
78

magento2-prismicio-sample-data

Magento 2 - PrismicIO Sample Data
HTML
2
star
79

magento2-notifier-mail-adapter

PHP
2
star
80

gdpr-dump-magento-2-extensions

GDPR dump templates for popular Magento 2 extensions
2
star
81

SendInvoiceEmail

This small extension allows to send out invoice emails for payment methods that do not do this themselves, like PayPal Express and Authorize.net
PHP
2
star
82

Dataprovider

Connection with Dataprovider.com to autofill checkout page
PHP
2
star
83

Backorders

Adds a menu option beneath 'Sales' to show all current orders that contain backorders.
PHP
2
star
84

laravel-coding-standards

2
star
85

Bundlequick

Bundlequick allows you to quickly create a bundled product based on two or more simple products you have selected by using the Bundlequick mass update action.
PHP
2
star
86

Dynamiclinks

This module will dynamically show upsell products based on the previous set of products they have seen in the category view.
PHP
2
star
87

module-categorygridlist

Magento 2 - Offers an option in the backend to toggle grid or list view on a category basis, instead of on a global basis
PHP
2
star
88

FormRedirect

With this extension you can send your contactform thank you page to any page you want!
PHP
2
star
89

magento2-hyva-cro-payment-method-free-labels

Add 'Free' labels to your payment method list in the Hyvä checkout
HTML
1
star
90

github-cli-docker

For all the docker peeps out there, run Github-CLI via docker locally
Shell
1
star
91

magento2-hyva-cro-sticky-cart-proceed-button

Change static call to action to a sticky call to action in the mobile cart
HTML
1
star
92

magento2-composer-plugin

Magento 2 Composer plugin
PHP
1
star
93

CheckoutTelephoneInputType

HTML
1
star
94

magento2-openkvk

PHP
1
star
95

best-practices

HTML
1
star
96

OneLineStoreName

Reformat the 'store' line in the order grid to allow for a compacter view
PHP
1
star
97

HideOutOfStockCrosssell

Hides products in cross-sell recommendations that are out of stock (when backorders are enabled)
PHP
1
star
98

magento2-elasticsuite-prismic-search

Magento 2 ElasticSuite Prismic Search
PHP
1
star
99

magento2-legacy-email-enable

Enable Magento 2 legacy email templates
PHP
1
star
100

magento-module-facebook

PHP
1
star