Skip to content

Commit

Permalink
Update dependencies and add Playwright fixtures for Magento testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mescalantea committed Jan 31, 2025
1 parent 0937efe commit 6b30aca
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 37 deletions.
36 changes: 21 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "magento2-core",
"version": "1.0.0",
"type": "module",
"description": "1. [About seQura](#about-sequra) 2. [Installation guide](https://sequra.atlassian.net/wiki/spaces/DOC/pages/1377304583/MAGENTO+2) 3. [Sign-up](#sign-up) 4. [For developers](#for-developers)",
"main": "index.js",
"scripts": {},
Expand All @@ -9,6 +10,7 @@
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.7"
"@types/node": "^22.10.7",
"playwright-fixture-for-plugins": "github:sequra/playwright-fixture-for-plugins#feature/Setup-project"
}
}
4 changes: 2 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default defineConfig({
/* Configure projects for major browsers */
projects: [
{
name: 'example',
name: 'configuration-payment-methods',
use: { ...devices['Desktop Chrome'] },
testMatch: 'example.spec.js',
testMatch: '004-configuration-payment-methods.spec.js',
},
],
});
Expand Down
69 changes: 69 additions & 0 deletions tests-e2e/fixtures/MagentoBackOffice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { BackOffice } from 'playwright-fixture-for-plugins';
export default class MagentoBackOffice extends BackOffice {

/**
* Init the locators with the locators available
*
* @returns {Object}
*/
initLocators() {
return {
usernameInput: () => this.page.locator('#username'),
passwordInput: () => this.page.locator('#login'),
loginButton: () => this.page.locator('.action-login'),
// menuBarItemSales: () => this.page.locator('#menu-magento-sales-sales'),
menuBarItemSeQuraLink: () => this.page.locator('[data-ui-id="menu-sequra-core-menu"] > a'),
};
}

/**
* Login
*
* @param {Object} options Additional options
* @returns {Promise<void>}
*/
async login(options = { waitUntil: 'load' }) {
const user = process.env.M2_ADMIN_USER;
const pass = process.env.M2_ADMIN_PASSWORD;
const usernameInput = this.locators.usernameInput();

try {
await this.page.goto(`${this.baseURL}/${process.env.M2_BACKEND_FRONTNAME}`, { waitUntil: 'domcontentloaded' });
await this.expect(usernameInput, 'Username input is visible').toBeVisible({ timeout: 100 });
}
catch {
return;
}

console.log(`Logging in as user: "${user}" with password: "${pass}"`);

await usernameInput.fill(user);
await this.locators.passwordInput().fill(pass);
await this.locators.loginButton().click();
await this.page.waitForURL(/admin/, options);
}

/**
* Logout
*
* @param {Object} options Additional options
* @returns {Promise<void>}
*/
async logout(options = {}) {
throw new Error('Not implemented');
}

/**
* Navigate to SeQura settings page
*
* @param {Object} options
* @param {string} options.page The page within settings to navigate to
*/
async gotoSeQuraSettings(options = { page: '' }) {
await this.login();
// await this.locators.menuBarItemSales().click();
const link = this.locators.menuBarItemSeQuraLink();
const url = (await link.getAttribute('href')) + `#${options.page}`;
await this.page.goto(url, { waitUntil: 'domcontentloaded' });
}
}
31 changes: 31 additions & 0 deletions tests-e2e/fixtures/MagentoSeQuraHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { SeQuraHelper } from 'playwright-fixture-for-plugins';

export default class MagentoSeQuraHelper extends SeQuraHelper {

/**
* Init the webhooks available
*
* @returns {Object} The webhooks available
*/
initWebhooks() {
return {
clear_config: 'clear_config',
dummy_config: 'dummy_config',
// dummyServicesConfig: 'dummy_services_config',
// removeDbTables: 'remove_db_tables'
};
}

/**
* Prepare the URL to use
*
* @param {Object} options Additional options
* @param {string} options.webhook The webhook
* @param {Array<Object>} options.args The arguments to pass to the webhook. Each argument is an object with `name` and `value` properties
* @returns {string} The URL to use
*/
getWebhookUrl(options = { webhook, args: [] }) {
const { webhook, args } = options;
return `${this.baseURL}/rest/V1/sequrahelper/webhook/?sq-webhook=${webhook}${this.getWebhookUrlArgs(args)}`;
}
}
23 changes: 23 additions & 0 deletions tests-e2e/fixtures/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test as baseTest, expect } from "@playwright/test";
import { PaymentMethodsSettingsPage } from "playwright-fixture-for-plugins";
import MagentoBackOffice from "./MagentoBackOffice";
import MagentoSeQuraHelper from "./MagentoSeQuraHelper";

const test = baseTest.extend({
backOffice: async ({ page, baseURL }, use) => await use(new MagentoBackOffice(page, baseURL, expect)),
helper: async ({ page, baseURL, request }, use) => await use(new MagentoSeQuraHelper(page, baseURL, expect, request)),
paymentMethodsSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new PaymentMethodsSettingsPage(page, baseURL, expect, request, backOffice, helper)),
});

test.afterEach(async ({ page }, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus) {
const screenshotPath = testInfo.outputPath(`screenshot.png`);
testInfo.attachments.push({
name: 'screenshot', path:
screenshotPath, contentType: 'image/png'
});
await page.screenshot({ path: screenshotPath, fullPage: true });
}
});

export { test, expect };
18 changes: 18 additions & 0 deletions tests-e2e/specs/004-configuration-payment-methods.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test } from '../fixtures/test';

test.describe('Configuration', () => {
test('Payment methods', async ({ helper, paymentMethodsSettingsPage }) => {
// Setup
const { dummy_config } = helper.webhooks;
const countries = [
{ name: 'Spain', paymentMethods: ['Paga Después', 'Divide tu pago en 3', 'Paga Fraccionado'] },
{ name: 'France', paymentMethods: ['Payez en plusieurs fois'] },
{ name: 'Italy', paymentMethods: ['Pagamento a rate'] },
{ name: 'Portugal', paymentMethods: ['Pagamento Fracionado'] }
];
// Execution
await helper.executeWebhook({ webhook: dummy_config });
await paymentMethodsSettingsPage.goto();
await paymentMethodsSettingsPage.expectAvailablePaymentMethodsAreVisible(countries);
});
});
19 changes: 0 additions & 19 deletions tests-e2e/specs/example.spec.js

This file was deleted.

0 comments on commit 6b30aca

Please sign in to comment.