From 5ad564d524634d86d30666dbb88f7c5a3282564d Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 21 Apr 2022 11:05:40 +0200 Subject: [PATCH 001/100] MOL-383 Add E2E playwright transaction tests --- .env.example | 3 + package.json | 5 +- playwright.config.js | 114 +++++++++++++++ tests/e2e/README.md | 14 +- .../specs/classicCheckoutTransaction.spec.ts | 131 ++++++++++++++++++ 5 files changed, 256 insertions(+), 11 deletions(-) create mode 100644 playwright.config.js create mode 100644 tests/e2e/specs/classicCheckoutTransaction.spec.ts diff --git a/.env.example b/.env.example index 47e8b6461..80e721780 100644 --- a/.env.example +++ b/.env.example @@ -23,3 +23,6 @@ WP_TITLE="Mollie Test" ADMIN_USER=admin ADMIN_PASS=admin ADMIN_EMAIL=me@my.com + +E2E_AUTH_USERNAME=admin +E2E_AUTH_PW=admin diff --git a/package.json b/package.json index 361fac8e6..ca3788c0d 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,10 @@ "@symfony/webpack-encore": "^0.28.2", "@woocommerce/dependency-extraction-webpack-plugin": "^1.7.0", "@wordpress/element": "^4.0.4", - "cypress": "^9.2.0", - "cypress-woocommerce": "^0.1.1", + "@playwright/test": "^1.21.1", "date-and-time": "^0.14.0", "del": "^3.0.0", + "dotenv": "^16.0.0", "gulp": "^4.0.0", "gulp-cli": "^2.0.1", "gulp-help-doc": "^1.1.1", @@ -53,7 +53,6 @@ "watch": "webpack --watch", "build": "gulp buildAssets", "setup": "gulp setup", - "cypress:open": "cypress open" }, "dependencies": { "@woocommerce/e2e-utils": "^0.1.6", diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 000000000..43cf0f94c --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,114 @@ +// @ts-check +const { devices } = require('@playwright/test'); + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ + require('dotenv').config(); + +/** + * @see https://playwright.dev/docs/test-configuration + * @type {import('@playwright/test').PlaywrightTestConfig} + */ +const config = { + testDir: './tests/e2e', + /* Maximum time one test can run for. */ + timeout: 30 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 5000 + }, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + //globalSetup: require.resolve('./e2e/global-setup'), + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ + actionTimeout: 0, + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: process.env.E2E_URL_TESTSITE, + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + + httpCredentials: { + username: process.env.E2E_AUTH_USERNAME, + password: process.env.E2E_AUTH_PW, + }, + // Tell all tests to load signed-in state from 'storageState.json'. + //storageState: 'storageState.json' + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { + ...devices['Desktop Chrome'], + }, + }, + + { + name: 'firefox', + use: { + ...devices['Desktop Firefox'], + }, + }, + + { + name: 'webkit', + use: { + ...devices['Desktop Safari'], + }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { + // ...devices['Pixel 5'], + // }, + // }, + // { + // name: 'Mobile Safari', + // use: { + // ...devices['iPhone 12'], + // }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { + // channel: 'msedge', + // }, + // }, + // { + // name: 'Google Chrome', + // use: { + // channel: 'chrome', + // }, + // }, + ], + + /* Folder for test artifacts such as screenshots, videos, traces, etc. */ + // outputDir: 'test-results/', + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // port: 3000, + // }, +}; + +module.exports = config; diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 11189fa75..5ca2861d8 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -1,13 +1,11 @@ -### Setup -- Set a working WordPress site URL here: tests/e2e/config/default.json +### Setup E2E tests +In your test environment +- Import the products +- Update the env with url and credentials +- VSCode has a playwright plugin - Install and activate basic auth plugin: https://github.com/WP-API/Basic-Auth ``` -$ npm install +$ npx playwright test ``` -### Run tests -``` -$ jest -$ jest -i ./tests/e2e/specs/single.test.js -``` diff --git a/tests/e2e/specs/classicCheckoutTransaction.spec.ts b/tests/e2e/specs/classicCheckoutTransaction.spec.ts new file mode 100644 index 000000000..80d330888 --- /dev/null +++ b/tests/e2e/specs/classicCheckoutTransaction.spec.ts @@ -0,0 +1,131 @@ + +import { test, expect } from '@playwright/test'; + + +const GATEWAYS = { + 'banktransfer':{ + 'title':'Bank Transfer', + + } +} + +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } +} +async function loginAdmin(page: Page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); +} +async function setOrderAPI(page: Page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +async function setPaymentAPI(page: Page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +async function classicCheckoutTransaction(page: Page, testedProduct, testedGateway) { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add product to cart + + const productCartButton = testedProduct.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + // Fill input[name="billing_first_name"] + await page.locator('input[name="billing_first_name"]').fill('Test'); + // Fill input[name="billing_last_name"] + await page.locator('input[name="billing_last_name"]').fill('test'); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + + // WOOCOMMERCE ORDER PAID PAGE + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + + // WOOCOMMERCE ORDER PAGE + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); +} + +test.describe('Transaction in classic checkout', () => { + test('Transaction with Order API', async ({ page }) => { + //login as Admin + await loginAdmin(page); + //Set Order API + await setOrderAPI(page); + for ( const key in GATEWAYS){ + let testedGateway = GATEWAYS[key] + for( const key in PRODUCTS){ + let testedProduct = PRODUCTS[key] + await classicCheckoutTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + + test('Transaction with Payment API', async ({ page }) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + for ( const key in GATEWAYS){ + let testedGateway = GATEWAYS[key] + for( const key in PRODUCTS){ + let testedProduct = PRODUCTS[key] + await classicCheckoutTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); +}); + + From eab3916c2aac395e5cc129b071fa3421a36f0ef4 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 26 Apr 2022 08:35:22 +0200 Subject: [PATCH 002/100] MOL-383 Add E2E playwright fix transaction tests new folders --- .github/workflows/playwright.yml | 27 ++++ .gitignore | 2 + package.json | 4 +- playwright.config.js | 7 +- tests/e2e/.gitignore | 3 - .../Settings/paymentClassicCheckout.spec.js | 47 ++++++ tests/e2e/Transaction/classicCheckout.spec.js | 134 ++++++++++++++++++ tests/e2e/jest-puppeteer.config.js | 5 - tests/e2e/package.json | 18 --- .../specs/classicCheckoutTransaction.spec.ts | 131 ----------------- tests/e2e/specs/woocommerce.test.js | 113 --------------- 11 files changed, 214 insertions(+), 277 deletions(-) create mode 100644 .github/workflows/playwright.yml delete mode 100644 tests/e2e/.gitignore create mode 100644 tests/e2e/Settings/paymentClassicCheckout.spec.js create mode 100644 tests/e2e/Transaction/classicCheckout.spec.js delete mode 100644 tests/e2e/jest-puppeteer.config.js delete mode 100644 tests/e2e/package.json delete mode 100644 tests/e2e/specs/classicCheckoutTransaction.spec.ts delete mode 100644 tests/e2e/specs/woocommerce.test.js diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 000000000..4d7b32a27 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14.x' + - name: Install dependencies + run: npm ci + - name: Install Playwright + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v2 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index 1719e3c3b..fbf477a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ .env cypress.json +test-results/ +playwright-report/ diff --git a/package.json b/package.json index ca3788c0d..a4c37ca8d 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,10 @@ "@babel/polyfill": "^7.7.0", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.14.5", + "@playwright/test": "^1.21.1", "@symfony/webpack-encore": "^0.28.2", "@woocommerce/dependency-extraction-webpack-plugin": "^1.7.0", "@wordpress/element": "^4.0.4", - "@playwright/test": "^1.21.1", "date-and-time": "^0.14.0", "del": "^3.0.0", "dotenv": "^16.0.0", @@ -52,7 +52,7 @@ "scripts": { "watch": "webpack --watch", "build": "gulp buildAssets", - "setup": "gulp setup", + "setup": "gulp setup" }, "dependencies": { "@woocommerce/e2e-utils": "^0.1.6", diff --git a/playwright.config.js b/playwright.config.js index 43cf0f94c..e524a7ad4 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -5,7 +5,8 @@ const { devices } = require('@playwright/test'); * Read environment variables from file. * https://github.com/motdotla/dotenv */ - require('dotenv').config(); +// require('dotenv').config(); + /** * @see https://playwright.dev/docs/test-configuration @@ -30,7 +31,6 @@ const config = { workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', - //globalSetup: require.resolve('./e2e/global-setup'), /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ @@ -40,13 +40,10 @@ const config = { /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', - httpCredentials: { username: process.env.E2E_AUTH_USERNAME, password: process.env.E2E_AUTH_PW, }, - // Tell all tests to load signed-in state from 'storageState.json'. - //storageState: 'storageState.json' }, /* Configure projects for major browsers */ diff --git a/tests/e2e/.gitignore b/tests/e2e/.gitignore deleted file mode 100644 index cef17fc3a..000000000 --- a/tests/e2e/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -package-lock.json -/config/default.json diff --git a/tests/e2e/Settings/paymentClassicCheckout.spec.js b/tests/e2e/Settings/paymentClassicCheckout.spec.js new file mode 100644 index 000000000..094c5671c --- /dev/null +++ b/tests/e2e/Settings/paymentClassicCheckout.spec.js @@ -0,0 +1,47 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); + +const GATEWAYS = { + 'banktransfer': { + 'title': 'Bank Transfer', + } +} +/** + * @param {import('@playwright/test').Page} page + */ +async function loginAdmin(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() +]); +} +test.describe('Should show payment settings on classic checkout', () => { + test.beforeAll(async ({ page }) => { + //login as Admin + await loginAdmin(page); + //reset settings + //go to checkout + }); + test('Should show default settings', async ({ page }) => { + for ( const key in GATEWAYS){ + let testedGateway = GATEWAYS[key] + //check default title + //check default icon + //check default description + //check issuers dropdown show + //shown with random available country + //no fee added + }// end loop gateways + }); +}); + + + + + + + + + diff --git a/tests/e2e/Transaction/classicCheckout.spec.js b/tests/e2e/Transaction/classicCheckout.spec.js new file mode 100644 index 000000000..4a1a2d01c --- /dev/null +++ b/tests/e2e/Transaction/classicCheckout.spec.js @@ -0,0 +1,134 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const GATEWAYS = { + 'banktransfer':{ + 'title':'Bank Transfer', + + } +} +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } +} +/** + * @param {import('@playwright/test').Page} page + */ +async function loginAdmin(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setOrderAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setPaymentAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function classicCheckoutTransaction(page, testedProduct, testedGateway) { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add product to cart + const productCartButton = testedProduct.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + // Fill input[name="billing_first_name"] + await page.locator('input[name="billing_first_name"]').fill('Test'); + // Fill input[name="billing_last_name"] + await page.locator('input[name="billing_last_name"]').fill('test'); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + + // WOOCOMMERCE ORDER PAID PAGE + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + + // WOOCOMMERCE ORDER PAGE + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); +} +test.describe('Transaction in classic checkout', () => { + test('Transaction with Order API', async ({ page }) => { + //login as Admin + await loginAdmin(page); + await setOrderAPI(page); + for ( const key in GATEWAYS){ + let testedGateway = GATEWAYS[key] + for( const key in PRODUCTS){ + let testedProduct = PRODUCTS[key] + await classicCheckoutTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API', async ({ page }) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + for ( const key in GATEWAYS){ + let testedGateway = GATEWAYS[key] + for( const key in PRODUCTS){ + let testedProduct = PRODUCTS[key] + await classicCheckoutTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways +}); +}); \ No newline at end of file diff --git a/tests/e2e/jest-puppeteer.config.js b/tests/e2e/jest-puppeteer.config.js deleted file mode 100644 index 169e3fa29..000000000 --- a/tests/e2e/jest-puppeteer.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - launch: { - headless: false, - }, -} diff --git a/tests/e2e/package.json b/tests/e2e/package.json deleted file mode 100644 index 81b57642b..000000000 --- a/tests/e2e/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "wc-e2e", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "NODE_ENV= jest" - }, - "devDependencies": { - "@woocommerce/api": "^0.2.0", - "@woocommerce/e2e-utils": "^0.1.5", - "jest-puppeteer": "^5.0.4", - "puppeteer": "^9.1.1" - }, - "jest": { - "preset": "jest-puppeteer" - } -} diff --git a/tests/e2e/specs/classicCheckoutTransaction.spec.ts b/tests/e2e/specs/classicCheckoutTransaction.spec.ts deleted file mode 100644 index 80d330888..000000000 --- a/tests/e2e/specs/classicCheckoutTransaction.spec.ts +++ /dev/null @@ -1,131 +0,0 @@ - -import { test, expect } from '@playwright/test'; - - -const GATEWAYS = { - 'banktransfer':{ - 'title':'Bank Transfer', - - } -} - -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } -} -async function loginAdmin(page: Page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} -async function setOrderAPI(page: Page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} -async function setPaymentAPI(page: Page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} -async function classicCheckoutTransaction(page: Page, testedProduct, testedGateway) { - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add product to cart - - const productCartButton = testedProduct.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); - - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); - - // CUSTOMER DETAILS - // Fill input[name="billing_first_name"] - await page.locator('input[name="billing_first_name"]').fill('Test'); - // Fill input[name="billing_last_name"] - await page.locator('input[name="billing_last_name"]').fill('test'); - - // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); - // Click text=Place order - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - page.locator('text=Place order').click() - ]); - - // IN MOLLIE - // Capture order number in Mollie and mark as paid - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - - // WOOCOMMERCE ORDER PAID PAGE - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); - - // WOOCOMMERCE ORDER PAGE - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); - - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); -} - -test.describe('Transaction in classic checkout', () => { - test('Transaction with Order API', async ({ page }) => { - //login as Admin - await loginAdmin(page); - //Set Order API - await setOrderAPI(page); - for ( const key in GATEWAYS){ - let testedGateway = GATEWAYS[key] - for( const key in PRODUCTS){ - let testedProduct = PRODUCTS[key] - await classicCheckoutTransaction(page, testedProduct, testedGateway); - }// end loop products - }// end loop gateways - }); - - test('Transaction with Payment API', async ({ page }) => { - //login as Admin - await loginAdmin(page); - //Set Payment API - await setPaymentAPI(page); - for ( const key in GATEWAYS){ - let testedGateway = GATEWAYS[key] - for( const key in PRODUCTS){ - let testedProduct = PRODUCTS[key] - await classicCheckoutTransaction(page, testedProduct, testedGateway); - }// end loop products - }// end loop gateways - }); -}); - - diff --git a/tests/e2e/specs/woocommerce.test.js b/tests/e2e/specs/woocommerce.test.js deleted file mode 100644 index ca9fbd4d9..000000000 --- a/tests/e2e/specs/woocommerce.test.js +++ /dev/null @@ -1,113 +0,0 @@ -const { - merchant, - shopper, - uiUnblocked, -} = require('@woocommerce/e2e-utils'); - -const config = require('config'); -const {WP_ADMIN_WC_SETTINGS} = require("@woocommerce/e2e-utils/build/flows/constants"); -const simpleProductName = config.get( 'products.simple.name' ); - -describe('Checkout page', () => { - - beforeAll(async () => { - /*await merchant.login(); - await createSimpleProduct(); - - // Enable iDeal payment method - await merchant.openSettings('checkout', 'mollie_wc_gateway_ideal'); - await setCheckbox('#mollie_wc_gateway_ideal_enabled'); - await settingsPageSaveChanges(); - await verifyCheckboxIsSet('#mollie_wc_gateway_ideal_enabled'); - - await merchant.logout();*/ - }, 30000); - - async function molliePaidOrder() { - await expect(page).toClick('.checkbox__label', {text: 'Paid'}); - await expect(page).toClick('.form__button', {text: 'Continue'}); - await page.waitForNavigation(); - } - async function mollieCancelOrder() { - await expect(page).toClick('.checkbox__label', {text: 'Canceled'}); - await expect(page).toClick('.form__button', {text: 'Continue'}); - await page.waitForNavigation(); - } - - it('allows existing customer to place order of simple product', async () => { - - //await page.authenticate({'username':'', 'password': ''}); - - //await shopper.login(); - await shopper.goToShop(); - await shopper.addToCartFromShopPage(simpleProductName); - await shopper.goToCheckout(); - - await uiUnblocked(); - await expect(page).toClick('.wc_payment_method label', {text: 'Przelewy24'}); - await uiUnblocked(); - await shopper.placeOrder(); - - await molliePaidOrder(); - await expect(page).toMatch('Order received'); - - let orderReceivedHtmlElement = await page.$('.woocommerce-order-overview__order.order'); - let orderReceivedText = await page.evaluate(element => element.textContent, orderReceivedHtmlElement); - customerOrderId = orderReceivedText.split(/(\s+)/)[6].toString(); - - }, 500000); - - it('store owner can confirm the order was received', async () => { - - await merchant.login(); - await merchant.goToOrder(customerOrderId); - - await uiUnblocked(); - await expect(page).toMatch('Processing'); - - }, 500000); - - it('store owner can refund the order', async () => { - - await merchant.goToOrder(customerOrderId); - page.on('dialog', async dialog => { - - await dialog.accept(); - }); - await expect(page).toClick('.refund-items', {text: 'Refund'}); - - page.type('input[name=refund_amount]','9') - await expect(page).toMatch('Refunded'); - - }, 500000); - - it('allows existing customer to cancel order of simple product', async () => { - //await page.authenticate({'username':'', 'password': ''}); - - await shopper.goToShop(); - await shopper.addToCartFromShopPage(simpleProductName); - await shopper.goToCheckout(); - - await uiUnblocked(); - await expect(page).toClick('.wc_payment_method label', {text: 'Przelewy24'}); - await uiUnblocked(); - await shopper.placeOrder(); - - await mollieCancelOrder(); - await expect(page).toMatch('Pay for order'); - - }, 500000); -}); - -describe('Settings page', () => { - it('allows owner to see gateways in settings', async () => { - //await page.authenticate({'username':'', 'password': ''}); - - await merchant.login(); - await page.goto(WP_ADMIN_WC_SETTINGS + 'checkout', { - waitUntil: 'networkidle0' - }); - await expect(page).toMatch('Mollie - Bank Transfer'); - await expect(page).toMatch('Mollie - Belfius Direct Net'); - }, 500000); -}); From 9acaa15a72b70e090beedd1129b1ad4678910879 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 4 May 2022 12:16:43 +0200 Subject: [PATCH 003/100] MOL-383 add new tests --- playwright.config.js | 2 +- .../e2e/Cart/PayPalButtonClassicCart.spec.js | 134 ++++++ .../PayPalButtonClassicProduct.spec.js | 118 +++++ tests/e2e/Settings/generalSettings.spec.js | 103 ++++ .../Settings/paymentClassicCheckout.spec.js | 121 ++++- tests/e2e/Transaction/classicCheckout.spec.js | 451 +++++++++++++----- 6 files changed, 811 insertions(+), 118 deletions(-) create mode 100644 tests/e2e/Cart/PayPalButtonClassicCart.spec.js create mode 100644 tests/e2e/Product/PayPalButtonClassicProduct.spec.js create mode 100644 tests/e2e/Settings/generalSettings.spec.js diff --git a/playwright.config.js b/playwright.config.js index e524a7ad4..e641ae3d1 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -5,7 +5,7 @@ const { devices } = require('@playwright/test'); * Read environment variables from file. * https://github.com/motdotla/dotenv */ -// require('dotenv').config(); + require('dotenv').config(); /** diff --git a/tests/e2e/Cart/PayPalButtonClassicCart.spec.js b/tests/e2e/Cart/PayPalButtonClassicCart.spec.js new file mode 100644 index 000000000..de6b79d8a --- /dev/null +++ b/tests/e2e/Cart/PayPalButtonClassicCart.spec.js @@ -0,0 +1,134 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const GATEWAYS = { + 'paypal':{ + 'title':'PayPal', + + } +} +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + }, + 'virtual': { + 'name': 'virtual_no_down', + 'price': '20,25€' + } +} +/** + * @param {import('@playwright/test').Page} page + */ +async function loginAdmin(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setOrderAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setPaymentAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +test.describe('PayPal Transaction in classic cart', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await loginAdmin(page); + + }); + test('Not be seen if not enabled', async ({ page }) => { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add virtual product to cart + const productCartButton = PRODUCTS.virtual.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and not see + await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + //remove from cart + await page.locator('.product-remove').click(); + }); + test('Not be seen if not virtual', async ({ page }) => { + // set PayPal visible in cart + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add non virtual product to cart + const productCartButton = PRODUCTS.simple.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and not see + await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + //remove from cart + await page.locator('.product-remove').click(); + }); + test('Transaction with Order API - virtual product', async ({ page }) => { + let testedGateway = GATEWAYS.paypal + await loginAdmin(page); + await setOrderAPI(page); + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add virtual product to cart + const productCartButton = PRODUCTS.virtual.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and click + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); + + // Check paid with Mollie + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + + // WOOCOMMERCE ORDER PAGE + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + }); +}); diff --git a/tests/e2e/Product/PayPalButtonClassicProduct.spec.js b/tests/e2e/Product/PayPalButtonClassicProduct.spec.js new file mode 100644 index 000000000..4a91b4735 --- /dev/null +++ b/tests/e2e/Product/PayPalButtonClassicProduct.spec.js @@ -0,0 +1,118 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const GATEWAYS = { + 'paypal':{ + 'title':'PayPal', + + } +} +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + }, + 'virtual': { + 'name': 'virtual_no_down', + 'price': '20,25€' + } +} +/** + * @param {import('@playwright/test').Page} page + */ +async function loginAdmin(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setOrderAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setPaymentAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +test.describe('PayPal Transaction in classic product', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await loginAdmin(page); + + }); + test('Not be seen if not enabled', async ({ page }) => { + // Go to virtual product page + await page.goto(process.env.E2E_URL_TESTSITE + '/product/virtual_no_down/'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + + }); + test('Not be seen if not virtual', async ({ page }) => { + // set PayPal visible in cart + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + // Go to simple product + await page.goto(process.env.E2E_URL_TESTSITE + '/product/simple_taxes'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + }); + test('Transaction with Order API - virtual product', async ({ page }) => { + let testedGateway = GATEWAYS.paypal; + await loginAdmin(page); + await setOrderAPI(page); + // Go to virtual product page + await page.goto(process.env.E2E_URL_TESTSITE + '/product/virtual_no_down/'); + + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = PRODUCTS.virtual.price + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); + + // Check paid with Mollie + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + + // WOOCOMMERCE ORDER PAGE + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + }); +}); diff --git a/tests/e2e/Settings/generalSettings.spec.js b/tests/e2e/Settings/generalSettings.spec.js new file mode 100644 index 000000000..9989123cd --- /dev/null +++ b/tests/e2e/Settings/generalSettings.spec.js @@ -0,0 +1,103 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } + } +const GATEWAYS = { + 'banktransfer': { + 'id' : 'banktransfer', + 'defaultTitle' : 'Bank Transfer', + 'settingsDescription' : '', + 'defaultDescription' : '', + 'paymentFields' : false, + 'instructions' : true, + 'supports' : [ + 'products', + 'refunds', + ], + 'filtersOnBuild' : true, + 'confirmationDelayed' : true, + 'SEPA' : false, + 'customRedirect' : true, + } +} +/** + * @param {import('@playwright/test').Page} page + */ +async function loginAdmin(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); +} +async function resetSettings(page){ + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await Promise.all([ + page.waitForNavigation(), + await page.locator('text=clear now').click() + ]); +} + +async function insertAPIKeys(page){ + await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); + await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +test.describe('Should show general settings', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + //login as Admin + await loginAdmin(page); + await resetSettings(page); + + + + }); + test('Should show empty and disconnected', async ({ page }) => { + // Go to settings + await loginAdmin(page); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); + await expect(page.locator('text=No API key provided. Please set your Mollie API keys below.')).toBeVisible(); + + for ( const key in GATEWAYS ){ + let testedGateway = GATEWAYS[key] + //check default icon with a locator that has disabled and activate + const url = await page.$eval(`text=${testedGateway.defaultTitle} disabled activate >> img`, img => img.src); + await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${testedGateway.id}.svg`) + } + //fill with API keys + await page.locator('[placeholder="Live API key should start with live_"]').fill('live_HFGW8amkfcb7dvrasy8WdUNRNhscxa'); + await page.locator('input[name="mollie-payments-for-woocommerce_test_mode_enabled"]').check(); + await page.locator('[placeholder="Test API key should start with test_"]').fill('test_NgHd7vSyPSpEyuTEwhvsxdjsgVG4SV'); + // Click text=Save changes + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion' }*/), + page.locator('text=Save changes').click() + ]); + await expect(page.locator('text=Mollie status: Connected')).toBeVisible(); + for ( const key in GATEWAYS ){ + let testedGateway = GATEWAYS[key] + await expect(page.locator(`text=${testedGateway.defaultTitle} enabled edit >> span`)).toBeVisible(); + } + }); +}); + + + + + + + + + diff --git a/tests/e2e/Settings/paymentClassicCheckout.spec.js b/tests/e2e/Settings/paymentClassicCheckout.spec.js index 094c5671c..6097a0a09 100644 --- a/tests/e2e/Settings/paymentClassicCheckout.spec.js +++ b/tests/e2e/Settings/paymentClassicCheckout.spec.js @@ -1,9 +1,27 @@ // @ts-check const { test, expect } = require('@playwright/test'); - +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } + } const GATEWAYS = { 'banktransfer': { - 'title': 'Bank Transfer', + 'id' : 'banktransfer', + 'defaultTitle' : 'Bank Transfer', + 'settingsDescription' : '', + 'defaultDescription' : '', + 'paymentFields' : false, + 'instructions' : true, + 'supports' : [ + 'products', + 'refunds', + ], + 'filtersOnBuild' : true, + 'confirmationDelayed' : true, + 'SEPA' : false, + 'customRedirect' : true, } } /** @@ -15,26 +33,109 @@ async function loginAdmin(page) { await Promise.all([ page.waitForNavigation(), page.locator('text=Log in').click() -]); + ]); +} +async function resetSettings(page){ + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await Promise.all([ + page.waitForNavigation(), + await page.locator('text=clear now').click() + ]); +} + +async function insertAPIKeys(page){ + await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); + await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); } + test.describe('Should show payment settings on classic checkout', () => { - test.beforeAll(async ({ page }) => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); //login as Admin await loginAdmin(page); - //reset settings - //go to checkout + await resetSettings(page); + await insertAPIKeys(page); + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add product to cart + const productCartButton = PRODUCTS.simple.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); }); - test('Should show default settings', async ({ page }) => { - for ( const key in GATEWAYS){ + for ( const key in GATEWAYS){ + test(`Should show ${key} default settings`, async ({ page }) => { + // Go to checkout + await page.goto(process.env.E2E_URL_TESTSITE + '/checkout'); let testedGateway = GATEWAYS[key] //check default title + await page.locator('#payment_method_mollie_wc_gateway_' + testedGateway.id) + await expect(page.locator('#payment')).toContainText(testedGateway.defaultTitle); //check default icon + const url = await page.$eval(`text=${testedGateway.defaultTitle} >> img`, img => img.src); + await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${testedGateway.id}.svg`) //check default description + await expect(page.locator('#payment')).toContainText(testedGateway.defaultDescription); //check issuers dropdown show - //shown with random available country + if(testedGateway.paymentFields){ + let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) + await expect(issuers).toContainText(testedGateway.defaultDescription) + } //no fee added - }// end loop gateways + await expect(page.locator('#order_review')).not.toContainText('Fee') }); + }// end loop gateways + for ( const key in GATEWAYS){ + test(`Should show ${key} custom settings`, async ({ page }) => { + let testedGateway = GATEWAYS[key] + await loginAdmin(page); + //set custom settings + await page.goto(`${process.env.E2E_URL_TESTSITE}/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_${testedGateway.id}`) + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_title"]`).fill(`${testedGateway.defaultTitle} edited`); + await page.locator(`textarea[name="mollie_wc_gateway_${testedGateway.id}_description"]`).fill(`${testedGateway.defaultTitle} description edited`); + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_display_logo"]`).uncheck(); + //await page.locator(`#mainform > table:nth-child(9) > tbody > tr > td > span.select2.select2-container.select2-container--default > span.selection > span > ul > li > input`).click(); + await page.locator('[placeholder="Choose countries…"]').click(); + await page.locator('[placeholder="Choose countries…"]').fill('spa'); + await page.locator('li[role="option"]:has-text("Spain")').click(); + await page.locator(`select[name="mollie_wc_gateway_${testedGateway.id}_payment_surcharge"]`).selectOption('fixed_fee'); + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_fixed_fee"]`).fill('10'); + if(testedGateway.paymentFields){ + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_issuers_dropdown_shown"]`).uncheck(); + } + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + // Go to checkout + await page.goto(process.env.E2E_URL_TESTSITE + '/checkout'); + + //check custom title + await page.locator(`select[name="billing_country"]`).selectOption('ES'); + await page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`).click() + await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).toContainText(`${testedGateway.defaultTitle} edited`); + //check not display logo + await expect(page.locator(`text=${testedGateway.defaultTitle} >> img`)).toBeFalsy + //check custom description + await expect(page.locator('#payment')).toContainText(`${testedGateway.defaultTitle} description edited`); + //check issuers dropdown not show + if(testedGateway.paymentFields){ + let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) + await expect(issuers).toBeEmpty + } + //check fee added + await expect(page.locator('#order_review')).toContainText('Fee') + //check not sell to countries + await page.locator(`select[name="billing_country"]`).selectOption('DE'); + await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).not.toBeVisible(); + await page.locator(`select[name="billing_country"]`).selectOption('ES'); + + }); + }// end loop gateways }); diff --git a/tests/e2e/Transaction/classicCheckout.spec.js b/tests/e2e/Transaction/classicCheckout.spec.js index 4a1a2d01c..916aea3f6 100644 --- a/tests/e2e/Transaction/classicCheckout.spec.js +++ b/tests/e2e/Transaction/classicCheckout.spec.js @@ -1,134 +1,371 @@ // @ts-check -const { test, expect } = require('@playwright/test'); +const {test, expect} = require('@playwright/test'); const GATEWAYS = { - 'banktransfer':{ - 'title':'Bank Transfer', + 'banktransfer': { + 'title': 'Bank Transfer', - } + } } const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } } + /** * @param {import('@playwright/test').Page} page */ async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); } + /** * @param {import('@playwright/test').Page} page */ async function setOrderAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); } + /** * @param {import('@playwright/test').Page} page */ async function setPaymentAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +async function addProductToCart(page, testedProduct) { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add product to cart + const productCartButton = testedProduct.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); +} + +async function fillCustomerInCheckout(page) { + // Fill input[name="billing_first_name"] + await page.locator('input[name="billing_first_name"]').fill('Test'); + // Fill input[name="billing_last_name"] + await page.locator('input[name="billing_last_name"]').fill('test'); +} + +async function markPaidInMollie(page) { + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + return mollieOrder; } + +async function wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway) { + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); +} + +async function wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); +} + /** * @param {import('@playwright/test').Page} page + * @param testedProduct + * @param testedGateway */ -async function classicCheckoutTransaction(page, testedProduct, testedGateway) { - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add product to cart - const productCartButton = testedProduct.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); - - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); - - // CUSTOMER DETAILS - // Fill input[name="billing_first_name"] - await page.locator('input[name="billing_first_name"]').fill('Test'); - // Fill input[name="billing_last_name"] - await page.locator('input[name="billing_last_name"]').fill('test'); - - // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); - // Click text=Place order - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - page.locator('text=Place order').click() - ]); - - // IN MOLLIE - // Capture order number in Mollie and mark as paid - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - - // WOOCOMMERCE ORDER PAID PAGE - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); - - // WOOCOMMERCE ORDER PAGE - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); - - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); +async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + await fillCustomerInCheckout(page); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); + + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); } + +async function classicCheckoutFailedTransaction(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + await fillCustomerInCheckout(page); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markFailedInMollie(page); + + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); +} + +async function classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway) { + +} + +async function classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { + +} + +async function classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { + await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + //in order page select quantity + //refund +} + +async function classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway) { + await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + //in order page select partial amount + //refund +} + +async function classicCheckoutExpiredTransaction(page, testedProduct, testedGateway) { + +} + test.describe('Transaction in classic checkout', () => { - test('Transaction with Order API', async ({ page }) => { - //login as Admin - await loginAdmin(page); - await setOrderAPI(page); - for ( const key in GATEWAYS){ - let testedGateway = GATEWAYS[key] - for( const key in PRODUCTS){ - let testedProduct = PRODUCTS[key] - await classicCheckoutTransaction(page, testedProduct, testedGateway); - }// end loop products - }// end loop gateways - }); - test('Transaction with Payment API', async ({ page }) => { - //login as Admin - await loginAdmin(page); - //Set Payment API - await setPaymentAPI(page); - for ( const key in GATEWAYS){ - let testedGateway = GATEWAYS[key] - for( const key in PRODUCTS){ - let testedProduct = PRODUCTS[key] - await classicCheckoutTransaction(page, testedProduct, testedGateway); - }// end loop products - }// end loop gateways + test('Transaction with Order API paid', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API failed', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutFailedTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API cancelled setting as pending', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + //setting as pending + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API cancelled setting as cancelled', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + //setting as cancelled + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction full refund Order', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction partial refund Order', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API expired', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutExpiredTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API paid', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API cancelled setting as pending', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + //setting as pending + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API cancelled setting as cancelled', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + //setting as cancelled + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction full refund Payment', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction partial refund Payment', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API expired', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await classicCheckoutExpiredTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); }); -}); \ No newline at end of file From 50c0219ffe932f7dca0171f231340ebb8c8a164b Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 5 May 2022 09:58:38 +0200 Subject: [PATCH 004/100] MOL-383 Extract shared functions --- .gitignore | 2 +- tests/e2e/Cart/PayPalButtonBlockCart.spec.js | 126 ++++++++ .../e2e/Cart/PayPalButtonClassicCart.spec.js | 88 +----- .../PayPalButtonClassicProduct.spec.js | 69 +--- tests/e2e/Settings/generalSettings.spec.js | 39 +-- .../Settings/paymentClassicCheckout.spec.js | 32 +- .../{config => Shared}/default.example.json | 0 tests/e2e/Shared/mollieUtils.js | 61 ++++ tests/e2e/Shared/testMollieInWooPage.js | 22 ++ tests/e2e/Shared/wooUtils.js | 32 ++ tests/e2e/Shared/wpUtils.js | 14 + tests/e2e/Transaction/BlockCheckout.spec.js | 299 ++++++++++++++++++ tests/e2e/Transaction/classicCheckout.spec.js | 84 +---- 13 files changed, 596 insertions(+), 272 deletions(-) create mode 100644 tests/e2e/Cart/PayPalButtonBlockCart.spec.js rename tests/e2e/{config => Shared}/default.example.json (100%) create mode 100644 tests/e2e/Shared/mollieUtils.js create mode 100644 tests/e2e/Shared/testMollieInWooPage.js create mode 100644 tests/e2e/Shared/wooUtils.js create mode 100644 tests/e2e/Shared/wpUtils.js create mode 100644 tests/e2e/Transaction/BlockCheckout.spec.js diff --git a/.gitignore b/.gitignore index a8f562c78..50f340238 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ /public/css/ /tools/ /build/ -/tests/e2e/config/default.json +/tests/e2e/Shared/default.json .env cypress.json diff --git a/tests/e2e/Cart/PayPalButtonBlockCart.spec.js b/tests/e2e/Cart/PayPalButtonBlockCart.spec.js new file mode 100644 index 000000000..42cd6f5f0 --- /dev/null +++ b/tests/e2e/Cart/PayPalButtonBlockCart.spec.js @@ -0,0 +1,126 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const GATEWAYS = { + 'paypal':{ + 'title':'PayPal', + + } +} +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + }, + 'virtual': { + 'name': 'virtual_no_down', + 'price': '20,25€' + } +} + +/** + * @param {import('@playwright/test').Page} page + */ +async function setOrderAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} +/** + * @param {import('@playwright/test').Page} page + */ +async function setPaymentAPI(page) { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +test.describe('PayPal Transaction in block cart', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await loginAdmin(page); + + }); + test('Not be seen if not enabled', async ({ page }) => { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add virtual product to cart + const productCartButton = PRODUCTS.virtual.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and not see + await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + //remove from cart + await page.locator('.product-remove').click(); + }); + test('Not be seen if not virtual', async ({ page }) => { + // set PayPal visible in cart + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add non virtual product to cart + const productCartButton = PRODUCTS.simple.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and not see + await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); + await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); + //remove from cart + await page.locator('.product-remove').click(); + }); + test('Transaction with Order API - virtual product', async ({ page }) => { + let testedGateway = GATEWAYS.paypal + await loginAdmin(page); + await setOrderAPI(page); + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add virtual product to cart + const productCartButton = PRODUCTS.virtual.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + //go to cart and click + await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); + + // Check paid with Mollie + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + + // WOOCOMMERCE ORDER PAGE + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + }); +}); diff --git a/tests/e2e/Cart/PayPalButtonClassicCart.spec.js b/tests/e2e/Cart/PayPalButtonClassicCart.spec.js index de6b79d8a..66ae839cb 100644 --- a/tests/e2e/Cart/PayPalButtonClassicCart.spec.js +++ b/tests/e2e/Cart/PayPalButtonClassicCart.spec.js @@ -1,5 +1,10 @@ // @ts-check const { test, expect } = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {addProductToCart} = require('../Shared/wooUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); + const GATEWAYS = { 'paypal':{ 'title':'PayPal', @@ -16,39 +21,6 @@ const PRODUCTS = { 'price': '20,25€' } } -/** - * @param {import('@playwright/test').Page} page - */ -async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} -/** - * @param {import('@playwright/test').Page} page - */ -async function setOrderAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} -/** - * @param {import('@playwright/test').Page} page - */ -async function setPaymentAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} test.describe('PayPal Transaction in classic cart', () => { test.beforeAll(async ({browser }) => { @@ -57,11 +29,7 @@ test.describe('PayPal Transaction in classic cart', () => { }); test('Not be seen if not enabled', async ({ page }) => { - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add virtual product to cart - const productCartButton = PRODUCTS.virtual.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await addProductToCart(page, PRODUCTS.virtual.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); @@ -76,11 +44,7 @@ test.describe('PayPal Transaction in classic cart', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add non virtual product to cart - const productCartButton = PRODUCTS.simple.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await addProductToCart(page, PRODUCTS.simple.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); @@ -89,13 +53,9 @@ test.describe('PayPal Transaction in classic cart', () => { }); test('Transaction with Order API - virtual product', async ({ page }) => { let testedGateway = GATEWAYS.paypal - await loginAdmin(page); - await setOrderAPI(page); - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add virtual product to cart - const productCartButton = PRODUCTS.virtual.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await loginAdmin(page); + await setOrderAPI(page); + await addProductToCart(page, PRODUCTS.virtual.name); //go to cart and click await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); //Capture WooCommerce total amount @@ -105,30 +65,14 @@ test.describe('PayPal Transaction in classic cart', () => { page.locator('input[alt="PayPal Button"]').click() ]); - // Check paid with Mollie - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); - - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); }); }); diff --git a/tests/e2e/Product/PayPalButtonClassicProduct.spec.js b/tests/e2e/Product/PayPalButtonClassicProduct.spec.js index 4a91b4735..2901cba39 100644 --- a/tests/e2e/Product/PayPalButtonClassicProduct.spec.js +++ b/tests/e2e/Product/PayPalButtonClassicProduct.spec.js @@ -1,5 +1,10 @@ // @ts-check const { test, expect } = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); + + const GATEWAYS = { 'paypal':{ 'title':'PayPal', @@ -16,39 +21,7 @@ const PRODUCTS = { 'price': '20,25€' } } -/** - * @param {import('@playwright/test').Page} page - */ -async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} -/** - * @param {import('@playwright/test').Page} page - */ -async function setOrderAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} -/** - * @param {import('@playwright/test').Page} page - */ -async function setPaymentAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} + test.describe('PayPal Transaction in classic product', () => { test.beforeAll(async ({browser }) => { @@ -89,30 +62,14 @@ test.describe('PayPal Transaction in classic product', () => { page.locator('input[alt="PayPal Button"]').click() ]); - // Check paid with Mollie - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); - // WOOCOMMERCE ORDER PAGE - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); }); }); diff --git a/tests/e2e/Settings/generalSettings.spec.js b/tests/e2e/Settings/generalSettings.spec.js index 9989123cd..ce4e95339 100644 --- a/tests/e2e/Settings/generalSettings.spec.js +++ b/tests/e2e/Settings/generalSettings.spec.js @@ -1,5 +1,7 @@ // @ts-check const { test, expect } = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); const PRODUCTS = { 'simple': { 'name': 'simple_taxes', @@ -24,35 +26,6 @@ const GATEWAYS = { 'customRedirect' : true, } } -/** - * @param {import('@playwright/test').Page} page - */ -async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} -async function resetSettings(page){ - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await Promise.all([ - page.waitForNavigation(), - await page.locator('text=clear now').click() - ]); -} - -async function insertAPIKeys(page){ - await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); - await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); - await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); - await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} test.describe('Should show general settings', () => { test.beforeAll(async ({browser }) => { @@ -60,16 +33,14 @@ test.describe('Should show general settings', () => { //login as Admin await loginAdmin(page); await resetSettings(page); - - - + await insertAPIKeys(page); }); test('Should show empty and disconnected', async ({ page }) => { // Go to settings await loginAdmin(page); await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); await expect(page.locator('text=No API key provided. Please set your Mollie API keys below.')).toBeVisible(); - + for ( const key in GATEWAYS ){ let testedGateway = GATEWAYS[key] //check default icon with a locator that has disabled and activate @@ -89,7 +60,7 @@ test.describe('Should show general settings', () => { for ( const key in GATEWAYS ){ let testedGateway = GATEWAYS[key] await expect(page.locator(`text=${testedGateway.defaultTitle} enabled edit >> span`)).toBeVisible(); - } + } }); }); diff --git a/tests/e2e/Settings/paymentClassicCheckout.spec.js b/tests/e2e/Settings/paymentClassicCheckout.spec.js index 6097a0a09..ee1e3b16e 100644 --- a/tests/e2e/Settings/paymentClassicCheckout.spec.js +++ b/tests/e2e/Settings/paymentClassicCheckout.spec.js @@ -1,5 +1,8 @@ // @ts-check const { test, expect } = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); + const PRODUCTS = { 'simple': { 'name': 'simple_taxes', @@ -24,35 +27,6 @@ const GATEWAYS = { 'customRedirect' : true, } } -/** - * @param {import('@playwright/test').Page} page - */ -async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} -async function resetSettings(page){ - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await Promise.all([ - page.waitForNavigation(), - await page.locator('text=clear now').click() - ]); -} - -async function insertAPIKeys(page){ - await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); - await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); - await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); - await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} test.describe('Should show payment settings on classic checkout', () => { test.beforeAll(async ({browser }) => { diff --git a/tests/e2e/config/default.example.json b/tests/e2e/Shared/default.example.json similarity index 100% rename from tests/e2e/config/default.example.json rename to tests/e2e/Shared/default.example.json diff --git a/tests/e2e/Shared/mollieUtils.js b/tests/e2e/Shared/mollieUtils.js new file mode 100644 index 000000000..4337d1014 --- /dev/null +++ b/tests/e2e/Shared/mollieUtils.js @@ -0,0 +1,61 @@ +/** + * @param {import('@playwright/test').Page} page + */ +const setOrderAPI = async (page) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +/** + * @param {import('@playwright/test').Page} page + */ +const setPaymentAPI = async (page) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +/** + * @param {import('@playwright/test').Page} page + */ +const markPaidInMollie = async (page) =>{ + const mollieHeader = await page.innerText('.header__info'); + const mollieOrder = mollieHeader.substring(6, mollieHeader.length) + await page.locator('text=Paid').click(); + await page.locator('text=Continue').click(); + return mollieOrder; +} + +/** + * @param {import('@playwright/test').Page} page + */ +const insertAPIKeys = async (page) =>{ + await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); + await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); + await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); +} + +/** + * @param {import('@playwright/test').Page} page + */ +const resetSettings = async (page) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await Promise.all([ + page.waitForNavigation(), + await page.locator('text=clear now').click() + ]); +} + +module.exports = {setOrderAPI, setPaymentAPI, markPaidInMollie, insertAPIKeys, resetSettings}; diff --git a/tests/e2e/Shared/testMollieInWooPage.js b/tests/e2e/Shared/testMollieInWooPage.js new file mode 100644 index 000000000..f5047590a --- /dev/null +++ b/tests/e2e/Shared/testMollieInWooPage.js @@ -0,0 +1,22 @@ +const wooOrderPaidPage = async (page, mollieOrder, totalAmount, testedGateway) => { + // Check order number + await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); + // Check total amount in order + await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); + // Check customer in billind details + await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + // Check Mollie method appears + await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); +} + +const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); +} + +module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid} diff --git a/tests/e2e/Shared/wooUtils.js b/tests/e2e/Shared/wooUtils.js new file mode 100644 index 000000000..13b3f71e0 --- /dev/null +++ b/tests/e2e/Shared/wooUtils.js @@ -0,0 +1,32 @@ +/** + * @param {import('@playwright/test').Page} page + */ +const addProductToCart = async (page, testedProduct) => { + // Go to shop + await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); + // Add product to cart + const productCartButton = testedProduct.name; + await page.locator('[data-product_sku="' + productCartButton + '"]').click(); +} + +/** + * @param {import('@playwright/test').Page} page + */ +const fillCustomerInCheckout = async (page) => { + // Fill input[name="billing_first_name"] + await page.locator('input[name="billing_first_name"]').fill('Test'); + // Fill input[name="billing_last_name"] + await page.locator('input[name="billing_last_name"]').fill('test'); +} + +/** + * @param {import('@playwright/test').Page} page + */ +const fillCustomerInBlockCheckout = async (page) => { + // Fill input[name="billing_first_name"] + await page.locator('input[name="billing_first_name"]').fill('Test'); + // Fill input[name="billing_last_name"] + await page.locator('input[name="billing_last_name"]').fill('test'); +} + +module.exports = {addProductToCart, fillCustomerInCheckout, fillCustomerInBlockCheckout} diff --git a/tests/e2e/Shared/wpUtils.js b/tests/e2e/Shared/wpUtils.js new file mode 100644 index 000000000..f3952174a --- /dev/null +++ b/tests/e2e/Shared/wpUtils.js @@ -0,0 +1,14 @@ + + +const loginAdmin = async (page)=>{ + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_pass').fill(process.env.ADMIN_PASS); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Log in').click() + ]); + +} + +module.exports = {loginAdmin}; + diff --git a/tests/e2e/Transaction/BlockCheckout.spec.js b/tests/e2e/Transaction/BlockCheckout.spec.js new file mode 100644 index 000000000..de925d70b --- /dev/null +++ b/tests/e2e/Transaction/BlockCheckout.spec.js @@ -0,0 +1,299 @@ +// @ts-check +const {test, expect} = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); +const {addProductToCart, fillCustomerInBlockCheckout} = require('../Shared/wooUtils'); + +const GATEWAYS = { + 'banktransfer': { + 'title': 'Bank Transfer', + + } +} +const PRODUCTS = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } +} + + + + +/** + * @param {import('@playwright/test').Page} page + * @param testedProduct + * @param testedGateway + */ +async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + await fillCustomerInBlockCheckout(page); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); + + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); +} + +async function blockCheckoutFailedTransaction(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct); + + // Go to checkout + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + await page.locator('text=Checkout').first().click() + ]); + + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); + + // CUSTOMER DETAILS + await fillCustomerInBlockCheckout(page); + + // Check testedGateway option NO ISSUERS DROPDOWN + await page.locator('text=' + testedGateway.title).check(); + // Click text=Place order + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), + page.locator('text=Place order').click() + ]); + + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markFailedInMollie(page); + + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); +} + +async function blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway) { + +} + +async function blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { + +} + +async function blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { + await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + //in order page select quantity + //refund +} + +async function blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway) { + await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + //in order page select partial amount + //refund +} + +async function blockCheckoutExpiredTransaction(page, testedProduct, testedGateway) { + +} + +test.describe('Transaction in classic checkout', () => { + test('Transaction with Order API paid', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API failed', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutFailedTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API cancelled setting as pending', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + //setting as pending + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API cancelled setting as cancelled', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + //setting as cancelled + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction full refund Order', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction partial refund Order', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Order API expired', async ({page}) => { + await loginAdmin(page); + await setOrderAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutExpiredTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API paid', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API cancelled setting as pending', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + //setting as pending + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API cancelled setting as cancelled', async ({page}) => { + //login as Admin + await loginAdmin(page); + //Set Payment API + await setPaymentAPI(page); + //setting as cancelled + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction full refund Payment', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction partial refund Payment', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); + test('Transaction with Payment API expired', async ({page}) => { + await loginAdmin(page); + await setPaymentAPI(page); + for (const key in GATEWAYS) { + let testedGateway = GATEWAYS[key] + for (const key in PRODUCTS) { + let testedProduct = PRODUCTS[key] + await blockCheckoutExpiredTransaction(page, testedProduct, testedGateway); + }// end loop products + }// end loop gateways + }); +}); diff --git a/tests/e2e/Transaction/classicCheckout.spec.js b/tests/e2e/Transaction/classicCheckout.spec.js index 916aea3f6..11531f270 100644 --- a/tests/e2e/Transaction/classicCheckout.spec.js +++ b/tests/e2e/Transaction/classicCheckout.spec.js @@ -1,5 +1,9 @@ // @ts-check const {test, expect} = require('@playwright/test'); +const { loginAdmin } = require('../Shared/wpUtils'); +const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); +const {addProductToCart, fillCustomerInCheckout} = require('../Shared/wooUtils'); const GATEWAYS = { 'banktransfer': { 'title': 'Bank Transfer', @@ -13,86 +17,6 @@ const PRODUCTS = { } } -/** - * @param {import('@playwright/test').Page} page - */ -async function loginAdmin(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); - await page.locator('#user_pass').fill(process.env.ADMIN_PASS); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Log in').click() - ]); -} - -/** - * @param {import('@playwright/test').Page} page - */ -async function setOrderAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} - -/** - * @param {import('@playwright/test').Page} page - */ -async function setPaymentAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} - -async function addProductToCart(page, testedProduct) { - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add product to cart - const productCartButton = testedProduct.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); -} - -async function fillCustomerInCheckout(page) { - // Fill input[name="billing_first_name"] - await page.locator('input[name="billing_first_name"]').fill('Test'); - // Fill input[name="billing_last_name"] - await page.locator('input[name="billing_last_name"]').fill('test'); -} - -async function markPaidInMollie(page) { - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - return mollieOrder; -} - -async function wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway) { - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); -} - -async function wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); - - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); -} - /** * @param {import('@playwright/test').Page} page * @param testedProduct From 395a693a9e89fa3b4c6716a495a73fc7dbc6874b Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 6 May 2022 15:29:13 +0200 Subject: [PATCH 005/100] MOL-383 use shared functions --- tests/e2e/Cart/PayPalButtonBlockCart.spec.js | 75 ++++---------------- tests/e2e/Shared/mollieUtils.js | 2 +- tests/e2e/Shared/wooUtils.js | 6 +- 3 files changed, 19 insertions(+), 64 deletions(-) diff --git a/tests/e2e/Cart/PayPalButtonBlockCart.spec.js b/tests/e2e/Cart/PayPalButtonBlockCart.spec.js index 42cd6f5f0..a3b8913a9 100644 --- a/tests/e2e/Cart/PayPalButtonBlockCart.spec.js +++ b/tests/e2e/Cart/PayPalButtonBlockCart.spec.js @@ -1,6 +1,10 @@ // @ts-check const { test, expect } = require('@playwright/test'); const { loginAdmin } = require('../Shared/wpUtils'); +const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {addProductToCart} = require('../Shared/wooUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); + const GATEWAYS = { 'paypal':{ 'title':'PayPal', @@ -18,28 +22,6 @@ const PRODUCTS = { } } -/** - * @param {import('@playwright/test').Page} page - */ -async function setOrderAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'order') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} -/** - * @param {import('@playwright/test').Page} page - */ -async function setPaymentAPI(page) { - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_api_switch', 'payment') - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); -} test.describe('PayPal Transaction in block cart', () => { test.beforeAll(async ({browser }) => { @@ -49,10 +31,7 @@ test.describe('PayPal Transaction in block cart', () => { }); test('Not be seen if not enabled', async ({ page }) => { // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add virtual product to cart - const productCartButton = PRODUCTS.virtual.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await addProductToCart(page, PRODUCTS.virtual.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); @@ -67,11 +46,7 @@ test.describe('PayPal Transaction in block cart', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add non virtual product to cart - const productCartButton = PRODUCTS.simple.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await addProductToCart(page, PRODUCTS.simple.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); @@ -80,13 +55,9 @@ test.describe('PayPal Transaction in block cart', () => { }); test('Transaction with Order API - virtual product', async ({ page }) => { let testedGateway = GATEWAYS.paypal - await loginAdmin(page); - await setOrderAPI(page); - // Go to shop - await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); - // Add virtual product to cart - const productCartButton = PRODUCTS.virtual.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await loginAdmin(page); + await setOrderAPI(page); + await addProductToCart(page, PRODUCTS.virtual.name); //go to cart and click await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); @@ -97,30 +68,14 @@ test.describe('PayPal Transaction in block cart', () => { page.locator('input[alt="PayPal Button"]').click() ]); - // Check paid with Mollie - const mollieHeader = await page.innerText('.header__info'); - const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); - await page.locator('text=Continue').click(); - + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/order-received/639/?key=wc_order_DO3CVhQvzpCxv&utm_nooverride=1'); - // Check order number - await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); - // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); - // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); - // Check order is in status processing in order page - await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Processing"); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); - - // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); }); }); diff --git a/tests/e2e/Shared/mollieUtils.js b/tests/e2e/Shared/mollieUtils.js index 4337d1014..6ca7ab4c2 100644 --- a/tests/e2e/Shared/mollieUtils.js +++ b/tests/e2e/Shared/mollieUtils.js @@ -37,7 +37,7 @@ const markPaidInMollie = async (page) =>{ * @param {import('@playwright/test').Page} page */ const insertAPIKeys = async (page) =>{ - await page.goto('https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings'); await page.locator(`input[name="mollie-payments-for-woocommerce_live_api_key"]`).fill(process.env.MOLLIE_LIVE_API_KEY); await page.locator(`input[name="mollie-payments-for-woocommerce_test_mode_enabled"]`).check(); await page.locator(`input[name="mollie-payments-for-woocommerce_test_api_key"]`).fill(process.env.MOLLIE_TEST_API_KEY); diff --git a/tests/e2e/Shared/wooUtils.js b/tests/e2e/Shared/wooUtils.js index 13b3f71e0..f94e81a7c 100644 --- a/tests/e2e/Shared/wooUtils.js +++ b/tests/e2e/Shared/wooUtils.js @@ -1,12 +1,12 @@ /** * @param {import('@playwright/test').Page} page + * @param testedProductName */ -const addProductToCart = async (page, testedProduct) => { +const addProductToCart = async (page, testedProductName) => { // Go to shop await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); // Add product to cart - const productCartButton = testedProduct.name; - await page.locator('[data-product_sku="' + productCartButton + '"]').click(); + await page.locator('[data-product_sku="' + testedProductName + '"]').click(); } /** From 8b4acad50ec10cdf3f04bb7a85a7ffccb6628b82 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 9 May 2022 16:01:49 +0200 Subject: [PATCH 006/100] MOL-383 set e2e projects with different loads ddev --- .../orchestrate.d/51_woocommerce_products.sh | 4 + .idea/php.xml | 51 ++++++-- DEVELOPERS.md | 13 ++ package.json | 9 +- playwright.config.js | 114 +++++++++++------- ...spec.js => PayPalButtonCart.block.spec.js} | 0 ...ec.js => PayPalButtonCart.classic.spec.js} | 0 ...js => PayPalButtonProduct.classic.spec.js} | 0 ...> PaymentSettingsCheckout.classic.spec.js} | 0 tests/e2e/Settings/generalSettings.spec.js | 38 ++---- tests/e2e/Shared/base-test.js | 8 ++ tests/e2e/Shared/gateways.js | 38 ++++++ tests/e2e/Shared/products.js | 15 +++ ...heckout.spec.js => Checkout.block.spec.js} | 0 ...ckout.spec.js => Checkout.classic.spec.js} | 0 15 files changed, 201 insertions(+), 89 deletions(-) create mode 100644 .ddev/commands/web/orchestrate.d/51_woocommerce_products.sh rename tests/e2e/Cart/{PayPalButtonBlockCart.spec.js => PayPalButtonCart.block.spec.js} (100%) rename tests/e2e/Cart/{PayPalButtonClassicCart.spec.js => PayPalButtonCart.classic.spec.js} (100%) rename tests/e2e/Product/{PayPalButtonClassicProduct.spec.js => PayPalButtonProduct.classic.spec.js} (100%) rename tests/e2e/Settings/{paymentClassicCheckout.spec.js => PaymentSettingsCheckout.classic.spec.js} (100%) create mode 100644 tests/e2e/Shared/base-test.js create mode 100644 tests/e2e/Shared/gateways.js create mode 100644 tests/e2e/Shared/products.js rename tests/e2e/Transaction/{BlockCheckout.spec.js => Checkout.block.spec.js} (100%) rename tests/e2e/Transaction/{classicCheckout.spec.js => Checkout.classic.spec.js} (100%) diff --git a/.ddev/commands/web/orchestrate.d/51_woocommerce_products.sh b/.ddev/commands/web/orchestrate.d/51_woocommerce_products.sh new file mode 100644 index 000000000..e70cd9ced --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/51_woocommerce_products.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +wp plugin install wordpress-importer --activate +wp import wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=skip diff --git a/.idea/php.xml b/.idea/php.xml index d9cc407a9..a52249f5a 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -64,22 +64,47 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + @@ -308,4 +333,4 @@ - \ No newline at end of file + diff --git a/DEVELOPERS.md b/DEVELOPERS.md index 07e1fd842..8ead856d5 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -21,6 +21,19 @@ template package [`wp-oop/plugin-boilerplate`][]. 3. Run `ddev orchestrate` to set up the WordPress environment. (You can pass the `-f` flag if you ever wish to start from scratch) 4. TODO: document how to build assets +## Using ngrok +You will often need to test and debug webhooks which require your development environment to be reachable from the outside +DDEV provides integration with `ngrok` via the `ddev share` command. Unfortunately, this is not very helpful with WordPress +since it needs correct URLs in the database. +Therefore, we have a wrapper command that sets up & restores the URLs in the database before and after a sharing session. +You will need to have ngrok and jq command previously installed. You also need to sign up for an ngrok account and connect with the token, if you have not done it before. + +To start a sharing session, simply run +```shell +bin/ddev-share +``` + + ## Using ngrok You will often need to test and debug webhooks which require your development environment to be reachable from the outside DDEV provides integration with `ngrok` via the `ddev share` command. Unfortunately, this is not very helpful with WordPress diff --git a/package.json b/package.json index a4c37ca8d..ec9b4bd6b 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,14 @@ "scripts": { "watch": "webpack --watch", "build": "gulp buildAssets", - "setup": "gulp setup" + "setup": "gulp setup", + "e2e-simple": "npx playwright test --project=simple-classic", + "e2e-block": "npx playwright test --project=simple-block", + "e2e-full-transaction": "npx playwright test --project=full-transaction", + "e2e-cart-paypal": "npx playwright test --project=cart-paypal", + "e2e-product-paypal": "npx playwright test --project=product-paypal", + "e2e-simple-settings": "npx playwright test --project=simple-settings", + "e2e-full-settings": "npx playwright test --project=full-settings" }, "dependencies": { "@woocommerce/e2e-utils": "^0.1.6", diff --git a/playwright.config.js b/playwright.config.js index e641ae3d1..402a56f55 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,6 +1,7 @@ // @ts-check const { devices } = require('@playwright/test'); - +const {simple, virtual} = require('./tests/e2e/Shared/products'); +const {banktransfer, paypal} = require('./tests/e2e/Shared/gateways'); /** * Read environment variables from file. * https://github.com/motdotla/dotenv @@ -48,54 +49,77 @@ const config = { /* Configure projects for major browsers */ projects: [ - { - name: 'chromium', - use: { - ...devices['Desktop Chrome'], + //all simple classic:simple prod, simple subs, one gw, one browser, checkout and settings, no buttons + { + name: 'simple-classic', + testIgnore: ['**/Cart/**','**/Product/**', '**/*.block.spec.js'], + use: { + ...devices['Desktop Chrome'], + gateways: banktransfer, + products: simple, + }, }, - }, - { - name: 'firefox', - use: { - ...devices['Desktop Firefox'], + //all simple blocks:simple prod, simple subs, one gw, one browser + { + name: 'simple-block', + testIgnore: ['**/Cart/**','**/Product/**', '**/*.classic.spec.js'], + use: { + ...devices['Desktop Chrome'], + gateways: banktransfer, + products: simple, + }, }, - }, - - { - name: 'webkit', - use: { - ...devices['Desktop Safari'], + //cart :paypal + { + name: 'cart-paypal', + testMatch: '**/Cart/**', + use: { + ...devices['Desktop Chrome'], + gateways: paypal, + products: {simple, virtual}, + }, + }, + //product:paypal + { + name: 'product-paypal', + testMatch: '**/Product/**', + use: { + ...devices['Desktop Chrome'], + gateways: paypal, + products: {simple, virtual}, + }, + }, + //settings simple + { + name: 'simple-settings', + testIgnore: ['**/Cart/**', '**/Product/**', '**/Transaction/**'], + use: { + ...devices['Desktop Chrome'], + gateways: banktransfer, + products: simple, + }, + }, + // full settings:all gw, all browsers + { + name: 'full-settings', + testIgnore: ['**/Cart/**', '**/Product/**', '**/Transaction/**'], + use: { + ...devices['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari'], + gateways: {banktransfer, paypal}, + products: simple, + }, + }, + //full transaction:all gw, all products, all browsers + { + name: 'full-transaction', + testIgnore: ['**/Cart/**', '**/Product/**', '**/Settings/**'], + use: { + ...devices['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari'], + gateways: {banktransfer, paypal}, + products: {simple, virtual}, + }, }, - }, - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { - // ...devices['Pixel 5'], - // }, - // }, - // { - // name: 'Mobile Safari', - // use: { - // ...devices['iPhone 12'], - // }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { - // channel: 'msedge', - // }, - // }, - // { - // name: 'Google Chrome', - // use: { - // channel: 'chrome', - // }, - // }, ], /* Folder for test artifacts such as screenshots, videos, traces, etc. */ diff --git a/tests/e2e/Cart/PayPalButtonBlockCart.spec.js b/tests/e2e/Cart/PayPalButtonCart.block.spec.js similarity index 100% rename from tests/e2e/Cart/PayPalButtonBlockCart.spec.js rename to tests/e2e/Cart/PayPalButtonCart.block.spec.js diff --git a/tests/e2e/Cart/PayPalButtonClassicCart.spec.js b/tests/e2e/Cart/PayPalButtonCart.classic.spec.js similarity index 100% rename from tests/e2e/Cart/PayPalButtonClassicCart.spec.js rename to tests/e2e/Cart/PayPalButtonCart.classic.spec.js diff --git a/tests/e2e/Product/PayPalButtonClassicProduct.spec.js b/tests/e2e/Product/PayPalButtonProduct.classic.spec.js similarity index 100% rename from tests/e2e/Product/PayPalButtonClassicProduct.spec.js rename to tests/e2e/Product/PayPalButtonProduct.classic.spec.js diff --git a/tests/e2e/Settings/paymentClassicCheckout.spec.js b/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js similarity index 100% rename from tests/e2e/Settings/paymentClassicCheckout.spec.js rename to tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js diff --git a/tests/e2e/Settings/generalSettings.spec.js b/tests/e2e/Settings/generalSettings.spec.js index ce4e95339..8c13c1684 100644 --- a/tests/e2e/Settings/generalSettings.spec.js +++ b/tests/e2e/Settings/generalSettings.spec.js @@ -1,31 +1,9 @@ // @ts-check -const { test, expect } = require('@playwright/test'); +const { expect } = require('@playwright/test'); +const { test } = require('../Shared/base-test'); + const { loginAdmin } = require('../Shared/wpUtils'); const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } - } -const GATEWAYS = { - 'banktransfer': { - 'id' : 'banktransfer', - 'defaultTitle' : 'Bank Transfer', - 'settingsDescription' : '', - 'defaultDescription' : '', - 'paymentFields' : false, - 'instructions' : true, - 'supports' : [ - 'products', - 'refunds', - ], - 'filtersOnBuild' : true, - 'confirmationDelayed' : true, - 'SEPA' : false, - 'customRedirect' : true, - } -} test.describe('Should show general settings', () => { test.beforeAll(async ({browser }) => { @@ -35,14 +13,14 @@ test.describe('Should show general settings', () => { await resetSettings(page); await insertAPIKeys(page); }); - test('Should show empty and disconnected', async ({ page }) => { + test('Should show empty and disconnected', async ({ page , gateways}) => { // Go to settings await loginAdmin(page); await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); await expect(page.locator('text=No API key provided. Please set your Mollie API keys below.')).toBeVisible(); - for ( const key in GATEWAYS ){ - let testedGateway = GATEWAYS[key] + for ( const key in gateways ){ + let testedGateway = gateways[key] //check default icon with a locator that has disabled and activate const url = await page.$eval(`text=${testedGateway.defaultTitle} disabled activate >> img`, img => img.src); await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${testedGateway.id}.svg`) @@ -57,8 +35,8 @@ test.describe('Should show general settings', () => { page.locator('text=Save changes').click() ]); await expect(page.locator('text=Mollie status: Connected')).toBeVisible(); - for ( const key in GATEWAYS ){ - let testedGateway = GATEWAYS[key] + for ( const key in gateways ){ + let testedGateway = gateways[key] await expect(page.locator(`text=${testedGateway.defaultTitle} enabled edit >> span`)).toBeVisible(); } }); diff --git a/tests/e2e/Shared/base-test.js b/tests/e2e/Shared/base-test.js new file mode 100644 index 000000000..0178ae71f --- /dev/null +++ b/tests/e2e/Shared/base-test.js @@ -0,0 +1,8 @@ +const base = require('@playwright/test'); +const {simple} = require('../Shared/products'); +const {banktransfer} = require('../Shared/gateways'); + +exports.test = base.test.extend({ + products: [simple, { option: true }], + gateways: [banktransfer, { option: true }], +}); diff --git a/tests/e2e/Shared/gateways.js b/tests/e2e/Shared/gateways.js new file mode 100644 index 000000000..060b9435a --- /dev/null +++ b/tests/e2e/Shared/gateways.js @@ -0,0 +1,38 @@ +const banktransfer = { + 'id': 'banktransfer', + 'defaultTitle': 'Bank Transfer', + 'settingsDescription': '', + 'defaultDescription': '', + 'paymentFields': false, + 'instructions': true, + 'supports': [ + 'products', + 'refunds', + ], + 'filtersOnBuild': true, + 'confirmationDelayed': true, + 'SEPA': false, + 'customRedirect': true, +} +const ideal = { + 'id': 'ideal', + 'defaultTitle': 'iDeal', + 'settingsDescription': '', + 'defaultDescription': 'Select your bank', + 'paymentFields': true, + 'instructions': true, + 'supports': [ + 'products', + 'refunds', + ], + 'SEPA': true +} +const creditcard = { + 'id': 'creditcard', + 'defaultTitle': 'Credit card', +} +const paypal = { + 'id': 'paypal', + 'defaultTitle': 'PayPal', +} +module.exports = {banktransfer, ideal, creditcard, paypal}; diff --git a/tests/e2e/Shared/products.js b/tests/e2e/Shared/products.js new file mode 100644 index 000000000..f5af42a9a --- /dev/null +++ b/tests/e2e/Shared/products.js @@ -0,0 +1,15 @@ +const simple = { + 'simple': { + 'name': 'simple_taxes', + 'price': '24,33€' + } +} +const virtual = { + 'virtual': { + 'name': 'virtual_no_down', + 'price': '20,25€' + } +} + + +module.exports = {simple, virtual}; diff --git a/tests/e2e/Transaction/BlockCheckout.spec.js b/tests/e2e/Transaction/Checkout.block.spec.js similarity index 100% rename from tests/e2e/Transaction/BlockCheckout.spec.js rename to tests/e2e/Transaction/Checkout.block.spec.js diff --git a/tests/e2e/Transaction/classicCheckout.spec.js b/tests/e2e/Transaction/Checkout.classic.spec.js similarity index 100% rename from tests/e2e/Transaction/classicCheckout.spec.js rename to tests/e2e/Transaction/Checkout.classic.spec.js From 0962e6a6aa0d1b2bf4c9deec766abcd4a8f6c50e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 17 May 2022 08:06:56 +0200 Subject: [PATCH 007/100] fix tests with login and parametrized args --- playwright.config.js | 25 ++- tests/e2e/Cart/PayPalButtonCart.block.spec.js | 94 ++++------ .../e2e/Cart/PayPalButtonCart.classic.spec.js | 88 ++++------ .../PayPalButtonProduct.classic.spec.js | 77 ++++----- tests/e2e/Settings/GeneralSettings.spec.js | 33 ++++ .../PaymentSettingsCheckout.classic.spec.js | 134 ++++++--------- tests/e2e/Settings/generalSettings.spec.js | 52 ------ tests/e2e/Shared/gateways.js | 15 +- tests/e2e/Shared/global-setup.js | 10 ++ tests/e2e/Shared/products.js | 12 +- tests/e2e/Shared/wpUtils.js | 1 + .../e2e/Transaction/Checkout.classic.spec.js | 162 ++++++------------ 12 files changed, 285 insertions(+), 418 deletions(-) create mode 100644 tests/e2e/Settings/GeneralSettings.spec.js delete mode 100644 tests/e2e/Settings/generalSettings.spec.js create mode 100644 tests/e2e/Shared/global-setup.js diff --git a/playwright.config.js b/playwright.config.js index 402a56f55..5aec952a6 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -32,19 +32,16 @@ const config = { workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', + globalSetup: require.resolve('./tests/e2e/Shared/global-setup'), /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ actionTimeout: 0, /* Base URL to use in actions like `await page.goto('/')`. */ baseURL: process.env.E2E_URL_TESTSITE, - + storageState: './storageState.json', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', - httpCredentials: { - username: process.env.E2E_AUTH_USERNAME, - password: process.env.E2E_AUTH_PW, - }, }, /* Configure projects for major browsers */ @@ -80,7 +77,7 @@ const config = { products: {simple, virtual}, }, }, - //product:paypal + //product:paypal { name: 'product-paypal', testMatch: '**/Product/**', @@ -90,24 +87,22 @@ const config = { products: {simple, virtual}, }, }, - //settings simple + //settings simple { name: 'simple-settings', - testIgnore: ['**/Cart/**', '**/Product/**', '**/Transaction/**'], + testMatch: '**/Settings/GeneralSettings.spec.js', use: { ...devices['Desktop Chrome'], - gateways: banktransfer, - products: simple, + gateways: {banktransfer}, + products: {simple}, }, }, - // full settings:all gw, all browsers + // full settings:all gw, all browsers { name: 'full-settings', - testIgnore: ['**/Cart/**', '**/Product/**', '**/Transaction/**'], + testMatch: '**/Settings/PaymentSettingsCheckout.classic.spec.js', use: { - ...devices['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari'], - gateways: {banktransfer, paypal}, - products: simple, + ...devices['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari'] }, }, //full transaction:all gw, all products, all browsers diff --git a/tests/e2e/Cart/PayPalButtonCart.block.spec.js b/tests/e2e/Cart/PayPalButtonCart.block.spec.js index a3b8913a9..5538d74f1 100644 --- a/tests/e2e/Cart/PayPalButtonCart.block.spec.js +++ b/tests/e2e/Cart/PayPalButtonCart.block.spec.js @@ -1,44 +1,26 @@ // @ts-check -const { test, expect } = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); -const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const { expect } = require('@playwright/test'); +const { test } = require('../Shared/base-test'); +const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); const {addProductToCart} = require('../Shared/wooUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); -const GATEWAYS = { - 'paypal':{ - 'title':'PayPal', - - } -} -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - }, - 'virtual': { - 'name': 'virtual_no_down', - 'price': '20,25€' - } -} - - -test.describe('PayPal Transaction in block cart', () => { - test.beforeAll(async ({browser }) => { - const page = await browser.newPage(); - await loginAdmin(page); - - }); - test('Not be seen if not enabled', async ({ page }) => { - // Go to shop - await addProductToCart(page, PRODUCTS.virtual.name); +test.describe('PayPal Transaction in classic cart', () => { + test('Not be seen if not enabled', async ({page, products}) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').uncheck(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + await addProductToCart(page, products.virtual.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); //remove from cart - await page.locator('.product-remove').click(); + await page.locator('text=Remove item').click(); }); - test('Not be seen if not virtual', async ({ page }) => { + test('Not be seen if not virtual', async ({page, products}) => { // set PayPal visible in cart await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); @@ -46,36 +28,34 @@ test.describe('PayPal Transaction in block cart', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - await addProductToCart(page, PRODUCTS.simple.name); + await addProductToCart(page, products.simple.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); //remove from cart - await page.locator('.product-remove').click(); + await page.locator('text=Remove item').click(); }); - test('Transaction with Order API - virtual product', async ({ page }) => { - let testedGateway = GATEWAYS.paypal - await loginAdmin(page); - await setOrderAPI(page); - await addProductToCart(page, PRODUCTS.virtual.name); - //go to cart and click - await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); - await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), - page.locator('input[alt="PayPal Button"]').click() - ]); - - // IN MOLLIE - // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + test('Transaction with Order API - virtual product', async ({page, gateways, products}) => { + let testedGateway = gateways + await setOrderAPI(page); + await addProductToCart(page, products.virtual.name); + //go to cart and click + await page.goto(process.env.E2E_URL_TESTSITE + '/cart-block/'); + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('div.wp-block-woocommerce-cart-order-summary-block > div:nth-child(4) > div > span.wc-block-formatted-money-amount.wc-block-components-formatted-money-amount.wc-block-components-totals-item__value'); + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); - // WOOCOMMERCE ORDER PAID PAGE - await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); - // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); - }); + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); + }); }); diff --git a/tests/e2e/Cart/PayPalButtonCart.classic.spec.js b/tests/e2e/Cart/PayPalButtonCart.classic.spec.js index 66ae839cb..713bfc9a3 100644 --- a/tests/e2e/Cart/PayPalButtonCart.classic.spec.js +++ b/tests/e2e/Cart/PayPalButtonCart.classic.spec.js @@ -1,42 +1,26 @@ // @ts-check -const { test, expect } = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); -const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const { expect } = require('@playwright/test'); +const { test } = require('../Shared/base-test'); +const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); const {addProductToCart} = require('../Shared/wooUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); -const GATEWAYS = { - 'paypal':{ - 'title':'PayPal', - - } -} -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - }, - 'virtual': { - 'name': 'virtual_no_down', - 'price': '20,25€' - } -} - test.describe('PayPal Transaction in classic cart', () => { - test.beforeAll(async ({browser }) => { - const page = await browser.newPage(); - await loginAdmin(page); - - }); - test('Not be seen if not enabled', async ({ page }) => { - await addProductToCart(page, PRODUCTS.virtual.name); + test('Not be seen if not enabled', async ({page, products}) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').uncheck(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + await addProductToCart(page, products.virtual.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); //remove from cart - await page.locator('.product-remove').click(); + await page.locator('tr.woocommerce-cart-form__cart-item.cart_item > td.product-remove > a').click(); }); - test('Not be seen if not virtual', async ({ page }) => { + test('Not be seen if not virtual', async ({page, products}) => { // set PayPal visible in cart await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); @@ -44,35 +28,35 @@ test.describe('PayPal Transaction in classic cart', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - await addProductToCart(page, PRODUCTS.simple.name); + await addProductToCart(page, products.simple.name); //go to cart and not see await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); //remove from cart - await page.locator('.product-remove').click(); + await page.locator('tr.woocommerce-cart-form__cart-item.cart_item > td.product-remove > a').click(); }); - test('Transaction with Order API - virtual product', async ({ page }) => { - let testedGateway = GATEWAYS.paypal - await loginAdmin(page); - await setOrderAPI(page); - await addProductToCart(page, PRODUCTS.virtual.name); - //go to cart and click - await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), - page.locator('input[alt="PayPal Button"]').click() - ]); + test('Transaction with Order API - virtual product', async ({page, gateways, products}) => { + let testedGateway = gateways + await setOrderAPI(page); + await addProductToCart(page, products.virtual.name); + //go to cart and click + await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); - // IN MOLLIE - // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markPaidInMollie(page); - // WOOCOMMERCE ORDER PAID PAGE - await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); - // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); - }); + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); + }); }); diff --git a/tests/e2e/Product/PayPalButtonProduct.classic.spec.js b/tests/e2e/Product/PayPalButtonProduct.classic.spec.js index 2901cba39..52ae945dd 100644 --- a/tests/e2e/Product/PayPalButtonProduct.classic.spec.js +++ b/tests/e2e/Product/PayPalButtonProduct.classic.spec.js @@ -1,66 +1,53 @@ // @ts-check -const { test, expect } = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); +const { expect } = require('@playwright/test'); +const { test } = require('../Shared/base-test'); const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); - -const GATEWAYS = { - 'paypal':{ - 'title':'PayPal', - - } -} -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - }, - 'virtual': { - 'name': 'virtual_no_down', - 'price': '20,25€' - } -} - - test.describe('PayPal Transaction in classic product', () => { - test.beforeAll(async ({browser }) => { - const page = await browser.newPage(); - await loginAdmin(page); - - }); test('Not be seen if not enabled', async ({ page }) => { - // Go to virtual product page - await page.goto(process.env.E2E_URL_TESTSITE + '/product/virtual_no_down/'); + // Go to virtual product product + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_product"]').uncheck(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + await page.goto(process.env.E2E_URL_TESTSITE + '/product/album/'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); - }); test('Not be seen if not virtual', async ({ page }) => { - // set PayPal visible in cart + // set PayPal visible in product await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); - await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_product"]').check(); await Promise.all([ page.waitForNavigation(), page.locator('text=Save changes').click() ]); // Go to simple product - await page.goto(process.env.E2E_URL_TESTSITE + '/product/simple_taxes'); + await page.goto(process.env.E2E_URL_TESTSITE + '/product/beanie'); await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); }); - test('Transaction with Order API - virtual product', async ({ page }) => { - let testedGateway = GATEWAYS.paypal; - await loginAdmin(page); - await setOrderAPI(page); + test('Transaction with Order API - virtual product', async ({ page, gateways, products }) => { + let testedGateway = gateways; + await setOrderAPI(page); + // set PayPal visible in product + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); + await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_product"]').check(); + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); // Go to virtual product page - await page.goto(process.env.E2E_URL_TESTSITE + '/product/virtual_no_down/'); + await page.goto(process.env.E2E_URL_TESTSITE + '/product/album/'); - await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); - //Capture WooCommerce total amount - const totalAmount = PRODUCTS.virtual.price - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), - page.locator('input[alt="PayPal Button"]').click() - ]); + await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); + //Capture WooCommerce total amount + const totalAmount = products.virtual.price + await Promise.all([ + page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.locator('input[alt="PayPal Button"]').click() + ]); // IN MOLLIE // Capture order number in Mollie and mark as paid @@ -71,5 +58,5 @@ test.describe('PayPal Transaction in classic product', () => { // WOOCOMMERCE ORDER PAGE await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); - }); + }); }); diff --git a/tests/e2e/Settings/GeneralSettings.spec.js b/tests/e2e/Settings/GeneralSettings.spec.js new file mode 100644 index 000000000..be2d92f69 --- /dev/null +++ b/tests/e2e/Settings/GeneralSettings.spec.js @@ -0,0 +1,33 @@ +// @ts-check +const { expect } = require('@playwright/test'); +const { test } = require('../Shared/base-test'); +const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); + +test.describe('Should show general settings', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await resetSettings(page); + }); + test('Should show empty and disconnected', async ({ page , gateways}) => { + // Go to settings + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); + await expect(page.locator('text=No API key provided. Please set your Mollie API keys below.')).toBeVisible(); + for ( const gatewayName in gateways ){ + //check default icon with a locator that has disabled and activate + const title = gateways[gatewayName].defaultTitle + const id = gateways[gatewayName].id + const url = await page.$eval(`text=${title} disabled activate >> img`, img => img.src); + await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${id}.svg`) + } + }); + test('Should connect when API key is present', async ({ page , gateways}) => { + // Go to settings + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); + await insertAPIKeys(page); + await expect(page.locator('text=Mollie status: Connected')).toBeVisible(); + for ( const gatewayName in gateways ){ + const title = gateways[gatewayName].defaultTitle + await expect(page.locator(`text=${title} enabled edit >> span`)).toBeVisible(); + } + }); +}); diff --git a/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js b/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js index ee1e3b16e..1c31bbee2 100644 --- a/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js +++ b/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js @@ -1,38 +1,16 @@ // @ts-check -const { test, expect } = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); +const {expect} = require('@playwright/test'); +const {test} = require('../Shared/base-test'); const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); - -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } - } -const GATEWAYS = { - 'banktransfer': { - 'id' : 'banktransfer', - 'defaultTitle' : 'Bank Transfer', - 'settingsDescription' : '', - 'defaultDescription' : '', - 'paymentFields' : false, - 'instructions' : true, - 'supports' : [ - 'products', - 'refunds', - ], - 'filtersOnBuild' : true, - 'confirmationDelayed' : true, - 'SEPA' : false, - 'customRedirect' : true, - } -} +const {simple} = require('../Shared/products'); +const {banktransfer, paypal} = require('../Shared/gateways'); +const PRODUCTS = {simple} +const GATEWAYS = {banktransfer, paypal} test.describe('Should show payment settings on classic checkout', () => { - test.beforeAll(async ({browser }) => { + + test.beforeAll(async ({browser}) => { const page = await browser.newPage(); - //login as Admin - await loginAdmin(page); await resetSettings(page); await insertAPIKeys(page); // Go to shop @@ -41,8 +19,8 @@ test.describe('Should show payment settings on classic checkout', () => { const productCartButton = PRODUCTS.simple.name; await page.locator('[data-product_sku="' + productCartButton + '"]').click(); }); - for ( const key in GATEWAYS){ - test(`Should show ${key} default settings`, async ({ page }) => { + for (const key in GATEWAYS) { + test(`Should show ${key} default settings`, async ({page}) => { // Go to checkout await page.goto(process.env.E2E_URL_TESTSITE + '/checkout'); let testedGateway = GATEWAYS[key] @@ -55,61 +33,59 @@ test.describe('Should show payment settings on classic checkout', () => { //check default description await expect(page.locator('#payment')).toContainText(testedGateway.defaultDescription); //check issuers dropdown show - if(testedGateway.paymentFields){ + if (testedGateway.paymentFields) { let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) await expect(issuers).toContainText(testedGateway.defaultDescription) } //no fee added await expect(page.locator('#order_review')).not.toContainText('Fee') - }); + }); }// end loop gateways - for ( const key in GATEWAYS){ - test(`Should show ${key} custom settings`, async ({ page }) => { - let testedGateway = GATEWAYS[key] - await loginAdmin(page); - //set custom settings - await page.goto(`${process.env.E2E_URL_TESTSITE}/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_${testedGateway.id}`) - await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_title"]`).fill(`${testedGateway.defaultTitle} edited`); - await page.locator(`textarea[name="mollie_wc_gateway_${testedGateway.id}_description"]`).fill(`${testedGateway.defaultTitle} description edited`); - await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_display_logo"]`).uncheck(); - //await page.locator(`#mainform > table:nth-child(9) > tbody > tr > td > span.select2.select2-container.select2-container--default > span.selection > span > ul > li > input`).click(); - await page.locator('[placeholder="Choose countries…"]').click(); - await page.locator('[placeholder="Choose countries…"]').fill('spa'); - await page.locator('li[role="option"]:has-text("Spain")').click(); - await page.locator(`select[name="mollie_wc_gateway_${testedGateway.id}_payment_surcharge"]`).selectOption('fixed_fee'); - await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_fixed_fee"]`).fill('10'); - if(testedGateway.paymentFields){ - await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_issuers_dropdown_shown"]`).uncheck(); - } - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); - // Go to checkout - await page.goto(process.env.E2E_URL_TESTSITE + '/checkout'); - - //check custom title - await page.locator(`select[name="billing_country"]`).selectOption('ES'); - await page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`).click() - await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).toContainText(`${testedGateway.defaultTitle} edited`); - //check not display logo - await expect(page.locator(`text=${testedGateway.defaultTitle} >> img`)).toBeFalsy - //check custom description - await expect(page.locator('#payment')).toContainText(`${testedGateway.defaultTitle} description edited`); - //check issuers dropdown not show - if(testedGateway.paymentFields){ - let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) - await expect(issuers).toBeEmpty - } - //check fee added - await expect(page.locator('#order_review')).toContainText('Fee') - //check not sell to countries - await page.locator(`select[name="billing_country"]`).selectOption('DE'); - await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).not.toBeVisible(); - await page.locator(`select[name="billing_country"]`).selectOption('ES'); + for (const key in GATEWAYS) { + test(`Should show ${key} custom settings`, async ({page}) => { + let testedGateway = GATEWAYS[key] + //set custom settings + await page.goto(`${process.env.E2E_URL_TESTSITE}/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_${testedGateway.id}`) + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_title"]`).fill(`${testedGateway.defaultTitle} edited`); + await page.locator(`textarea[name="mollie_wc_gateway_${testedGateway.id}_description"]`).fill(`${testedGateway.defaultTitle} description edited`); + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_display_logo"]`).uncheck(); + //await page.locator(`#mainform > table:nth-child(9) > tbody > tr > td > span.select2.select2-container.select2-container--default > span.selection > span > ul > li > input`).click(); + await page.locator('[placeholder="Choose countries…"]').click(); + await page.locator('[placeholder="Choose countries…"]').fill('spa'); + await page.locator('li[role="option"]:has-text("Spain")').click(); + await page.locator(`select[name="mollie_wc_gateway_${testedGateway.id}_payment_surcharge"]`).selectOption('fixed_fee'); + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_fixed_fee"]`).fill('10'); + if (testedGateway.paymentFields) { + await page.locator(`input[name="mollie_wc_gateway_${testedGateway.id}_issuers_dropdown_shown"]`).uncheck(); + } + await Promise.all([ + page.waitForNavigation(), + page.locator('text=Save changes').click() + ]); + // Go to checkout + await page.goto(process.env.E2E_URL_TESTSITE + '/checkout'); + //check custom title + await page.locator(`select[name="billing_country"]`).selectOption('ES'); + await page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`).click() + await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).toContainText(`${testedGateway.defaultTitle} edited`); + //check not display logo + await expect(page.locator(`text=${testedGateway.defaultTitle} >> img`)).toBeFalsy + //check custom description + await expect(page.locator('#payment')).toContainText(`${testedGateway.defaultTitle} description edited`); + //check issuers dropdown not show + if (testedGateway.paymentFields) { + let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) + await expect(issuers).toBeEmpty + } + //check fee added + await expect(page.locator('#order_review')).toContainText('Fee') + //check not sell to countries + await page.locator(`select[name="billing_country"]`).selectOption('DE'); + await expect(page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > label`)).not.toBeVisible(); + await page.locator(`select[name="billing_country"]`).selectOption('ES'); }); - }// end loop gateways + }// end loop gateways }); diff --git a/tests/e2e/Settings/generalSettings.spec.js b/tests/e2e/Settings/generalSettings.spec.js deleted file mode 100644 index 8c13c1684..000000000 --- a/tests/e2e/Settings/generalSettings.spec.js +++ /dev/null @@ -1,52 +0,0 @@ -// @ts-check -const { expect } = require('@playwright/test'); -const { test } = require('../Shared/base-test'); - -const { loginAdmin } = require('../Shared/wpUtils'); -const {insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); - -test.describe('Should show general settings', () => { - test.beforeAll(async ({browser }) => { - const page = await browser.newPage(); - //login as Admin - await loginAdmin(page); - await resetSettings(page); - await insertAPIKeys(page); - }); - test('Should show empty and disconnected', async ({ page , gateways}) => { - // Go to settings - await loginAdmin(page); - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion'); - await expect(page.locator('text=No API key provided. Please set your Mollie API keys below.')).toBeVisible(); - - for ( const key in gateways ){ - let testedGateway = gateways[key] - //check default icon with a locator that has disabled and activate - const url = await page.$eval(`text=${testedGateway.defaultTitle} disabled activate >> img`, img => img.src); - await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${testedGateway.id}.svg`) - } - //fill with API keys - await page.locator('[placeholder="Live API key should start with live_"]').fill('live_HFGW8amkfcb7dvrasy8WdUNRNhscxa'); - await page.locator('input[name="mollie-payments-for-woocommerce_test_mode_enabled"]').check(); - await page.locator('[placeholder="Test API key should start with test_"]').fill('test_NgHd7vSyPSpEyuTEwhvsxdjsgVG4SV'); - // Click text=Save changes - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://cmaymo.emp.pluginpsyde.com/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion' }*/), - page.locator('text=Save changes').click() - ]); - await expect(page.locator('text=Mollie status: Connected')).toBeVisible(); - for ( const key in gateways ){ - let testedGateway = gateways[key] - await expect(page.locator(`text=${testedGateway.defaultTitle} enabled edit >> span`)).toBeVisible(); - } - }); -}); - - - - - - - - - diff --git a/tests/e2e/Shared/gateways.js b/tests/e2e/Shared/gateways.js index 060b9435a..7116da626 100644 --- a/tests/e2e/Shared/gateways.js +++ b/tests/e2e/Shared/gateways.js @@ -32,7 +32,18 @@ const creditcard = { 'defaultTitle': 'Credit card', } const paypal = { - 'id': 'paypal', - 'defaultTitle': 'PayPal', + 'id' : 'paypal', + 'defaultTitle' : 'PayPal', + 'settingsDescription' : '', + 'defaultDescription' : '', + 'paymentFields' : false, + 'instructions' : true, + 'supports' : [ + 'products', + 'refunds', + ], + 'filtersOnBuild' : false, + 'confirmationDelayed' : false, + 'SEPA' : false, } module.exports = {banktransfer, ideal, creditcard, paypal}; diff --git a/tests/e2e/Shared/global-setup.js b/tests/e2e/Shared/global-setup.js new file mode 100644 index 000000000..df369fea8 --- /dev/null +++ b/tests/e2e/Shared/global-setup.js @@ -0,0 +1,10 @@ +const { chromium } = require('@playwright/test'); +const { loginAdmin } = require('./wpUtils'); + +module.exports = async config => { + const browser = await chromium.launch(); + const page = await browser.newPage(); + await loginAdmin(page); + await page.context().storageState({ path: 'storageState.json' }); + await browser.close(); +}; diff --git a/tests/e2e/Shared/products.js b/tests/e2e/Shared/products.js index f5af42a9a..f0d14c89b 100644 --- a/tests/e2e/Shared/products.js +++ b/tests/e2e/Shared/products.js @@ -1,14 +1,10 @@ const simple = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } + 'name': 'woo-beanie', + 'price': '18,00€' } const virtual = { - 'virtual': { - 'name': 'virtual_no_down', - 'price': '20,25€' - } + 'name': 'woo-album', + 'price': '15,00€' } diff --git a/tests/e2e/Shared/wpUtils.js b/tests/e2e/Shared/wpUtils.js index f3952174a..1a48d38bc 100644 --- a/tests/e2e/Shared/wpUtils.js +++ b/tests/e2e/Shared/wpUtils.js @@ -2,6 +2,7 @@ const loginAdmin = async (page)=>{ await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); + await page.locator('#user_login').fill(process.env.ADMIN_USER); await page.locator('#user_pass').fill(process.env.ADMIN_PASS); await Promise.all([ page.waitForNavigation(), diff --git a/tests/e2e/Transaction/Checkout.classic.spec.js b/tests/e2e/Transaction/Checkout.classic.spec.js index 11531f270..75777a99a 100644 --- a/tests/e2e/Transaction/Checkout.classic.spec.js +++ b/tests/e2e/Transaction/Checkout.classic.spec.js @@ -1,21 +1,9 @@ // @ts-check -const {test, expect} = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); +const {expect} = require('@playwright/test'); +const {test} = require('../Shared/base-test'); const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInCheckout} = require('../Shared/wooUtils'); -const GATEWAYS = { - 'banktransfer': { - 'title': 'Bank Transfer', - - } -} -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } -} /** * @param {import('@playwright/test').Page} page @@ -117,30 +105,23 @@ async function classicCheckoutExpiredTransaction(page, testedProduct, testedGate } test.describe('Transaction in classic checkout', () => { - test('Transaction with Order API paid', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Order API paid', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API failed', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Order API failed', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutFailedTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutFailedTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API cancelled setting as pending', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Order API cancelled setting as pending', async ({page, products, gateways}) => { await setOrderAPI(page); //setting as pending await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); @@ -149,16 +130,13 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutCancelledTransactionPending(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API cancelled setting as cancelled', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Order API cancelled setting as cancelled', async ({page, products, gateways}) => { await setOrderAPI(page); //setting as cancelled await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); @@ -167,63 +145,46 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutCancelledTransactionCancelled(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction full refund Order', async ({page}) => { - await loginAdmin(page); + test('Transaction classic full refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransactionFullRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction partial refund Order', async ({page}) => { - await loginAdmin(page); + test('Transaction classic partial refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransactionPartialRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API expired', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Order API expired', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutExpiredTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutExpiredTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API paid', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction classic with Payment API paid', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API cancelled setting as pending', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction classic with Payment API cancelled setting as pending', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); //setting as pending @@ -232,17 +193,13 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutCancelledTransactionPending(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API cancelled setting as cancelled', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction classic with Payment API cancelled setting as cancelled', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); //setting as cancelled @@ -251,44 +208,33 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutCancelledTransactionCancelled(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction full refund Payment', async ({page}) => { - await loginAdmin(page); + test('Transaction classic full refund Payment', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransactionFullRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction partial refund Payment', async ({page}) => { - await loginAdmin(page); + test('Transaction classic partial refund Payment', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutPaidTransactionPartialRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API expired', async ({page}) => { - await loginAdmin(page); + test('Transaction classic with Payment API expired', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await classicCheckoutExpiredTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await classicCheckoutExpiredTransaction(page, product, gateway); }// end loop products }// end loop gateways }); From 1f5d4eff448ee4d68c96e2ffa49906478e08d1d8 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 30 May 2022 08:28:58 +0200 Subject: [PATCH 008/100] correct tests --- .ddev/config.yaml | 4 +- playwright.config.js | 8 +- tests/e2e/Shared/global-setup.js | 5 +- tests/e2e/Shared/mollieUtils.js | 7 +- tests/e2e/Shared/testMollieInWooPage.js | 11 +- tests/e2e/Shared/wpUtils.js | 2 - tests/e2e/Transaction/Checkout.block.spec.js | 170 ++++++------------ .../e2e/Transaction/Checkout.classic.spec.js | 84 +++------ 8 files changed, 110 insertions(+), 181 deletions(-) diff --git a/.ddev/config.yaml b/.ddev/config.yaml index 43d66e43c..6e41c5712 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -3,7 +3,7 @@ type: php docroot: .ddev/wordpress php_version: "7.4" webserver_type: nginx-fpm -router_http_port: "80" +router_http_port: "86" router_https_port: "443" xdebug_enabled: false additional_hostnames: [] @@ -95,7 +95,7 @@ hooks: # Please take care with this because it can cause great confusion. # upload_dir: custom/upload/dir -# would set the destination path for ddev import-files to /custom/upload/dir +# would set the destination path for ddev import-files to /custom/upload/dir # working_dir: # web: /var/www/html diff --git a/playwright.config.js b/playwright.config.js index 5aec952a6..22c288a23 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -11,8 +11,10 @@ const {banktransfer, paypal} = require('./tests/e2e/Shared/gateways'); /** * @see https://playwright.dev/docs/test-configuration - * @type {import('@playwright/test').PlaywrightTestConfig} + * + * @type {import('@playwright/test').PlaywrightTestConfig<{ products: Object, gateways: Object }>} */ + const config = { testDir: './tests/e2e', /* Maximum time one test can run for. */ @@ -31,7 +33,9 @@ const config = { /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', + reporter: [ + [process.env.CI ? 'github' : 'list'], + ['junit', { outputFile: './tests/e2e/Reports/results.xml' }]], globalSetup: require.resolve('./tests/e2e/Shared/global-setup'), /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { diff --git a/tests/e2e/Shared/global-setup.js b/tests/e2e/Shared/global-setup.js index df369fea8..7c63fd21c 100644 --- a/tests/e2e/Shared/global-setup.js +++ b/tests/e2e/Shared/global-setup.js @@ -1,10 +1,11 @@ const { chromium } = require('@playwright/test'); -const { loginAdmin } = require('./wpUtils'); +const { loginAdmin } = require('../Shared/wpUtils'); module.exports = async config => { + const { storageState } = config.projects[0].use; const browser = await chromium.launch(); const page = await browser.newPage(); await loginAdmin(page); - await page.context().storageState({ path: 'storageState.json' }); + await page.context().storageState({ path: storageState }); await browser.close(); }; diff --git a/tests/e2e/Shared/mollieUtils.js b/tests/e2e/Shared/mollieUtils.js index 6ca7ab4c2..41b87422c 100644 --- a/tests/e2e/Shared/mollieUtils.js +++ b/tests/e2e/Shared/mollieUtils.js @@ -24,11 +24,12 @@ const setPaymentAPI = async (page) => { /** * @param {import('@playwright/test').Page} page + * @param status */ -const markPaidInMollie = async (page) =>{ +const markStatusInMollie = async (page, status) =>{ const mollieHeader = await page.innerText('.header__info'); const mollieOrder = mollieHeader.substring(6, mollieHeader.length) - await page.locator('text=Paid').click(); + await page.locator('text=' + status).click(); await page.locator('text=Continue').click(); return mollieOrder; } @@ -58,4 +59,4 @@ const resetSettings = async (page) => { ]); } -module.exports = {setOrderAPI, setPaymentAPI, markPaidInMollie, insertAPIKeys, resetSettings}; +module.exports = {setOrderAPI, setPaymentAPI, markStatusInMollie, insertAPIKeys, resetSettings}; diff --git a/tests/e2e/Shared/testMollieInWooPage.js b/tests/e2e/Shared/testMollieInWooPage.js index f5047590a..f4cb243e1 100644 --- a/tests/e2e/Shared/testMollieInWooPage.js +++ b/tests/e2e/Shared/testMollieInWooPage.js @@ -1,3 +1,5 @@ +const { expect } = require('@playwright/test'); + const wooOrderPaidPage = async (page, mollieOrder, totalAmount, testedGateway) => { // Check order number await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); @@ -9,6 +11,13 @@ const wooOrderPaidPage = async (page, mollieOrder, totalAmount, testedGateway) = await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); } +const wooOrderRetryPage = async (page, mollieOrder, totalAmount, testedGateway) => { + // Check we are in retry page + const regex = new RegExp(`${process.env.E2E_URL_TESTSITE}/checkout/order-pay/${mollieOrder}.`); + await expect(page).toHaveURL(regex); + +} + const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); // Check order is in status processing in order page @@ -19,4 +28,4 @@ const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); } -module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid} +module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage} diff --git a/tests/e2e/Shared/wpUtils.js b/tests/e2e/Shared/wpUtils.js index 1a48d38bc..838d19a15 100644 --- a/tests/e2e/Shared/wpUtils.js +++ b/tests/e2e/Shared/wpUtils.js @@ -1,5 +1,3 @@ - - const loginAdmin = async (page)=>{ await page.goto(process.env.E2E_URL_TESTSITE + '/wp-login.php'); await page.locator('#user_login').fill(process.env.ADMIN_USER); diff --git a/tests/e2e/Transaction/Checkout.block.spec.js b/tests/e2e/Transaction/Checkout.block.spec.js index de925d70b..9b30eab9c 100644 --- a/tests/e2e/Transaction/Checkout.block.spec.js +++ b/tests/e2e/Transaction/Checkout.block.spec.js @@ -1,26 +1,10 @@ // @ts-check -const {test, expect} = require('@playwright/test'); -const { loginAdmin } = require('../Shared/wpUtils'); +const {expect} = require('@playwright/test'); +const { test } = require('../Shared/base-test'); const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInBlockCheckout} = require('../Shared/wooUtils'); -const GATEWAYS = { - 'banktransfer': { - 'title': 'Bank Transfer', - - } -} -const PRODUCTS = { - 'simple': { - 'name': 'simple_taxes', - 'price': '24,33€' - } -} - - - - /** * @param {import('@playwright/test').Page} page * @param testedProduct @@ -34,8 +18,8 @@ async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), await page.locator('text=Checkout').first().click() ]); - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + //Capture WooCommerce total amount const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); @@ -120,31 +104,24 @@ async function blockCheckoutExpiredTransaction(page, testedProduct, testedGatewa } -test.describe('Transaction in classic checkout', () => { - test('Transaction with Order API paid', async ({page}) => { - await loginAdmin(page); +test.describe('Transaction in block checkout', () => { + test('Transaction block with Order API paid', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API failed', async ({page}) => { - await loginAdmin(page); + test('Transaction block with Order API failed', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutFailedTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutFailedTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API cancelled setting as pending', async ({page}) => { - await loginAdmin(page); + test('Transaction block with Order API cancelled setting as pending', async ({page, products, gateways}) => { await setOrderAPI(page); //setting as pending await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); @@ -153,16 +130,13 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutCancelledTransactionPending(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API cancelled setting as cancelled', async ({page}) => { - await loginAdmin(page); + test('Transaction block with Order API cancelled setting as cancelled', async ({page, products, gateways}) => { await setOrderAPI(page); //setting as cancelled await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); @@ -171,63 +145,46 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutCancelledTransactionCancelled(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction full refund Order', async ({page}) => { - await loginAdmin(page); + test('Transaction block full refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransactionFullRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction partial refund Order', async ({page}) => { - await loginAdmin(page); + test('Transaction block partial refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransactionPartialRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Order API expired', async ({page}) => { - await loginAdmin(page); + test('Transaction block with Order API expired', async ({page, products, gateways}) => { await setOrderAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutExpiredTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutExpiredTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API paid', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction block with Payment API paid', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransaction(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API cancelled setting as pending', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction block with Payment API cancelled setting as pending', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); //setting as pending @@ -236,17 +193,13 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutCancelledTransactionPending(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API cancelled setting as cancelled', async ({page}) => { - //login as Admin - await loginAdmin(page); + test('Transaction block with Payment API cancelled setting as cancelled', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); //setting as cancelled @@ -255,44 +208,33 @@ test.describe('Transaction in classic checkout', () => { page.waitForNavigation(), page.locator('text=Save changes').click() ]); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutCancelledTransactionCancelled(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction full refund Payment', async ({page}) => { - await loginAdmin(page); + test('Transaction block full refund Payment', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransactionFullRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction partial refund Payment', async ({page}) => { - await loginAdmin(page); + test('Transaction block partial refund Payment', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutPaidTransactionPartialRefund(page, product, gateway); }// end loop products }// end loop gateways }); - test('Transaction with Payment API expired', async ({page}) => { - await loginAdmin(page); + test('Transaction block with Payment API expired', async ({page, products, gateways}) => { await setPaymentAPI(page); - for (const key in GATEWAYS) { - let testedGateway = GATEWAYS[key] - for (const key in PRODUCTS) { - let testedProduct = PRODUCTS[key] - await blockCheckoutExpiredTransaction(page, testedProduct, testedGateway); + for (const gateway in gateways) { + for (const product in products) { + await blockCheckoutExpiredTransaction(page, product, gateway); }// end loop products }// end loop gateways }); diff --git a/tests/e2e/Transaction/Checkout.classic.spec.js b/tests/e2e/Transaction/Checkout.classic.spec.js index 75777a99a..28d304568 100644 --- a/tests/e2e/Transaction/Checkout.classic.spec.js +++ b/tests/e2e/Transaction/Checkout.classic.spec.js @@ -1,17 +1,12 @@ // @ts-check const {expect} = require('@playwright/test'); const {test} = require('../Shared/base-test'); -const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); +const {setOrderAPI, setPaymentAPI, markStatusInMollie} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInCheckout} = require('../Shared/wooUtils'); -/** - * @param {import('@playwright/test').Page} page - * @param testedProduct - * @param testedGateway - */ -async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway) { - await addProductToCart(page, testedProduct); +async function beforePlacingOrder(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct.name); // Go to checkout await Promise.all([ @@ -19,7 +14,7 @@ async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway await page.locator('text=Checkout').first().click() ]); - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); + await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout'); //Capture WooCommerce total amount const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); @@ -27,16 +22,27 @@ async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway await fillCustomerInCheckout(page); // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); + + await page.locator('#payment_method_mollie_wc_gateway_' + testedGateway.id).check(); // Click text=Place order await Promise.all([ page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), page.locator('text=Place order').click() ]); + return totalAmount; +} + +/** + * @param {import('@playwright/test').Page} page + * @param testedProduct + * @param testedGateway + */ +async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Paid"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); @@ -46,46 +52,33 @@ async function classicCheckoutPaidTransaction(page, testedProduct, testedGateway } async function classicCheckoutFailedTransaction(page, testedProduct, testedGateway) { - await addProductToCart(page, testedProduct); - - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); - - // CUSTOMER DETAILS - await fillCustomerInCheckout(page); - - // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); - // Click text=Place order - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - page.locator('text=Place order').click() - ]); + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markFailedInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Failed"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); + //await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); } async function classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markStatusInMollie(page, "Canceled"); } async function classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markStatusInMollie(page, "Canceled"); } async function classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { @@ -100,9 +93,6 @@ async function classicCheckoutPaidTransactionPartialRefund(page, testedProduct, //refund } -async function classicCheckoutExpiredTransaction(page, testedProduct, testedGateway) { - -} test.describe('Transaction in classic checkout', () => { test('Transaction classic with Order API paid', async ({page, products, gateways}) => { @@ -167,14 +157,6 @@ test.describe('Transaction in classic checkout', () => { }// end loop products }// end loop gateways }); - test('Transaction classic with Order API expired', async ({page, products, gateways}) => { - await setOrderAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await classicCheckoutExpiredTransaction(page, product, gateway); - }// end loop products - }// end loop gateways - }); test('Transaction classic with Payment API paid', async ({page, products, gateways}) => { //Set Payment API await setPaymentAPI(page); @@ -230,12 +212,4 @@ test.describe('Transaction in classic checkout', () => { }// end loop products }// end loop gateways }); - test('Transaction classic with Payment API expired', async ({page, products, gateways}) => { - await setPaymentAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await classicCheckoutExpiredTransaction(page, product, gateway); - }// end loop products - }// end loop gateways - }); }); From 3b67cfaf75704aa40461d4a373d65d1c399f946b Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 13 Jun 2022 09:03:41 +0200 Subject: [PATCH 009/100] add woo orchestration and update tests --- .ddev/cart-block.txt | 51 +++++++++++ .ddev/checkout-block.txt | 45 ++++++++++ .../{50_woocommerce.sh => 30_woocommerce.sh} | 0 ...products.sh => 31_woocommerce_products.sh} | 0 .../orchestrate.d/32_woocommerce_blocks.sh | 3 + .../orchestrate.d/33_woocommerce_config.sh | 15 ++++ .../34_woocommerce_classic_pages.sh | 3 + .../35_woocommerce_block_pages.sh | 4 + ...kages.sh => 40_install_plugin_packages.sh} | 0 .../orchestrate.d/40_setup_and_activate.sh | 5 -- .../orchestrate.d/41_setup_and_activate.sh | 5 ++ .idea/php-test-framework.xml | 3 +- .idea/php.xml | 2 +- package.json | 2 +- playwright.config.js | 16 ++-- tests/e2e/Shared/testMollieInWooPage.js | 25 ++++-- tests/e2e/Shared/wooUtils.js | 14 +-- .../e2e/Transaction/Checkout.classic.spec.js | 88 ++++++++++++------- 18 files changed, 219 insertions(+), 62 deletions(-) create mode 100644 .ddev/cart-block.txt create mode 100644 .ddev/checkout-block.txt rename .ddev/commands/web/orchestrate.d/{50_woocommerce.sh => 30_woocommerce.sh} (100%) rename .ddev/commands/web/orchestrate.d/{51_woocommerce_products.sh => 31_woocommerce_products.sh} (100%) create mode 100644 .ddev/commands/web/orchestrate.d/32_woocommerce_blocks.sh create mode 100644 .ddev/commands/web/orchestrate.d/33_woocommerce_config.sh create mode 100644 .ddev/commands/web/orchestrate.d/34_woocommerce_classic_pages.sh create mode 100644 .ddev/commands/web/orchestrate.d/35_woocommerce_block_pages.sh rename .ddev/commands/web/orchestrate.d/{30_install_plugin_packages.sh => 40_install_plugin_packages.sh} (100%) delete mode 100644 .ddev/commands/web/orchestrate.d/40_setup_and_activate.sh create mode 100644 .ddev/commands/web/orchestrate.d/41_setup_and_activate.sh diff --git a/.ddev/cart-block.txt b/.ddev/cart-block.txt new file mode 100644 index 000000000..ef46ba325 --- /dev/null +++ b/.ddev/cart-block.txt @@ -0,0 +1,51 @@ + +
+
+
+
+
+ + + +
+
+ + + +
+ + + +
+ + + +
+
+
+ + + +
+
+ + + +

Your cart is currently empty!

+ + + +

Browse store.

+ + + +
+ + + +

New in store

+ + +
+
+ diff --git a/.ddev/checkout-block.txt b/.ddev/checkout-block.txt new file mode 100644 index 000000000..ef672eea4 --- /dev/null +++ b/.ddev/checkout-block.txt @@ -0,0 +1,45 @@ + +
+
+
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+ + + +
+
+
+
+ diff --git a/.ddev/commands/web/orchestrate.d/50_woocommerce.sh b/.ddev/commands/web/orchestrate.d/30_woocommerce.sh similarity index 100% rename from .ddev/commands/web/orchestrate.d/50_woocommerce.sh rename to .ddev/commands/web/orchestrate.d/30_woocommerce.sh diff --git a/.ddev/commands/web/orchestrate.d/51_woocommerce_products.sh b/.ddev/commands/web/orchestrate.d/31_woocommerce_products.sh similarity index 100% rename from .ddev/commands/web/orchestrate.d/51_woocommerce_products.sh rename to .ddev/commands/web/orchestrate.d/31_woocommerce_products.sh diff --git a/.ddev/commands/web/orchestrate.d/32_woocommerce_blocks.sh b/.ddev/commands/web/orchestrate.d/32_woocommerce_blocks.sh new file mode 100644 index 000000000..906620c9d --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/32_woocommerce_blocks.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wp plugin install woo-gutenberg-products-block --activate diff --git a/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh b/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh new file mode 100644 index 000000000..bbc778c03 --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +#activate tax setting +wp option set woocommerce_calc_taxes "yes" +#create tax +wp wc tax create --rate=10 --name="Standard tax" --priority=1 --compound=0 --shipping=1 --user="admin" + +#euro +wp option set woocommerce_currency "EUR" + +#store address +wp option set woocommerce_store_address "Calle Drutal" +wp option set woocommerce_store_address_2 "" +wp option set woocommerce_store_city "Valencia" +wp option set woocommerce_default_country "DE:DE-BE" diff --git a/.ddev/commands/web/orchestrate.d/34_woocommerce_classic_pages.sh b/.ddev/commands/web/orchestrate.d/34_woocommerce_classic_pages.sh new file mode 100644 index 000000000..655e16f40 --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/34_woocommerce_classic_pages.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wp wc tool run install_pages --user="admin" diff --git a/.ddev/commands/web/orchestrate.d/35_woocommerce_block_pages.sh b/.ddev/commands/web/orchestrate.d/35_woocommerce_block_pages.sh new file mode 100644 index 000000000..2a5b6e826 --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/35_woocommerce_block_pages.sh @@ -0,0 +1,4 @@ +#!/bin/bash + + wp post create ../checkout-block.txt --post_title='checkout-block' --post_type=page --post_status=publish + wp post create ../cart-block.txt --post_title='cart-block' --post_type=page --post_status=publish diff --git a/.ddev/commands/web/orchestrate.d/30_install_plugin_packages.sh b/.ddev/commands/web/orchestrate.d/40_install_plugin_packages.sh similarity index 100% rename from .ddev/commands/web/orchestrate.d/30_install_plugin_packages.sh rename to .ddev/commands/web/orchestrate.d/40_install_plugin_packages.sh diff --git a/.ddev/commands/web/orchestrate.d/40_setup_and_activate.sh b/.ddev/commands/web/orchestrate.d/40_setup_and_activate.sh deleted file mode 100644 index fdd06dbfc..000000000 --- a/.ddev/commands/web/orchestrate.d/40_setup_and_activate.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -pushd "${DDEV_DOCROOT}" - -wp plugin activate "${PLUGIN_NAME:-$DDEV_PROJECT}" diff --git a/.ddev/commands/web/orchestrate.d/41_setup_and_activate.sh b/.ddev/commands/web/orchestrate.d/41_setup_and_activate.sh new file mode 100644 index 000000000..f2af3679b --- /dev/null +++ b/.ddev/commands/web/orchestrate.d/41_setup_and_activate.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +pushd "${DDEV_DOCROOT}" + +wp plugin activate "${$DDEV_PROJECT}" diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml index 48151b5a2..11b6887b9 100644 --- a/.idea/php-test-framework.xml +++ b/.idea/php-test-framework.xml @@ -6,10 +6,9 @@ - - \ No newline at end of file + diff --git a/.idea/php.xml b/.idea/php.xml index a52249f5a..bb55fd4a9 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -325,7 +325,7 @@ - + diff --git a/package.json b/package.json index 107e9cd7c..5ecb253af 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "watch": "webpack --watch", "build": "node_modules/.bin/encore dev --env.basePath=.", "setup": "gulp setup", - "e2e-simple": "npx playwright test --project=simple-classic", + "e2e-simple": "npx playwright test -c playwright.config.js --headed --project=simple-classic ", "e2e-block": "npx playwright test --project=simple-block", "e2e-full-transaction": "npx playwright test --project=full-transaction", "e2e-cart-paypal": "npx playwright test --project=cart-paypal", diff --git a/playwright.config.js b/playwright.config.js index 22c288a23..888b4ddfa 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,7 +1,7 @@ // @ts-check const { devices } = require('@playwright/test'); const {simple, virtual} = require('./tests/e2e/Shared/products'); -const {banktransfer, paypal} = require('./tests/e2e/Shared/gateways'); +const {banktransfer, paypal, creditcard} = require('./tests/e2e/Shared/gateways'); /** * Read environment variables from file. * https://github.com/motdotla/dotenv @@ -53,11 +53,11 @@ const config = { //all simple classic:simple prod, simple subs, one gw, one browser, checkout and settings, no buttons { name: 'simple-classic', - testIgnore: ['**/Cart/**','**/Product/**', '**/*.block.spec.js'], + testMatch: ['**/Transaction/Checkout.classic.spec.js'], use: { ...devices['Desktop Chrome'], - gateways: banktransfer, - products: simple, + gateways: {creditcard}, + products: {simple}, }, }, @@ -67,8 +67,8 @@ const config = { testIgnore: ['**/Cart/**','**/Product/**', '**/*.classic.spec.js'], use: { ...devices['Desktop Chrome'], - gateways: banktransfer, - products: simple, + gateways: {creditcard}, + products: {simple}, }, }, //cart :paypal @@ -77,7 +77,7 @@ const config = { testMatch: '**/Cart/**', use: { ...devices['Desktop Chrome'], - gateways: paypal, + gateways: {paypal}, products: {simple, virtual}, }, }, @@ -87,7 +87,7 @@ const config = { testMatch: '**/Product/**', use: { ...devices['Desktop Chrome'], - gateways: paypal, + gateways: {paypal}, products: {simple, virtual}, }, }, diff --git a/tests/e2e/Shared/testMollieInWooPage.js b/tests/e2e/Shared/testMollieInWooPage.js index f4cb243e1..62741b94a 100644 --- a/tests/e2e/Shared/testMollieInWooPage.js +++ b/tests/e2e/Shared/testMollieInWooPage.js @@ -4,11 +4,14 @@ const wooOrderPaidPage = async (page, mollieOrder, totalAmount, testedGateway) = // Check order number await expect(page.locator('li.woocommerce-order-overview__order.order')).toContainText(mollieOrder); // Check total amount in order - await expect(page.locator('li.woocommerce-order-overview__total.total')).toContainText(totalAmount); - // Check customer in billind details - await expect(page.locator('div.woocommerce-column.woocommerce-column--1.woocommerce-column--billing-address.col-1 > address')).toContainText("Test test"); + await expect(page.locator('li.woocommerce-order-overview__total.total > strong > span > bdi')).toContainText(totalAmount); + + if(testedGateway.id !== 'paypal'){ + // Check customer in billing details + await expect(page.locator('section.woocommerce-customer-details > address')).toContainText("Julia Callas"); + } // Check Mollie method appears - await expect(page.locator('li.woocommerce-order-overview__payment-method.method')).toContainText(testedGateway.title); + await expect(page.locator('li.woocommerce-order-overview__payment-method.method > strong')).toContainText(testedGateway.defaultTitle); } const wooOrderRetryPage = async (page, mollieOrder, totalAmount, testedGateway) => { @@ -25,7 +28,17 @@ const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); // Check order notes has correct text - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.title + ' payment'); + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.defaultTitle + ' payment'); +} + +const wooOrderDetailsPageOnFailed = async (page, mollieOrder, testedGateway) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Pending payment"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText(testedGateway.id + ' payment started'); } -module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage} +module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed} diff --git a/tests/e2e/Shared/wooUtils.js b/tests/e2e/Shared/wooUtils.js index f94e81a7c..441342f65 100644 --- a/tests/e2e/Shared/wooUtils.js +++ b/tests/e2e/Shared/wooUtils.js @@ -6,17 +6,21 @@ const addProductToCart = async (page, testedProductName) => { // Go to shop await page.goto(process.env.E2E_URL_TESTSITE + '/shop/'); // Add product to cart - await page.locator('[data-product_sku="' + testedProductName + '"]').click(); + await page.locator('[data-product_sku="' + testedProductName + '"]').click() } /** * @param {import('@playwright/test').Page} page */ const fillCustomerInCheckout = async (page) => { - // Fill input[name="billing_first_name"] - await page.locator('input[name="billing_first_name"]').fill('Test'); - // Fill input[name="billing_last_name"] - await page.locator('input[name="billing_last_name"]').fill('test'); + await page.locator('input[name="billing_first_name"]').fill('Julia'); + await page.locator('input[name="billing_last_name"]').fill('Callas'); + await page.selectOption('select#billing_country', 'DE'); + await page.locator('input[name="billing_city"]').fill('Berlin'); + await page.locator('input[name="billing_address_1"]').fill('Calle Drutal'); + await page.locator('input[name="billing_postcode"]').fill('22100'); + await page.locator('input[name="billing_phone"]').fill('1234566788'); + await page.locator('input[name="billing_email"]').fill('test@test.com'); } /** diff --git a/tests/e2e/Transaction/Checkout.classic.spec.js b/tests/e2e/Transaction/Checkout.classic.spec.js index 28d304568..4207686e0 100644 --- a/tests/e2e/Transaction/Checkout.classic.spec.js +++ b/tests/e2e/Transaction/Checkout.classic.spec.js @@ -1,20 +1,18 @@ // @ts-check const {expect} = require('@playwright/test'); const {test} = require('../Shared/base-test'); -const {setOrderAPI, setPaymentAPI, markStatusInMollie} = require('../Shared/mollieUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage} = require('../Shared/testMollieInWooPage'); +const {setOrderAPI, setPaymentAPI, markStatusInMollie, insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInCheckout} = require('../Shared/wooUtils'); - +/** + * @param {import('@playwright/test').Page} page + * @param testedProduct + * @param testedGateway + */ async function beforePlacingOrder(page, testedProduct, testedGateway) { await addProductToCart(page, testedProduct.name); + await page.goto(process.env.E2E_URL_TESTSITE + '/checkout/'); - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout'); //Capture WooCommerce total amount const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); @@ -23,7 +21,7 @@ async function beforePlacingOrder(page, testedProduct, testedGateway) { // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('#payment_method_mollie_wc_gateway_' + testedGateway.id).check(); + await page.locator(`text=${testedGateway.defaultTitle}`).click(); // Click text=Place order await Promise.all([ page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), @@ -62,7 +60,7 @@ async function classicCheckoutFailedTransaction(page, testedProduct, testedGatew await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - //await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); } async function classicCheckoutCancelledTransactionPending(page, testedProduct, testedGateway) { @@ -71,6 +69,11 @@ async function classicCheckoutCancelledTransactionPending(page, testedProduct, t // IN MOLLIE // Capture order number in Mollie and mark as paid const mollieOrder = await markStatusInMollie(page, "Canceled"); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); } async function classicCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { @@ -79,27 +82,44 @@ async function classicCheckoutCancelledTransactionCancelled(page, testedProduct, // IN MOLLIE // Capture order number in Mollie and mark as paid const mollieOrder = await markStatusInMollie(page, "Canceled"); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); + + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); } async function classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); - //in order page select quantity - //refund + await page.locator('text=Refund').click(); + await page.locator('input[class="refund_order_item_qty"]').fill(1); + page.on('dialog', dialog => dialog.accept()); + await page.locator('#woocommerce-order-items > div.inside > div.wc-order-data-row.wc-order-refund-items.wc-order-data-row-toggle > div.refund-actions > button.button.button-primary.do-api-refund').click(); + await expect(page.locator('#select2-order_status-container')).toContainText("Refunded"); } async function classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway) { await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); - //in order page select partial amount - //refund + await page.locator('text=Refund').click(); + await page.locator('input[name="#order_line_items > tr > td.line_cost > div.refund > input"]').fill(2); + page.on('dialog', dialog => dialog.accept()); + await page.locator('#woocommerce-order-items > div.inside > div.wc-order-data-row.wc-order-refund-items.wc-order-data-row-toggle > div.refund-actions > button.button.button-primary.do-api-refund').click(); + await expect(page.locator('#select2-order_status-container')).toContainText("Processing"); + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Amount refund of EUR2.00'); } test.describe('Transaction in classic checkout', () => { - test('Transaction classic with Order API paid', async ({page, products, gateways}) => { + test.beforeAll(async ({browser }) => { + /*const page = await browser.newPage(); + await resetSettings(page); + await insertAPIKeys(page);*/ + }); + /*test('Transaction classic with Order API paid', async ({page, products, gateways}) => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransaction(page, product, gateway); + await classicCheckoutPaidTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -107,11 +127,11 @@ test.describe('Transaction in classic checkout', () => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutFailedTransaction(page, product, gateway); + await classicCheckoutFailedTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways - }); - test('Transaction classic with Order API cancelled setting as pending', async ({page, products, gateways}) => { + });*/ + /*test('Transaction classic with Order API cancelled setting as pending', async ({page, products, gateways}) => { await setOrderAPI(page); //setting as pending await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); @@ -122,7 +142,7 @@ test.describe('Transaction in classic checkout', () => { ]); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutCancelledTransactionPending(page, product, gateway); + await classicCheckoutCancelledTransactionPending(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -130,30 +150,30 @@ test.describe('Transaction in classic checkout', () => { await setOrderAPI(page); //setting as cancelled await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'cancelled'); await Promise.all([ page.waitForNavigation(), page.locator('text=Save changes').click() ]); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutCancelledTransactionCancelled(page, product, gateway); + await classicCheckoutCancelledTransactionCancelled(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways - }); + });*/ test('Transaction classic full refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransactionFullRefund(page, product, gateway); + await classicCheckoutPaidTransactionFullRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); - test('Transaction classic partial refund Order', async ({page, products, gateways}) => { + /*test('Transaction classic partial refund Order', async ({page, products, gateways}) => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransactionPartialRefund(page, product, gateway); + await classicCheckoutPaidTransactionPartialRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -162,7 +182,7 @@ test.describe('Transaction in classic checkout', () => { await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransaction(page, product, gateway); + await classicCheckoutPaidTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -177,7 +197,7 @@ test.describe('Transaction in classic checkout', () => { ]); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutCancelledTransactionPending(page, product, gateway); + await classicCheckoutCancelledTransactionPending(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -192,7 +212,7 @@ test.describe('Transaction in classic checkout', () => { ]); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutCancelledTransactionCancelled(page, product, gateway); + await classicCheckoutCancelledTransactionCancelled(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -200,7 +220,7 @@ test.describe('Transaction in classic checkout', () => { await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransactionFullRefund(page, product, gateway); + await classicCheckoutPaidTransactionFullRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -208,8 +228,8 @@ test.describe('Transaction in classic checkout', () => { await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { - await classicCheckoutPaidTransactionPartialRefund(page, product, gateway); + await classicCheckoutPaidTransactionPartialRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways - }); + });*/ }); From 081de4052782e105728ffb903430805fbe51b2e8 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 20 Jun 2022 11:40:36 +0200 Subject: [PATCH 010/100] Update failing tests --- .../orchestrate.d/33_woocommerce_config.sh | 2 +- .ddev/docker-compose.wp-plugin.yaml | 6 +- .env.example | 3 + package.json | 7 +- playwright.config.js | 20 +- tests/e2e/Cart/PayPalButtonCart.block.spec.js | 4 +- .../e2e/Cart/PayPalButtonCart.classic.spec.js | 47 +---- .../PayPalButtonProduct.classic.spec.js | 17 +- tests/e2e/Settings/GeneralSettings.spec.js | 2 +- .../PaymentSettingsCheckout.classic.spec.js | 7 +- tests/e2e/Shared/testMollieInWooPage.js | 32 ++- tests/e2e/Shared/wooUtils.js | 4 +- tests/e2e/Shared/wpUtils.js | 2 +- tests/e2e/Transaction/Checkout.block.spec.js | 185 ++++++------------ .../e2e/Transaction/Checkout.classic.spec.js | 69 +++---- 15 files changed, 160 insertions(+), 247 deletions(-) diff --git a/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh b/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh index bbc778c03..2ee4c7831 100644 --- a/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh +++ b/.ddev/commands/web/orchestrate.d/33_woocommerce_config.sh @@ -4,7 +4,7 @@ wp option set woocommerce_calc_taxes "yes" #create tax wp wc tax create --rate=10 --name="Standard tax" --priority=1 --compound=0 --shipping=1 --user="admin" - +wp option set woocommerce_tax_display_shop "incl" #euro wp option set woocommerce_currency "EUR" diff --git a/.ddev/docker-compose.wp-plugin.yaml b/.ddev/docker-compose.wp-plugin.yaml index d3c2859f4..699272849 100644 --- a/.ddev/docker-compose.wp-plugin.yaml +++ b/.ddev/docker-compose.wp-plugin.yaml @@ -1,5 +1,7 @@ version: '3.6' services: web: - volumes: - - ../:/var/www/html/.ddev/wordpress/wp-content/plugins/mollie-payments-for-woocommerce:ro + volumes: + - source: ../ + target: /var/www/html/.ddev/wordpress/wp-content/plugins/mollie-payments-for-woocommerce:ro + type: bind diff --git a/.env.example b/.env.example index 80e721780..78fe98dfd 100644 --- a/.env.example +++ b/.env.example @@ -26,3 +26,6 @@ ADMIN_EMAIL=me@my.com E2E_AUTH_USERNAME=admin E2E_AUTH_PW=admin +E2E_URL_TESTSITE=mollie.ddev.site +MOLLIE_LIVE_API_KEY= +MOLLIE_TEST_API_KEY= diff --git a/package.json b/package.json index 5ecb253af..e3b680c43 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "watch": "webpack --watch", "build": "node_modules/.bin/encore dev --env.basePath=.", "setup": "gulp setup", - "e2e-simple": "npx playwright test -c playwright.config.js --headed --project=simple-classic ", + "e2e-simple": "npx playwright test --project=simple-classic", "e2e-block": "npx playwright test --project=simple-block", "e2e-full-transaction": "npx playwright test --project=full-transaction", "e2e-cart-paypal": "npx playwright test --project=cart-paypal", - "e2e-product-paypal": "npx playwright test --project=product-paypal", + "e2e-product-paypal": "npx playwright test --project=product-paypal", "e2e-simple-settings": "npx playwright test --project=simple-settings", - "e2e-full-settings": "npx playwright test --project=full-settings" + "e2e-full-settings": "npx playwright test --project=full-settings", + "e2e-all-simple": "npx playwright test" }, "dependencies": { "@woocommerce/e2e-utils": "^0.1.6", diff --git a/playwright.config.js b/playwright.config.js index 888b4ddfa..fba9165a3 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -18,7 +18,7 @@ const {banktransfer, paypal, creditcard} = require('./tests/e2e/Shared/gateways' const config = { testDir: './tests/e2e', /* Maximum time one test can run for. */ - timeout: 30 * 1000, + timeout: 50 * 1000, expect: { /** * Maximum time expect() should wait for the condition to be met. @@ -29,7 +29,7 @@ const config = { /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: process.env.CI ? 2 : 1, /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ @@ -50,7 +50,7 @@ const config = { /* Configure projects for major browsers */ projects: [ - //all simple classic:simple prod, simple subs, one gw, one browser, checkout and settings, no buttons + //all simple classic:simple prod, simple subs, one gw, one browser, checkout, no buttons { name: 'simple-classic', testMatch: ['**/Transaction/Checkout.classic.spec.js'], @@ -64,7 +64,7 @@ const config = { //all simple blocks:simple prod, simple subs, one gw, one browser { name: 'simple-block', - testIgnore: ['**/Cart/**','**/Product/**', '**/*.classic.spec.js'], + testMatch: ['**/Transaction/Checkout.block.spec.js'], use: { ...devices['Desktop Chrome'], gateways: {creditcard}, @@ -74,10 +74,10 @@ const config = { //cart :paypal { name: 'cart-paypal', - testMatch: '**/Cart/**', + testMatch: '**/Cart/PayPalButtonCart.classic.spec.js', use: { ...devices['Desktop Chrome'], - gateways: {paypal}, + gateways: paypal, products: {simple, virtual}, }, }, @@ -87,7 +87,7 @@ const config = { testMatch: '**/Product/**', use: { ...devices['Desktop Chrome'], - gateways: {paypal}, + gateways: paypal, products: {simple, virtual}, }, }, @@ -110,15 +110,15 @@ const config = { }, }, //full transaction:all gw, all products, all browsers - { + /*{ name: 'full-transaction', - testIgnore: ['**/Cart/**', '**/Product/**', '**/Settings/**'], + testMatch: ['**!/Transaction/!**'], use: { ...devices['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari'], gateways: {banktransfer, paypal}, products: {simple, virtual}, }, - }, + },*/ ], /* Folder for test artifacts such as screenshots, videos, traces, etc. */ diff --git a/tests/e2e/Cart/PayPalButtonCart.block.spec.js b/tests/e2e/Cart/PayPalButtonCart.block.spec.js index 5538d74f1..5e1fea9eb 100644 --- a/tests/e2e/Cart/PayPalButtonCart.block.spec.js +++ b/tests/e2e/Cart/PayPalButtonCart.block.spec.js @@ -1,7 +1,7 @@ // @ts-check const { expect } = require('@playwright/test'); const { test } = require('../Shared/base-test'); -const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {setOrderAPI, markStatusInMollie} = require('../Shared/mollieUtils'); const {addProductToCart} = require('../Shared/wooUtils'); const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); @@ -50,7 +50,7 @@ test.describe('PayPal Transaction in classic cart', () => { ]); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Paid"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); diff --git a/tests/e2e/Cart/PayPalButtonCart.classic.spec.js b/tests/e2e/Cart/PayPalButtonCart.classic.spec.js index 713bfc9a3..1c3a37afb 100644 --- a/tests/e2e/Cart/PayPalButtonCart.classic.spec.js +++ b/tests/e2e/Cart/PayPalButtonCart.classic.spec.js @@ -1,11 +1,15 @@ // @ts-check const { expect } = require('@playwright/test'); const { test } = require('../Shared/base-test'); -const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); +const {resetSettings, insertAPIKeys} = require('../Shared/mollieUtils'); const {addProductToCart} = require('../Shared/wooUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); test.describe('PayPal Transaction in classic cart', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await resetSettings(page); + await insertAPIKeys(page); + }); test('Not be seen if not enabled', async ({page, products}) => { await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').uncheck(); @@ -20,43 +24,4 @@ test.describe('PayPal Transaction in classic cart', () => { //remove from cart await page.locator('tr.woocommerce-cart-form__cart-item.cart_item > td.product-remove > a').click(); }); - test('Not be seen if not virtual', async ({page, products}) => { - // set PayPal visible in cart - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); - await page.locator('input[name="mollie_wc_gateway_paypal_mollie_paypal_button_enabled_cart"]').check(); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); - await addProductToCart(page, products.simple.name); - //go to cart and not see - await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); - await expect(page.locator('#mollie-PayPal-button')).not.toBeVisible(); - //remove from cart - await page.locator('tr.woocommerce-cart-form__cart-item.cart_item > td.product-remove > a').click(); - }); - test('Transaction with Order API - virtual product', async ({page, gateways, products}) => { - let testedGateway = gateways - await setOrderAPI(page); - await addProductToCart(page, products.virtual.name); - //go to cart and click - await page.goto(process.env.E2E_URL_TESTSITE + '/cart/'); - await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > form > table > tbody > tr.woocommerce-cart-form__cart-item.cart_item > td.product-subtotal > span > bdi'); - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), - page.locator('input[alt="PayPal Button"]').click() - ]); - - // IN MOLLIE - // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); - - // WOOCOMMERCE ORDER PAID PAGE - await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); - - // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); - }); }); diff --git a/tests/e2e/Product/PayPalButtonProduct.classic.spec.js b/tests/e2e/Product/PayPalButtonProduct.classic.spec.js index 52ae945dd..98ba699b7 100644 --- a/tests/e2e/Product/PayPalButtonProduct.classic.spec.js +++ b/tests/e2e/Product/PayPalButtonProduct.classic.spec.js @@ -1,10 +1,15 @@ // @ts-check const { expect } = require('@playwright/test'); const { test } = require('../Shared/base-test'); -const {setOrderAPI, markPaidInMollie} = require('../Shared/mollieUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); +const {setOrderAPI, markStatusInMollie, resetSettings, insertAPIKeys} = require('../Shared/mollieUtils'); +const {wooOrderPaidPage, wooOrderDetailsPageVirtual} = require('../Shared/testMollieInWooPage'); test.describe('PayPal Transaction in classic product', () => { + test.beforeAll(async ({browser }) => { + const page = await browser.newPage(); + await resetSettings(page); + await insertAPIKeys(page); + }); test('Not be seen if not enabled', async ({ page }) => { // Go to virtual product product await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=mollie_wc_gateway_paypal'); @@ -43,20 +48,20 @@ test.describe('PayPal Transaction in classic product', () => { await expect(page.locator('#mollie-PayPal-button')).toBeVisible(); //Capture WooCommerce total amount - const totalAmount = products.virtual.price + const totalAmount = await page.innerText('div.summary.entry-summary > p > span > bdi') await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }*/), + page.waitForNavigation({ url: 'https://www.mollie.com/checkout/test-mode?method=paypal&token=3.q6wq1i' }), page.locator('input[alt="PayPal Button"]').click() ]); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Paid"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); + await wooOrderDetailsPageVirtual(page, mollieOrder, testedGateway); }); }); diff --git a/tests/e2e/Settings/GeneralSettings.spec.js b/tests/e2e/Settings/GeneralSettings.spec.js index be2d92f69..89203da6c 100644 --- a/tests/e2e/Settings/GeneralSettings.spec.js +++ b/tests/e2e/Settings/GeneralSettings.spec.js @@ -17,7 +17,7 @@ test.describe('Should show general settings', () => { const title = gateways[gatewayName].defaultTitle const id = gateways[gatewayName].id const url = await page.$eval(`text=${title} disabled activate >> img`, img => img.src); - await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${id}.svg`) + await expect(url).toContain(`/public/images/${id}.svg`) } }); test('Should connect when API key is present', async ({ page , gateways}) => { diff --git a/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js b/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js index 1c31bbee2..f61b98165 100644 --- a/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js +++ b/tests/e2e/Settings/PaymentSettingsCheckout.classic.spec.js @@ -26,12 +26,11 @@ test.describe('Should show payment settings on classic checkout', () => { let testedGateway = GATEWAYS[key] //check default title await page.locator('#payment_method_mollie_wc_gateway_' + testedGateway.id) - await expect(page.locator('#payment')).toContainText(testedGateway.defaultTitle); + await expect(page.locator(`#payment`)).toContainText(testedGateway.defaultTitle); //check default icon const url = await page.$eval(`text=${testedGateway.defaultTitle} >> img`, img => img.src); - await expect(url).toEqual(`${process.env.E2E_URL_TESTSITE}/wp-content/plugins/${process.env.E2E_TESTPACKAGE}//public/images/${testedGateway.id}.svg`) - //check default description - await expect(page.locator('#payment')).toContainText(testedGateway.defaultDescription); + await expect(url).toContain(`/public/images/${testedGateway.id}.svg`) + //check issuers dropdown show if (testedGateway.paymentFields) { let issuers = page.locator(`#payment > ul > li.wc_payment_method.payment_method_mollie_wc_gateway_${testedGateway.id} > div`) diff --git a/tests/e2e/Shared/testMollieInWooPage.js b/tests/e2e/Shared/testMollieInWooPage.js index 62741b94a..c92724cc0 100644 --- a/tests/e2e/Shared/testMollieInWooPage.js +++ b/tests/e2e/Shared/testMollieInWooPage.js @@ -18,7 +18,10 @@ const wooOrderRetryPage = async (page, mollieOrder, totalAmount, testedGateway) // Check we are in retry page const regex = new RegExp(`${process.env.E2E_URL_TESTSITE}/checkout/order-pay/${mollieOrder}.`); await expect(page).toHaveURL(regex); +} +const wooOrderCanceledPage = async (page, mollieOrder, totalAmount, testedGateway) => { + await expect(page.locator('#wp--skip-link--target > div.wp-container-7.entry-content.wp-block-post-content > div > div > p')).toContainText('cancelled'); } const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { @@ -31,6 +34,16 @@ const wooOrderDetailsPageOnPaid = async (page, mollieOrder, testedGateway) => { await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.defaultTitle + ' payment'); } +const wooOrderDetailsPageVirtual = async (page, mollieOrder, testedGateway) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Completed"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Order completed using Mollie – ' + testedGateway.defaultTitle + ' payment'); +} + const wooOrderDetailsPageOnFailed = async (page, mollieOrder, testedGateway) => { await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); // Check order is in status processing in order page @@ -40,5 +53,22 @@ const wooOrderDetailsPageOnFailed = async (page, mollieOrder, testedGateway) => // Check order notes has correct text await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText(testedGateway.id + ' payment started'); } +const wooOrderDetailsPageOnCanceled = async (page, mollieOrder, testedGateway) => { + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/edit.php?post_type=shop_order'); + // Check order is in status processing in order page + await expect(page.locator('#post-' + mollieOrder + '> td.order_status.column-order_status > mark > span')).toContainText("Cancelled"); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/post.php?post=' + mollieOrder + '&action=edit'); + + // Check order notes has correct text + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText(testedGateway.id + ' payment started'); +} -module.exports = {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed} +module.exports = { + wooOrderPaidPage, + wooOrderDetailsPageOnPaid, + wooOrderRetryPage, + wooOrderDetailsPageOnFailed, + wooOrderCanceledPage: wooOrderCanceledPage, + wooOrderDetailsPageOnCanceled, + wooOrderDetailsPageVirtual +} diff --git a/tests/e2e/Shared/wooUtils.js b/tests/e2e/Shared/wooUtils.js index 441342f65..afa93520c 100644 --- a/tests/e2e/Shared/wooUtils.js +++ b/tests/e2e/Shared/wooUtils.js @@ -28,9 +28,9 @@ const fillCustomerInCheckout = async (page) => { */ const fillCustomerInBlockCheckout = async (page) => { // Fill input[name="billing_first_name"] - await page.locator('input[name="billing_first_name"]').fill('Test'); + await page.locator('input[name="billing_first_name"]').fill('Julia'); // Fill input[name="billing_last_name"] - await page.locator('input[name="billing_last_name"]').fill('test'); + await page.locator('input[name="billing_last_name"]').fill('Callas'); } module.exports = {addProductToCart, fillCustomerInCheckout, fillCustomerInBlockCheckout} diff --git a/tests/e2e/Shared/wpUtils.js b/tests/e2e/Shared/wpUtils.js index 838d19a15..70016ab15 100644 --- a/tests/e2e/Shared/wpUtils.js +++ b/tests/e2e/Shared/wpUtils.js @@ -4,7 +4,7 @@ const loginAdmin = async (page)=>{ await page.locator('#user_pass').fill(process.env.ADMIN_PASS); await Promise.all([ page.waitForNavigation(), - page.locator('text=Log in').click() + page.locator('input:has-text("Log In")').click() ]); } diff --git a/tests/e2e/Transaction/Checkout.block.spec.js b/tests/e2e/Transaction/Checkout.block.spec.js index 9b30eab9c..3350e8778 100644 --- a/tests/e2e/Transaction/Checkout.block.spec.js +++ b/tests/e2e/Transaction/Checkout.block.spec.js @@ -1,8 +1,11 @@ // @ts-check -const {expect} = require('@playwright/test'); -const { test } = require('../Shared/base-test'); -const {setOrderAPI, setPaymentAPI, markPaidInMollie} = require('../Shared/mollieUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid} = require('../Shared/testMollieInWooPage'); +const {test} = require('../Shared/base-test'); +const {setOrderAPI, setPaymentAPI, markStatusInMollie, resetSettings, insertAPIKeys} = require('../Shared/mollieUtils'); +const { + wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed, + wooOrderCanceledPage, + wooOrderDetailsPageOnCanceled +} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInBlockCheckout} = require('../Shared/wooUtils'); /** @@ -10,15 +13,9 @@ const {addProductToCart, fillCustomerInBlockCheckout} = require('../Shared/wooUt * @param testedProduct * @param testedGateway */ -async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) { - await addProductToCart(page, testedProduct); - - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); +async function beforePlacingOrder(page, testedProduct, testedGateway) { + await addProductToCart(page, testedProduct.name); + await page.goto(process.env.E2E_URL_TESTSITE + '/checkout/'); //Capture WooCommerce total amount const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); @@ -27,16 +24,27 @@ async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) await fillCustomerInBlockCheckout(page); // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); + + await page.locator(`text=${testedGateway.defaultTitle}`).click(); // Click text=Place order await Promise.all([ page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), page.locator('text=Place order').click() ]); + return totalAmount; +} + +/** + * @param {import('@playwright/test').Page} page + * @param testedProduct + * @param testedGateway + */ +async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markPaidInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Paid"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderPaidPage(page, mollieOrder, totalAmount, testedGateway); @@ -46,32 +54,11 @@ async function blockCheckoutPaidTransaction(page, testedProduct, testedGateway) } async function blockCheckoutFailedTransaction(page, testedProduct, testedGateway) { - await addProductToCart(page, testedProduct); - - // Go to checkout - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - await page.locator('text=Checkout').first().click() - ]); - - await expect(page).toHaveURL(process.env.E2E_URL_TESTSITE + '/checkout/'); - //Capture WooCommerce total amount - const totalAmount = await page.innerText('.order-total > td > strong > span > bdi'); - - // CUSTOMER DETAILS - await fillCustomerInBlockCheckout(page); - - // Check testedGateway option NO ISSUERS DROPDOWN - await page.locator('text=' + testedGateway.title).check(); - // Click text=Place order - await Promise.all([ - page.waitForNavigation(/*{ url: 'https://www.mollie.com/checkout/test-mode?method=GATEWAY&token=XXX' }*/), - page.locator('text=Place order').click() - ]); + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); // IN MOLLIE // Capture order number in Mollie and mark as paid - const mollieOrder = await markFailedInMollie(page); + const mollieOrder = await markStatusInMollie(page, "Failed"); // WOOCOMMERCE ORDER PAID PAGE await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); @@ -81,48 +68,53 @@ async function blockCheckoutFailedTransaction(page, testedProduct, testedGateway } async function blockCheckoutCancelledTransactionPending(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); -} - -async function blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { - -} + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markStatusInMollie(page, "Canceled"); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); -async function blockCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { - await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); - //in order page select quantity - //refund + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); } -async function blockCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway) { - await blockCheckoutPaidTransaction(page, testedProduct, testedGateway); - //in order page select partial amount - //refund -} +async function blockCheckoutCancelledTransactionCancelled(page, testedProduct, testedGateway) { + const totalAmount = await beforePlacingOrder(page, testedProduct, testedGateway); -async function blockCheckoutExpiredTransaction(page, testedProduct, testedGateway) { + // IN MOLLIE + // Capture order number in Mollie and mark as paid + const mollieOrder = await markStatusInMollie(page, "Canceled"); + // WOOCOMMERCE ORDER PAID PAGE + await wooOrderCanceledPage(page, mollieOrder, totalAmount, testedGateway); + // WOOCOMMERCE ORDER PAGE + await wooOrderDetailsPageOnCanceled(page, mollieOrder, testedGateway); } test.describe('Transaction in block checkout', () => { + test.beforeAll(async ({browser}) => { + const page = await browser.newPage(); + await resetSettings(page); + await insertAPIKeys(page); + }); test('Transaction block with Order API paid', async ({page, products, gateways}) => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutPaidTransaction(page, product, gateway); + await blockCheckoutPaidTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); test('Transaction block with Order API failed', async ({page, products, gateways}) => { - await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutFailedTransaction(page, product, gateway); + await blockCheckoutFailedTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); test('Transaction block with Order API cancelled setting as pending', async ({page, products, gateways}) => { - await setOrderAPI(page); //setting as pending await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); @@ -132,46 +124,7 @@ test.describe('Transaction in block checkout', () => { ]); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutCancelledTransactionPending(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block with Order API cancelled setting as cancelled', async ({page, products, gateways}) => { - await setOrderAPI(page); - //setting as cancelled - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutCancelledTransactionCancelled(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block full refund Order', async ({page, products, gateways}) => { - await setOrderAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutPaidTransactionFullRefund(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block partial refund Order', async ({page, products, gateways}) => { - await setOrderAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutPaidTransactionPartialRefund(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block with Order API expired', async ({page, products, gateways}) => { - await setOrderAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutExpiredTransaction(page, product, gateway); + await blockCheckoutCancelledTransactionPending(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); @@ -180,14 +133,13 @@ test.describe('Transaction in block checkout', () => { await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutPaidTransaction(page, product, gateway); + await blockCheckoutPaidTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); test('Transaction block with Payment API cancelled setting as pending', async ({page, products, gateways}) => { - //Set Payment API - await setPaymentAPI(page); //setting as pending + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); await Promise.all([ page.waitForNavigation(), @@ -195,46 +147,21 @@ test.describe('Transaction in block checkout', () => { ]); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutCancelledTransactionPending(page, product, gateway); + await blockCheckoutCancelledTransactionPending(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); test('Transaction block with Payment API cancelled setting as cancelled', async ({page, products, gateways}) => { - //Set Payment API - await setPaymentAPI(page); //setting as cancelled - await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'cancelled'); await Promise.all([ page.waitForNavigation(), page.locator('text=Save changes').click() ]); for (const gateway in gateways) { for (const product in products) { - await blockCheckoutCancelledTransactionCancelled(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block full refund Payment', async ({page, products, gateways}) => { - await setPaymentAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutPaidTransactionFullRefund(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block partial refund Payment', async ({page, products, gateways}) => { - await setPaymentAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutPaidTransactionPartialRefund(page, product, gateway); - }// end loop products - }// end loop gateways - }); - test('Transaction block with Payment API expired', async ({page, products, gateways}) => { - await setPaymentAPI(page); - for (const gateway in gateways) { - for (const product in products) { - await blockCheckoutExpiredTransaction(page, product, gateway); + await blockCheckoutCancelledTransactionCancelled(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); diff --git a/tests/e2e/Transaction/Checkout.classic.spec.js b/tests/e2e/Transaction/Checkout.classic.spec.js index 4207686e0..5d2284dd8 100644 --- a/tests/e2e/Transaction/Checkout.classic.spec.js +++ b/tests/e2e/Transaction/Checkout.classic.spec.js @@ -2,8 +2,9 @@ const {expect} = require('@playwright/test'); const {test} = require('../Shared/base-test'); const {setOrderAPI, setPaymentAPI, markStatusInMollie, insertAPIKeys, resetSettings} = require('../Shared/mollieUtils'); -const {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed} = require('../Shared/testMollieInWooPage'); +const {wooOrderPaidPage, wooOrderDetailsPageOnPaid, wooOrderRetryPage, wooOrderDetailsPageOnFailed, wooOrderCanceledPage, wooOrderDetailsPageOnCanceled} = require('../Shared/testMollieInWooPage'); const {addProductToCart, fillCustomerInCheckout} = require('../Shared/wooUtils'); + /** * @param {import('@playwright/test').Page} page * @param testedProduct @@ -83,39 +84,42 @@ async function classicCheckoutCancelledTransactionCancelled(page, testedProduct, // Capture order number in Mollie and mark as paid const mollieOrder = await markStatusInMollie(page, "Canceled"); // WOOCOMMERCE ORDER PAID PAGE - await wooOrderRetryPage(page, mollieOrder, totalAmount, testedGateway); + await wooOrderCanceledPage(page, mollieOrder, totalAmount, testedGateway); // WOOCOMMERCE ORDER PAGE - await wooOrderDetailsPageOnFailed(page, mollieOrder, testedGateway); + await wooOrderDetailsPageOnCanceled(page, mollieOrder, testedGateway); } async function classicCheckoutPaidTransactionFullRefund(page, testedProduct, testedGateway) { - await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); - await page.locator('text=Refund').click(); - await page.locator('input[class="refund_order_item_qty"]').fill(1); + await beforePlacingOrder(page, testedProduct, testedGateway); + const mollieOrder = await markStatusInMollie(page, "Paid"); + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); + await page.locator('text=This order is no longer editable. Refund >> button').click(); + await page.locator('input[class="refund_order_item_qty"]').fill('1'); page.on('dialog', dialog => dialog.accept()); await page.locator('#woocommerce-order-items > div.inside > div.wc-order-data-row.wc-order-refund-items.wc-order-data-row-toggle > div.refund-actions > button.button.button-primary.do-api-refund').click(); await expect(page.locator('#select2-order_status-container')).toContainText("Refunded"); } async function classicCheckoutPaidTransactionPartialRefund(page, testedProduct, testedGateway) { - await classicCheckoutPaidTransaction(page, testedProduct, testedGateway); - await page.locator('text=Refund').click(); - await page.locator('input[name="#order_line_items > tr > td.line_cost > div.refund > input"]').fill(2); + await beforePlacingOrder(page, testedProduct, testedGateway); + const mollieOrder = await markStatusInMollie(page, "Paid"); + await wooOrderDetailsPageOnPaid(page, mollieOrder, testedGateway); + await page.locator('text=This order is no longer editable. Refund >> button').click(); + await page.locator('input[class="refund_order_item_qty"]').fill('0.5'); page.on('dialog', dialog => dialog.accept()); await page.locator('#woocommerce-order-items > div.inside > div.wc-order-data-row.wc-order-refund-items.wc-order-data-row-toggle > div.refund-actions > button.button.button-primary.do-api-refund').click(); await expect(page.locator('#select2-order_status-container')).toContainText("Processing"); - await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('Amount refund of EUR2.00'); + await expect(page.locator('#woocommerce-order-notes > div.inside > ul')).toContainText('EUR9.90'); } - test.describe('Transaction in classic checkout', () => { test.beforeAll(async ({browser }) => { - /*const page = await browser.newPage(); + const page = await browser.newPage(); await resetSettings(page); - await insertAPIKeys(page);*/ + await insertAPIKeys(page); }); - /*test('Transaction classic with Order API paid', async ({page, products, gateways}) => { + test('Transaction classic with Order API paid', async ({page, products, gateways}) => { await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { @@ -124,15 +128,13 @@ test.describe('Transaction in classic checkout', () => { }// end loop gateways }); test('Transaction classic with Order API failed', async ({page, products, gateways}) => { - await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { await classicCheckoutFailedTransaction(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways - });*/ - /*test('Transaction classic with Order API cancelled setting as pending', async ({page, products, gateways}) => { - await setOrderAPI(page); + }); + test('Transaction classic with Order API cancelled setting as pending', async ({page, products, gateways}) => { //setting as pending await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); @@ -146,31 +148,14 @@ test.describe('Transaction in classic checkout', () => { }// end loop products }// end loop gateways }); - test('Transaction classic with Order API cancelled setting as cancelled', async ({page, products, gateways}) => { - await setOrderAPI(page); - //setting as cancelled - await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); - await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'cancelled'); - await Promise.all([ - page.waitForNavigation(), - page.locator('text=Save changes').click() - ]); - for (const gateway in gateways) { - for (const product in products) { - await classicCheckoutCancelledTransactionCancelled(page, products[product], gateways[gateway]); - }// end loop products - }// end loop gateways - });*/ test('Transaction classic full refund Order', async ({page, products, gateways}) => { - await setOrderAPI(page); for (const gateway in gateways) { for (const product in products) { await classicCheckoutPaidTransactionFullRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways }); - /*test('Transaction classic partial refund Order', async ({page, products, gateways}) => { - await setOrderAPI(page); + test('Transaction classic partial refund Order', async ({page, products, gateways}) => { for (const gateway in gateways) { for (const product in products) { await classicCheckoutPaidTransactionPartialRefund(page, products[product], gateways[gateway]); @@ -187,9 +172,8 @@ test.describe('Transaction in classic checkout', () => { }// end loop gateways }); test('Transaction classic with Payment API cancelled setting as pending', async ({page, products, gateways}) => { - //Set Payment API - await setPaymentAPI(page); //setting as pending + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); await Promise.all([ page.waitForNavigation(), @@ -202,10 +186,9 @@ test.describe('Transaction in classic checkout', () => { }// end loop gateways }); test('Transaction classic with Payment API cancelled setting as cancelled', async ({page, products, gateways}) => { - //Set Payment API - await setPaymentAPI(page); //setting as cancelled - await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'pending'); + await page.goto(process.env.E2E_URL_TESTSITE + '/wp-admin/admin.php?page=wc-settings&tab=mollie_settings§ion=advanced'); + await page.selectOption('select#mollie-payments-for-woocommerce_order_status_cancelled_payments', 'cancelled'); await Promise.all([ page.waitForNavigation(), page.locator('text=Save changes').click() @@ -217,7 +200,6 @@ test.describe('Transaction in classic checkout', () => { }// end loop gateways }); test('Transaction classic full refund Payment', async ({page, products, gateways}) => { - await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { await classicCheckoutPaidTransactionFullRefund(page, products[product], gateways[gateway]); @@ -225,11 +207,10 @@ test.describe('Transaction in classic checkout', () => { }// end loop gateways }); test('Transaction classic partial refund Payment', async ({page, products, gateways}) => { - await setPaymentAPI(page); for (const gateway in gateways) { for (const product in products) { await classicCheckoutPaidTransactionPartialRefund(page, products[product], gateways[gateway]); }// end loop products }// end loop gateways - });*/ + }); }); From 850206bc61e5f29bc0e066812740d8da7756c9be Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 17 Aug 2022 08:46:25 +0200 Subject: [PATCH 011/100] general cs clean --- inc/settings/mollie_advanced_settings.php | 30 +++---- inc/utils.php | 4 +- inc/woocommerce.php | 1 + src/Activation/ActivationModule.php | 1 - src/Activation/ConstraintsChecker.php | 1 - src/Activation/PluginDisabler.php | 2 +- src/Assets/AssetsModule.php | 26 +++--- src/BlockService/CheckoutBlockService.php | 8 +- .../ApplePayButton/ApplePayDataObjectHttp.php | 88 +++++++++++-------- .../ApplePayButton/PropertiesDictionary.php | 1 - .../PayPalButton/PayPalDataObjectHttp.php | 1 - src/Gateway/GatewayModule.php | 12 +-- src/Gateway/OrderMandatoryGatewayDisabler.php | 2 +- src/Gateway/Surcharge.php | 14 ++- src/Gateway/Voucher/MaybeDisableGateway.php | 7 +- src/Gateway/Voucher/VoucherModule.php | 20 ++--- src/Notice/NoticeInterface.php | 1 - src/Payment/MollieObject.php | 24 ++--- src/Payment/MollieOrder.php | 5 +- src/Payment/MollieOrderService.php | 1 - src/Payment/MolliePayment.php | 2 +- src/Payment/MollieSubscription.php | 16 ++-- src/Payment/OrderLines.php | 9 +- .../PaymentCheckoutRedirectService.php | 4 +- src/Payment/PaymentFactory.php | 1 - src/Payment/PaymentModule.php | 11 ++- src/PaymentMethods/Bancontact.php | 1 - src/PaymentMethods/Banktransfer.php | 1 - .../ApplepayInstructionStrategy.php | 1 - .../BanktransferInstructionStrategy.php | 3 +- .../CreditcardInstructionStrategy.php | 1 - .../DefaultInstructionStrategy.php | 1 - .../DirectdebitInstructionStrategy.php | 1 - .../IdealInstructionStrategy.php | 1 - .../MybankInstructionStrategy.php | 1 - .../PaypalInstructionStrategy.php | 1 - .../Przelewy24InstructionStrategy.php | 1 - .../SofortInstructionStrategy.php | 1 - src/PaymentMethods/Klarnasliceit.php | 1 - src/PaymentMethods/Mybank.php | 1 - .../CreditcardFieldsStrategy.php | 7 +- .../DefaultFieldsStrategy.php | 1 - .../IssuersDropdownBehavior.php | 1 + src/PaymentMethods/PaymentMethodsIconUrl.php | 4 +- .../DefaultRedirectStrategy.php | 3 +- .../PaymentRedirectStrategyI.php | 1 - src/PaymentMethods/Paypal.php | 1 - src/PaymentMethods/Paysafecard.php | 1 - src/PaymentMethods/Przelewy24.php | 1 - src/PaymentMethods/Sofort.php | 1 - src/PaymentMethods/Voucher.php | 1 - src/SDK/WordPressHttpAdapter.php | 9 +- src/SDK/WordPressHttpAdapterPicker.php | 8 +- .../General/MollieGeneralSettings.php | 17 ++-- src/Settings/Page/MollieSettingsPage.php | 14 +-- src/Settings/Settings.php | 17 ++-- src/Settings/SettingsComponents.php | 1 - src/Settings/SettingsModule.php | 2 - src/Shared/Data.php | 15 ++-- src/Shared/GatewaySurchargeHandler.php | 47 +++++----- src/Shared/SharedModule.php | 2 +- src/Shared/Status.php | 1 + src/Subscription/MaybeFixSubscription.php | 1 - .../MollieSepaRecurringGateway.php | 1 - .../MollieSubscriptionGateway.php | 40 ++++----- src/Uninstall/CleanDb.php | 10 ++- 66 files changed, 249 insertions(+), 266 deletions(-) diff --git a/inc/settings/mollie_advanced_settings.php b/inc/settings/mollie_advanced_settings.php index bdf532c44..fbd6cac68 100644 --- a/inc/settings/mollie_advanced_settings.php +++ b/inc/settings/mollie_advanced_settings.php @@ -9,11 +9,11 @@ ['cleanDB-mollie' => 1, 'nonce_mollie_cleanDb' => $nonce_mollie_cleanDb] ); $api_payment_description_labels = [ - '{orderNumber}' => _x( 'Order number', 'Label {orderNumber} description for payment description options', 'mollie-payments-for-woocommerce' ), - '{storeName}' => _x( 'Site Title', 'Label {storeName} description for payment description options', 'mollie-payments-for-woocommerce' ), - '{customer.firstname}' => _x( 'Customer\'s first name', 'Label {customer.firstname} description for payment description options', 'mollie-payments-for-woocommerce' ), - '{customer.lastname}' => _x( 'Customer\'s last name', 'Label {customer.lastname} description for payment description options', 'mollie-payments-for-woocommerce' ), - '{customer.company}' => _x( 'Customer\'s company name', 'Label {customer.company} description for payment description options', 'mollie-payments-for-woocommerce' ) + '{orderNumber}' => _x('Order number', 'Label {orderNumber} description for payment description options', 'mollie-payments-for-woocommerce'), + '{storeName}' => _x('Site Title', 'Label {storeName} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.firstname}' => _x('Customer\'s first name', 'Label {customer.firstname} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.lastname}' => _x('Customer\'s last name', 'Label {customer.lastname} description for payment description options', 'mollie-payments-for-woocommerce'), + '{customer.company}' => _x('Customer\'s company name', 'Label {customer.company} description for payment description options', 'mollie-payments-for-woocommerce'), ]; return [ @@ -101,7 +101,7 @@ 'type' => 'select', 'options' => [ PaymentService::PAYMENT_METHOD_TYPE_ORDER => ucfirst( - PaymentService::PAYMENT_METHOD_TYPE_ORDER + PaymentService::PAYMENT_METHOD_TYPE_ORDER ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', PaymentService::PAYMENT_METHOD_TYPE_PAYMENT => ucfirst( @@ -137,10 +137,9 @@

%3$s', - - _x( 'Available variables', 'Payment description options', 'mollie-payments-for-woocommerce' ), - implode( '', array_map( - function ($label, $label_description) { + _x('Available variables', 'Payment description options', 'mollie-payments-for-woocommerce'), + implode('', array_map( + static function ($label, $label_description) { return sprintf( '