Files
wp-plugin-starter-template-…/cypress/support/commands.js
marcusquinn e6dcda3f6e Fix GitHub Actions failures: code quality, tests, and linting
- Fix shellcheck warnings in bin/install-wp-tests.sh (quote variables, fix command -v usage)
- Remove trailing spaces in .github/workflows/phpunit.yml
- Add phpmd.xml to exclude camelCase checks for WordPress naming conventions
- Update composer.json to use phpmd.xml configuration
- Remove trailing commas in .eslintrc.js for Codacy compliance
- Add .markdownlint.json to configure markdown linting rules
- Improve Cypress test reliability with increased timeouts
- Update loginAsAdmin command with better error handling
- Make plugin activation checks more robust in Cypress tests

🤖 Generated with [Qoder][https://qoder.com]
2025-11-16 03:51:12 +00:00

75 lines
2.2 KiB
JavaScript

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
/**
* Custom command to login as admin
*/
Cypress.Commands.add('loginAsAdmin', () => {
cy.visit('/wp-admin', { timeout: 30000 });
cy.get('body', { timeout: 15000 }).then(($body) => {
if ($body.find('#wpadminbar').length > 0) {
cy.log('Already logged in as admin');
return;
}
if ($body.find('#user_login').length > 0) {
cy.get('#user_login').should('be.visible').type('admin');
cy.get('#user_pass').should('be.visible').type('password');
cy.get('#wp-submit').should('be.visible').click();
cy.get('#wpadminbar', { timeout: 15000 }).should('exist');
} else {
cy.log('Login form not found, assuming already logged in');
}
});
});
/**
* Custom command to activate plugin
*/
Cypress.Commands.add('activatePlugin', (pluginSlug) => {
cy.loginAsAdmin();
cy.visit('/wp-admin/plugins.php');
// Check if plugin is already active
cy.contains('tr', pluginSlug).then(($tr) => {
if ($tr.find('.deactivate').length > 0) {
// Plugin is already active
cy.log(`Plugin ${pluginSlug} is already active`);
return;
}
// Activate the plugin
cy.contains('tr', pluginSlug).find('.activate a').click();
cy.contains('tr', pluginSlug).find('.deactivate').should('exist');
});
});
/**
* Custom command to network activate plugin
*/
Cypress.Commands.add('networkActivatePlugin', (pluginSlug) => {
cy.loginAsAdmin();
cy.visit('/wp-admin/network/plugins.php');
// Check if plugin is already network active
cy.contains('tr', pluginSlug).then(($tr) => {
if ($tr.find('.network_active').length > 0) {
// Plugin is already network active
cy.log(`Plugin ${pluginSlug} is already network active`);
return;
}
// Network activate the plugin
cy.contains('tr', pluginSlug).find('.activate a').click();
cy.contains('tr', pluginSlug).find('.network_active').should('exist');
});
});