Skip to content

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Oct 5, 2025

Description (*)

Refactored all tests.

  • every admin page has now its own config file to have a more clean structure
  • all admin pages have all buttons (save, delete, back, ... configured for easy access
  • all admin pages have entry points for common actions
    • view index page
    • edit an item
    • add new item

Basic Validation

  • buttons ... all configured buttons have to exist (error on new or missing)
  • fields ... all configured input have to exist (NO error on new or missing)
  • grid ... configured grid has to exist
  • navigation ... top navigation has to be correctly set to active
  • url ... path match configuration
  • title .... title match configuration

Tests

... see test files ...

Current Work

  • complete configuration for writing tests easier
  • add more tests (base on issues)

How to use

  • install DDEV
  • install cypress-plugin
  • run ddev cypress-open -C .cypress.config.js (browser), or ddev cypress-run -C .cypress.config.js (cli)

Structure

Every page has a file for tests and a configuration file. E.g.

cypress/e2e/openmage/backend/cms/page.cy.js
const test = cy.testBackendCmsPage.config;
const validation = cy.openmage.validation;

describe(`Checks admin system "${test.index.title}"`, () => {
  beforeEach('Log in the user', () => {
      cy.adminLogIn();
      cy.adminGoToTestRoute(test, test.index);
  });

  it(`tests index route`, () => {
      validation.pageElements(test, test.index);
  });

  it(`tests edit route`, () => {
      test.index.clickGridRow();
      validation.pageElements(test, test.edit);
  });

  it(`tests new route`, () => {
      test.index.clickAdd();
      validation.pageElements(test, test.new);
  });

  it('tests to disable a CMS page that is used in config', () => {
      test.index.clickGridRow();

      test.edit.disablePage();
      test.edit.clickSaveAndContinue();

      validation.hasWarningMessage('Cannot disable page, it is used in configuration');
      validation.hasSuccessMessage('The page has been saved.');

      cy.get('#messages').screenshot('error-disable-active-page', { overwrite: true, padding: 10 });
  });

  it('tests to delete a CMS page that is used in config', () => {
      test.index.clickGridRow();
      test.edit.clickDelete();

      validation.hasErrorMessage('Cannot delete page');

      cy.get('#messages').screenshot('error-delete-active-page', { overwrite: true, padding: 10 });
  });

  it('tests to add a CMS page', () => {
      test.index.clickAdd();
      test.edit.clickSaveAndContinue();

      // @todo add validation for required fields
  });

  it('tests to un-asign a CMS page that is used in config', () => {
      test.index.clickGridRow();

      //cy.log('Asign another store to the CMS page');
      //cy.get('#page_store_id')
      //    .select(4);

      //tools.clickAction(test.edit.__buttons.saveAndContinue);

      // @todo: fix needed - this test passes because of a Magento bug
      //validation.hasSuccessMessage('The page has been saved.');

      test.edit.resetStores();
      test.edit.clickSaveAndContinue();

      validation.hasSuccessMessage('The page has been saved.');
  });
});

Having all the tests in it.

cypress/support/openmage/backend/cms/page.js
const tools = cy.openmage.tools;

// selector for all buttons
const base = {
  _button: '.form-buttons button',
};

// base configuration for input fields
base.__fields = {
  page_title : {
      selector: '#page_title',
  },
  // ... more fields ...
};

// base configuration for tabs
base.__tabs = {
  general: '#page_tabs_main_section',
  content: '#page_tabs_content_section',
  // ... more tabs ...

cy.testBackendCmsPage = {};

// configuration
cy.testBackendCmsPage.config = {
  // selector for top-navigation
  _id: '#nav-admin-cms-page',
  // selector for sub-navigation
  _id_parent: '#nav-admin-cms',
  // selector to get page title
  _h3: 'h3.icon-head',
  // import: mandatory when "__button" is used in pages
  _button: base._button,
  // helper to click tab
  clickTabMain: () => {
      tools.click(base.__tabs.general, 'Clicking on General tab');
  },
  // ... more ...
}

// configuration for index action
cy.testBackendCmsPage.config.index = {
  // validate title
  title: 'Manage Pages',
  // validate url
  url: 'cms_page/index',
  // validate grid
  _grid: '#cmsPageGrid',
  // configure and validate buttons
  __buttons: {
      add: base._button + '[title="Add New Page"]',
  },
  // helper to click add button
  clickAdd: () => {
      tools.click(cy.testBackendCmsPage.config.index.__buttons.add);
  },
  // helper to click row element
  clickGridRow: (selector = 'td', content = 'no-route') => {
      tools.clickContains(cy.testBackendCmsPage.config.index._grid, selector, content, 'Select a CMS page');
  },
}

// configuration for edit action
cy.testBackendCmsPage.config.edit = {
  // validate title
  title: 'Edit Page',
  // validate url
  url: 'cms_page/edit',
  // configure and validate buttons
  __buttons: {
      save: base._button + '[title="Save Page"]',
      saveAndContinue: base._button + '[title="Save and Continue Edit"]',
      delete: base._button + '[title="Delete Page"]',
      back: base._button + '[title="Back"]',
      reset: base._button + '[title="Reset"]',
  },
  // import base configuration
  __fields: base.__fields,
  __tabs: base.__tabs,
  // helper for repeating actions etc
  disablePage: () => {
      cy.log('Disable the CMS page');
      cy.get(base.__fields.page_is_active.selector)
          .select('Disabled');
  },
  // ... more ...
}

// ... more routes ...

For configuration of selectors for buttons and imput fields, title, url and funtions that are used in tests

@github-actions github-actions bot added Template : admin Relates to admin template Component: Adminhtml Relates to Mage_Adminhtml Component: Newsletter Relates to Mage_Newsletter labels Oct 5, 2025
@sreichel sreichel marked this pull request as ready for review October 5, 2025 20:50
@Copilot Copilot AI review requested due to automatic review settings October 5, 2025 20:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors Cypress end-to-end tests by modularizing route definitions, introducing shared helpers, and updating tests to the new structure.

  • Split monolithic route config into granular backend/ frontend path modules.
  • Added reusable helpers for page checks, clicks, and message assertions; updated tests to use them.
  • Minor admin template improvement: added title attribute to “Add New Template” button.

Reviewed Changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cypress/support/openmage/frontend/paths.js New frontend route map (replaces frontend part of old config).
cypress/support/openmage/config/paths.js Removed monolithic routes file; functionality split across backend/frontend modules.
cypress/support/openmage/backend/system.js New modular system routes (cache, design, email, myaccount, indexes, stores, variables, config).
cypress/support/openmage/backend/sales.js New modular sales routes (credit memo, invoice, order, shipment, transactions).
cypress/support/openmage/backend/promo.js New modular promo routes (catalog rules, quote rules).
cypress/support/openmage/backend/newsletter.js New modular newsletter routes (templates, queue, subscribers, reports).
cypress/support/openmage/backend/dashboard.js New dashboard route module.
cypress/support/openmage/backend/customer.js New customer routes (customers, groups, online).
cypress/support/openmage/backend/cms.js New CMS routes (blocks, pages, widgets) plus CMS-specific helpers.
cypress/support/openmage/backend/catalog.js New catalog routes (products, categories, search, sitemap, URL rewrite).
cypress/support/openmage.js Added utilities: check.pageElements, tools.clickAction/clickGridRow, message helpers; removed validation.saveAction.
cypress/support/e2e.js Switched imports to new modular backend/ frontend paths.
cypress/support/commands.js Updated adminGoToTestRoute signature; deprecated adminTestRoute; minor behavior changes.
cypress/fixtures/example.json Added sample fixture data.
cypress/e2e/... (many backend tests) Updated tests to use new route objects and helpers; added index/edit/new route coverage per area.
cypress/e2e/openmage/frontend/newsletter-subscribe.cy.js Updated to use new helpers and frontend path map.
cypress/e2e/openmage/frontend/customer/account/create.cy.js Updated to use new helpers and message assertions.
app/design/adminhtml/default/default/template/newsletter/template/list.phtml Added title attribute to "Add New Template" button for better UX and test targeting.

@sreichel sreichel marked this pull request as draft October 11, 2025 06:58
@sreichel sreichel requested a review from Copilot October 11, 2025 13:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 102 out of 103 changed files in this pull request and generated 8 comments.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
24.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@sreichel sreichel marked this pull request as ready for review October 11, 2025 13:53
@sreichel
Copy link
Contributor Author

Tests only ... merged

@sreichel sreichel merged commit a6595cf into OpenMage:main Oct 11, 2025
22 of 23 checks passed
@sreichel sreichel deleted the cypress/refactor branch October 11, 2025 14:22
@sreichel sreichel added chore and removed chore labels Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Adminhtml Relates to Mage_Adminhtml Component: Newsletter Relates to Mage_Newsletter environment improvement Template : admin Relates to admin template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant