magento2-cypress-testing-suite
magento2-cypress-testing-suite copied to clipboard
Default Hyvä cypress is failing
Describe the bug
When I run the cypress tests, several tests fail. The failing tests:
- Can add a coupon to the cart
- Can delete an added coupon from the cart
- Cannot add an invalid coupon
- Can visit the category page and filters on color red
- Can add a product to the wishlist when customer is logged in
- Can open default CMS pages
- Can find a single product
- Can remove an address
- Can edit the wishlist and remove item
To Reproduce Steps to reproduce the behavior:
composer.json
"require": {
"hyva-themes/magento2-default-theme": "1.1.17",
"hyva-themes/magento2-email-module": "^1.0",
"hyva-themes/magento2-graphql-tokens": "^1.0",
"hyva-themes/magento2-luma-checkout": "^1.1",
"hyva-themes/magento2-reset-theme": "^1.1",
"hyva-themes/magento2-theme-module": "1.1.17",
"magento/product-community-edition": "^2.4",
"markshust/magento2-module-disabletwofactorauth": "^2.0"
},
"require-dev": {
"magento/magento-cloud-docker": "^1.3",
"magento/module-bundle-sample-data": "100.4.*",
"magento/module-catalog-rule-sample-data": "100.4.*",
"magento/module-catalog-sample-data": "100.4.*",
"magento/module-cms-sample-data": "100.4.*",
"magento/module-configurable-sample-data": "100.4.*",
"magento/module-customer-sample-data": "100.4.*",
"magento/module-downloadable-sample-data": "100.4.*",
"magento/module-grouped-product-sample-data": "100.4.*",
"magento/module-msrp-sample-data": "100.4.*",
"magento/module-offline-shipping-sample-data": "100.4.*",
"magento/module-product-links-sample-data": "100.4.*",
"magento/module-review-sample-data": "100.4.*",
"magento/module-sales-rule-sample-data": "100.4.*",
"magento/module-sales-sample-data": "100.4.*",
"magento/module-swatches-sample-data": "100.4.*",
"magento/module-tax-sample-data": "100.4.*",
"magento/module-theme-sample-data": "100.4.*",
"magento/module-widget-sample-data": "100.4.*",
"magento/module-wishlist-sample-data": "100.4.*",
"magento/sample-data-media": "100.4.*"
},
cypress.config.js
const {defineConfig} = require('cypress');
const {tagify} = require('cypress-tags');
const fs = require('fs');
const envConfig = fs.existsSync('./cypress.env.json') ? require('./cypress.env.json') : {};
// Run "NODE_ENV=develop; npx cypress run" to run tests locally
const defaultBaseUrl = process.env.NODE_ENV === 'develop' ? 'https://hyva.playground.local' : 'https://hyva.playground.local';
// Sometimes our local envs are slow due to dev mode. Raising the timeout decreases flakiness
const defaultCommandTimeout = process.env.NODE_ENV === 'develop' ? 10000 : 4000;
// Customize to use either hyva, luma or custom specs
const defaultSpecPattern = [
'cypress/integration/hyva/**/*.spec.js',
];
const baseUrl = process.env.CYPRESS_MAGENTO2_BASE_URL || envConfig.MAGENTO2_BASE_URL || defaultBaseUrl;
module.exports = defineConfig({
projectId: "",
e2e: {
baseUrl: baseUrl,
specPattern: process.env.CYPRESS_MAGENTO2_SPEC_PATTERN || envConfig.MAGENTO2_SPEC_PATTERN || defaultSpecPattern,
specSuite: process.env.CYPRESS_MAGENTO2_SPEC_SUITE || envConfig.MAGENTO2_SPEC_SUITE || undefined,
excludeSpecPattern: process.env.CYPRESS_MAGENTO2_EXCLUDE_PATTERN || envConfig.MAGENTO2_EXCLUDE_PATTERN || '',
defaultCommandTimeout: parseInt(process.env.CYPRESS_MAGENTO2_DEFAULT_TIMEOUT || envConfig.MAGENTO2_DEFAULT_TIMEOUT || defaultCommandTimeout),
videoUploadOnPasses: !!(process.env.CYPRESS_VIDEO_UPLOAD_ON_PASSES || envConfig.VIDEO_UPLOAD_ON_PASSES || false),
watchForFileChanges: false,
supportFile: 'cypress/support/index.js',
viewportWidth: 1920,
viewportHeight: 1080,
env: {
mobileViewportWidthBreakpoint: 768,
mobileViewportWidthBreakpointHyva: 1024
},
setupNodeEvents(on, config) {
on('after:spec', (spec, results) => {
// If a retry failed, save the video, otherwise delete it to save time by not compressing it.
if (results && results.video) {
// Do we have failures for any retry attempts?
const failures = results.tests.find(test => {
return test.attempts.find(attempt => {
return attempt.state === 'failed'
})
});
// Delete the video if the spec passed on all attempts
if (!failures) {
fs.existsSync(results.video) && fs.unlinkSync(results.video)
}
}
})
on('file:preprocessor', tagify(config))
const applySpecSuiteToSpecPattern = (config) => {
// If the specSuite is an empty string, add a trailing / to $SPEC_SUITE to avoid // in the pattern
const regex = config.specSuite === '' ? /\$SPEC_SUITE\//g : /\$SPEC_SUITE/g;
const fn = (specPattern) => specPattern.replace(regex, config.specSuite)
config.specPattern = typeof config.specPattern === 'string' ? fn(config.specPattern) : config.specPattern.map(fn);
return config;
}
return config.specSuite === undefined
? new Promise((resolve, reject) => {
// Do a preflight request to determine which frontend test suite to run depending on the target theme
if (baseUrl.startsWith('https')) process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
const req = (baseUrl.startsWith('https') ? require('https') : require('http')).request(baseUrl);
req.on('response', res => {
config.specSuite = res.headers['x-built-with'] === 'Hyva Themes' ? 'hyva' : 'luma'
resolve(applySpecSuiteToSpecPattern(config));
})
req.on('error', reject);
req.end();
})
: applySpecSuiteToSpecPattern(config);
}
}
});
cypress.env.json
{
"MAGENTO2_ADMIN_TOKEN": "eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjEsInV0eXBpZCI6MiwiaWF0IjoxNjcwOTIwNTA1LCJleHAiOjE2NzA5MjQxMDV9.TsFWBeGjERqDdcfZzHuWsWXGI22dMyZgt2XWsizA7ls",
"MAGENTO2_SKIP_CHECKOUT": true,
"MAGENTO2_DEFAULT_TIMEOUT": 10000
}
@MaximGns do you have a link to a public Cypress Dashboard with this run maybe? That makes it easier to see what's going on.
The last run on the main branch worked perfectly, see here; https://github.com/elgentos/magento2-cypress-testing-suite/actions/runs/3242569500
And here for the Cypress Dashboard; https://cloud.cypress.io/projects/8vuidn/runs/20/test-results?actions=%5B%5D&browsers=%5B%5D&groups=%5B%5D&isFlaky=%5B%5D&modificationDateRange=%7B%22startDate%22%3A%221970-01-01%22%2C%22endDate%22%3A%222038-01-19%22%7D&orderBy=EXECUTION_ORDER&oses=%5B%5D&specs=%5B%5D&statuses=%5B%5D&testingTypesEnum=%5B%5D