Loki_FunctionalTests

PHP 8.2 - 8.5
Magento 2.4.6 - 2.4.9
CSP Yes
Functional Tests 1
PHPStan 1
Magento PHPCS 8
License OSL-3.0
Latest Release none

This is an internal package containing Functional Tests based on Playwright. This is used specifically by the Loki core development team. Do not use this for your own shop. Also, do not enable the module Loki_FunctionalTests in production. When using this module anyway, do make sure to configured a proper token.

Installation

Install this package via composer:

composer require loki/magento2-functional-tests

Next, enable this module:

bin/magento module:enable Loki_FunctionalTests

Setup

Setup Playwright:

cd vendor/loki/magento2-functional-tests/Test/Playwright/
npm install
npx playwright install

Next, create a custom .env file within the same Test/Playwright/ folder:

TEST_URL=http://magento.local
TEST_TOKEN=loki

Next, make sure the listing of Loki modules in app/etc/loki.json is up to date:

bin/magento loki:modules:dump

Set the token from the CLI

Make sure a secure token is configured. The security token can also be reset from the CLI:

bin/magento config:set loki/functional_tests/token loki

For instance, you could generate a random token as follows

TOKEN=`tr -dc A-Za-z0-9 </dev/urandom | head -c 128; echo`
bin/magento config:set loki/functional_tests/token $TOKEN

Just make sure that the token matches the one in .env.

Running tests

All commands are run from the previous folder:

cd vendor/loki/magento2-functional-tests/Test/Playwright/

Run tests in headless mode:

npx playwright test
npx playwright show-report

Or run tests in the UI mode:

npx playwright test --ui

Or:

npx playwright test --headed

Because the app/etc/loki.json file contains entries that are being turned into Playwright projects, you can also run just a single project:

npx playwright test --ui --project=LokiCheckout_Mollie
npx playwright test --ui --project=LokiCheckout_Core basic-test
npx playwright test --ui --project=LokiCheckout_Core basic-test --debug

Note that parallelism doesn't work well. Each test could reconfigure the Magento instance with specific modules and configuration options. With that, the reconfiguration for one test might conflict with another test. Because of this, tests should not be run in parallel :(

If the Magento root could not be detected, for instance because your modules are symlinked into the Magento folder, define the Magento root via the environment variable MAGENTO_ROOT:

MAGENTO_ROOT=/var/www/html npx playwright test --ui

Switching the frontend theme

The configure endpoint (used by setupCheckout()) accepts a theme option with the code of a frontend theme:

await setupCheckout(page, context, {theme: 'Hyva/default-csp'});
await setupCheckout(page, context, {theme: 'Magento/luma'});

The theme is saved in the default scope. Any website-level or store-level theme overrides are removed, so that the given theme is always the active one.

Running the run-playwright-tests.sh script

This script is used mainly by the Loki core development team. To use it, navigate to your Magento root and symlink the script:

ln -s ./vendor/loki/magento2-functional-tests/run-playwright-tests.sh .

The script allows for the following parameters:

  • A Playwright project aka Magento 2 module with a Test/Playwright/ folder. This can also be ui to start the UI instead;
  • A specific test (or test pattern) within the Playwright project);
  • Token type. Currently random is supported. Otherwise the token defaults to loki;

Run all LokiCheckout_Core tests:

./run-playwright-tests.sh LokiCheckout_Core

Starting the UI:

./run-playwright-tests.sh ui

Current status

pipeline success
WARNING: This module has no releases yet. If you want to use it, make sure to add the version @dev to the composer command.

Support

For getting support, create an Issue under the following project URL:

https://gitlab.yireo.com/loki-extensions/Loki_FunctionalTests.git

Configuration Options

The following options of this module can be configured via the Store Configuration:

Functional Tests > Token
loki/functional_tests/token
When making AJAX calls, this token adds some security. Make sure to either set this on the fly, whenever you are running tests. Or make sure
Module Dependencies

The following dependencies are declared in the module its `etc/module.xml` file:

Magento_AdminNotification Magento_Backend Magento_Catalog Magento_CatalogInventory Magento_Checkout Magento_CheckoutAgreements Magento_Cms Magento_Config Magento_Csp Magento_Customer Magento_Directory Magento_Eav Magento_Indexer Magento_MediaStorage Magento_Newsletter Magento_Payment Magento_Quote Magento_Rule Magento_Sales Magento_SalesRule Magento_SalesSequence Magento_Shipping Magento_Store Magento_Tax Magento_Theme Magento_Ui Magento_User Magento_Variable Magento_Vault Magento_Widget Yireo_CspUtilities
Composer details
Magento module name
Loki_FunctionalTests
Composer name
loki/magento2-functional-tests
Composer version
No release yet
Default branch
main
Requirements
ext-json: *
ext-pcre: *
magento/framework: ^103.0
magento/module-backend: ^102.0
magento/module-catalog: ^104.0
magento/module-catalog-inventory: ^100.4
magento/module-checkout: ^100.4
magento/module-config: ^101.0
magento/module-csp: ^100.4
magento/module-customer: ^103.0
magento/module-eav: ^102.1
magento/module-quote: ^101.2
magento/module-store: ^101.1
magento/module-theme: ^101.1
yireo/magento2-enable-module-sequence: *
php: >=8.2 <8.6
symfony/console: ^5.0 | ^6.0 | ^7.0
Releases
Changelog
  • Initial release, copied from LokiCheckout_FunctionalTests
  • Remove dependency with Loki Checkout
  • Allow for DI-extensibility of AddToCartManager, Configurator and CustomerManager
  • Split run-playwright-tests.sh into run-playwright-tests.sh and prepare-playwright-tests.sh
  • Remove Setup/ patch for changed configuration file (cause this module is new anyway)
  • Allow ModuleXmlDependencies to track modules recursively
  • Change hard-coded mention /checkout inside Addtocart to dynamic route
  • Fix type casting of customer ID to string in CustomerManager
  • Add token-protected test page loki_functional_tests/index/page?handles=a,b and Playwright helper @loki/open-test-page for modules without a checkout
  • Add theme option to configure endpoint to switch the frontend theme (like Magento/luma or Hyva/default-csp)

Last modified: October 26, 2026