Skip to content

Commit

Permalink
Update autotest to fit kb
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed May 16, 2024
1 parent 43165a8 commit 2c04bf8
Show file tree
Hide file tree
Showing 202 changed files with 10,631 additions and 87 deletions.
10 changes: 4 additions & 6 deletions .idea/WooCommerce.iml

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

2 changes: 1 addition & 1 deletion .idea/phpunit.xml

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

10 changes: 5 additions & 5 deletions tests/Playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
node_modules
pw-browsers
test-results
.env
yarn.lock
13 changes: 13 additions & 0 deletions tests/Playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

### Setup E2E tests
In your test environment
- Import the products
- -Check the language of the site, must be English unless specified
- 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
- Run ngrok to expose the site and be able to test the webhooks
```
$ npx playwright test
```

12 changes: 12 additions & 0 deletions tests/Playwright/globalSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { chromium } from '@playwright/test';
const { loginAdmin } = require('./tests/Shared/wpUtils');
async function globalSetup(config) {
const { baseURL, storageState } = config.projects[0].use;
const browser = await chromium.launch();
const page = await browser.newPage({ baseURL: baseURL, extraHTTPHeaders: {'ngrok-skip-browser-warning': '123'}});
await loginAdmin(page);
await page.context().storageState({ path: storageState });
await browser.close();
}

export default globalSetup;
16 changes: 5 additions & 11 deletions tests/Playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"name": "playwright",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.43.1",
"@types/node": "^20.12.7"
"license": "MIT",
"dependencies": {
"@playwright/test": "^1.34.2",
"@woocommerce/woocommerce-rest-api": "^1.0.1",
"dotenv": "^16.0.3"
}
}
183 changes: 119 additions & 64 deletions tests/Playwright/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,134 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');
const {defineConfig, devices} = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

require('dotenv').config();
const testRailOptions = {
// Whether to add <properties> with all annotations; default is false
embedAnnotationsAsProperties: true,
// Where to put the report.
outputFile: './test-results/junit-report.xml'
};
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* 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',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
retries: 1,
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: false,
//timeout: 120000,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
['line'],
['junit', testRailOptions]
],
globalSetup: './globalSetup.js',

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.BASEURL_DEFAULT_80,
storageState: './storageState.json',
//extraHTTPHeaders: {'ngrok-skip-browser-warning': '123'},
actionTimeout: 120000,
ignoreHTTPSErrors: true,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
video: {
mode: 'on-first-retry',
size: {width: 1280, height: 720},
dir: './videos'
}
},

{
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: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
/*{
name: 'setup-default-settings-merchant',
testMatch: './tests/Shared/setup-default-settings-merchant.spec.js',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_DEFAULT_80
}
},
{
name: 'setup-settings-merchant',
testMatch: './tests/Shared/setup-default-settings-merchant.spec.js',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_SETTINGS_80
}
},
{
name: 'setup-payment-api-merchant',
testMatch: './tests/Shared/setup-default-settings-merchant.spec.js',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_PAYMENT_80
}
},
{
name: 'plugins-page-80',
testDir: './tests/Plugins page',
dependencies: ['setup-settings-merchant'],
use: {
...devices['Desktop Chrome'],
testIdAttribute: 'data-slug',
baseURL: process.env.BASEURL_SETTINGS_80
}
},
{
name: 'woo-payments-tab-80',
testDir: './tests/WooCommerce Payments tab',
dependencies: ['setup-default-settings-merchant'],
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_DEFAULT_80
}
},*/
/*{
name: 'transaction-scenarios-orders-80',
testDir: './tests/transaction',
//dependencies: ['setup-default-settings-merchant'],
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_DEFAULT_80
}
},*/
/*{
name: 'transaction-scenarios-payments-80',
testDir: './tests/Transaction Scenarios',
dependencies: ['setup-payment-api-merchant'],
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_PAYMENT_80
}
},
{
name: 'mollie-settings-tab-80',
testDir: './tests/Mollie Settings tab',
dependencies: ['setup-settings-merchant'],
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_SETTINGS_80
}
},
{
name: 'error-handling-80',
testDir: './tests/Error Handling',
dependencies: ['setup-default-settings-merchant'],
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_DEFAULT_80
}
},*/
],
});

22 changes: 22 additions & 0 deletions tests/Playwright/tests/Shared/base-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const base = require('@playwright/test');
const {allProducts} = require('./products');
const {allMethods} = require('./gateways');

exports.test = base.test.extend({
products: [allProducts, { option: true }],
gateways: [allMethods, { option: true }],
baseURL: async ({}, use) => {
await use(process.env.BASEURL_DEFAULT_80);
},
context: async ({ browser, baseURL }, use) => {
// Additional options can be included when creating the context
const context = await browser.newContext({baseURL});
await use(context);
await context.close();
},
page: async ({ context }, use) => {
const page = await context.newPage();
await use(page);
await page.close();
},
});
17 changes: 17 additions & 0 deletions tests/Playwright/tests/Shared/gateways.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const methodsConfig = require('./methodsConfig.json')


const banktransfer = methodsConfig.banktransfer;
const ideal = methodsConfig.ideal;
const creditcard = methodsConfig.creditcard;
const paypal = methodsConfig.paypal;
const normalizedName = (name) => {
name = name.replace('\", \"mollie-payments-for-woocommerce\")', '');
return name.replace('__(\"', '');
}
const getMethodNames = () => {
return Object.values(methodsConfig).map((method) => normalizedName(method.defaultTitle));
};
const allMethodsIds = Object.keys(methodsConfig);
const allMethods = methodsConfig;
module.exports = {banktransfer, ideal, creditcard, paypal, normalizedName, getMethodNames, allMethods, allMethodsIds};
38 changes: 38 additions & 0 deletions tests/Playwright/tests/Shared/manualOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const manualOrder = {
set_paid: false,
billing: {
first_name: "Tester",
last_name: "testing",
address_1: "969 Market",
address_2: "",
city: "San Francisco",
state: "CA",
postcode: "94103",
country: "US",
email: "john.doe@example.com",
phone: "(555) 555-5555"
},
shipping: {
first_name: "John",
last_name: "Doe",
address_1: "969 Market",
address_2: "",
city: "San Francisco",
state: "CA",
postcode: "94103",
country: "US"
},
line_items: [
{
product_id: 14,
quantity: 1
}
],
shipping_lines: [
{
method_id: "flat_rate",
method_title: "Flat Rate",
total: "0.00"
}
]
};
Loading

0 comments on commit 2c04bf8

Please sign in to comment.