Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and Enhancement of Playwright Tests #930

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/Playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

### Setup Playwright tests
In your test environment
- Import the products
- Set WooCommerce taxes, shipping, and payment methods
- Check the language of the site, must be English unless specified
- Update the env with url and credentials
- Create the WooCommerce API key and insert in env
- If you make a dump of this environment, you can use it to restore the environment for the tests
- Suggestion to create different dumps for different preconditions
- In ddev playwright is already installed, in local you will need to [install it](https://playwright.dev/docs/intro#installing-playwright)


This runs one particular test
```
$ npx playwright test name-of-the-test.spec.js
```
This runs a project that can cover different tests against another environment

```
$ npx playwright test --project=project-name
```



26 changes: 26 additions & 0 deletions tests/Playwright/fixtures/base-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const base = require('@playwright/test');
const {allProducts, randomProduct} = require('../utils/products');
const {allMethods} = require('../utils/gateways');
const {default: WooCommerceRestApi} = require("@woocommerce/woocommerce-rest-api");

exports.test = base.test.extend({
products: [allProducts, { option: true }],
gateways: [allMethods, { option: true }],
canListenWebhooks: [process.env.WEBHOOKS, { option: true }],
baseURL: async ({}, use, testInfo) => {
const projectBaseURL = testInfo.project.use && testInfo.project.use.baseURL;
console.log('projectBaseURL', projectBaseURL);
await use(projectBaseURL || 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();
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chromium } from '@playwright/test';
const { loginAdmin } = require('./Shared/wpUtils');
const { loginAdmin } = require('./utils/wpUtils');
async function globalSetup(config) {
const { baseURL, storageState } = config.projects[0].use;
const browser = await chromium.launch();
Expand Down
8 changes: 8 additions & 0 deletions tests/Playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"license": "MIT",
"dependencies": {
"@playwright/test": "^1.34.2",
"@woocommerce/woocommerce-rest-api": "^1.0.1",
"dotenv": "^16.0.3"
}
}
66 changes: 66 additions & 0 deletions tests/Playwright/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// @ts-check
const {defineConfig, devices} = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
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({
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',

/* utils 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'
}
},
//todo: option random payment method version for every project, for faster execution, filtering the dataset
//todo: twint and blik payment methods in separate projects, precondition woocommerce different currency?
//todo: apple with a safari project
// Configure projects with a reduce set of test for preconditions to point to different configured envs,
// shared stories: php version, woo and wp version, different currencies, orders/payments api, taxes and shipping matrix
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
/*{
name: 'setup-default-php81',
testMatch: 'tests/Playwright/tests/transaction/Payment statuses - Block Checkout/_transaction_scenarios_payment_statuses_-_block_checkout.spec.js',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.BASEURL_DEFAULT_81
}
},*/
],
});

Loading
Loading