Download the PHP package tappet/cypress without Composer
On this page you can find all versions of the php package tappet/cypress. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cypress
Tappet - Enjoyable GUI testing with Tappet, using Cypress
[EXPERIMENTAL] Cypress adapter for Tappet GUI testing.
See the Tappet core README for the core Tappet concepts - arrange/act/assert specs, fixtures, pages, and in particular transitions, the mechanism used to detect and assert on whole-page-state changes such as navigation or a modal opening/closing. This README only covers what's specific to the Cypress adapter, including how custom transition detection is wired up here.
Installation
Prerequisites
- PHP 8.1 or later
- Composer
1. Install the adapter
2. Configure the adapter
Create tappet.{suite-name}.suite.php in the root of your project, for example:
tappet.cypress.suite.php (to name the suite cypress):
3. Install Cypress
Inside the nested Cypress project directory referenced by cypressRoot above (e.g. tests/gui), scaffold a Cypress
project along with this package's JS/TS half, which provides the Uniter defineConfig factory and Cypress plugin
that bridge PHP and JavaScript:
Update cypress.config.js to register tappet/cypress:
cypress.config.js
In the same directory, create a uniter.config.js to configure Uniter,
which is used to run PHP code under a JavaScript environment:
uniter.config.js
Now you can create your specs, for example tests/gui/spec/Workflow/create_workflow.spec.php.
Note that the spec/ part of the path was defined by specPattern: 'spec/**/*.spec.php' in cypress.config.js above.
Custom transition detection
Tappet core defines what a transition is (TransitionInterface) and how specs assert on one
(EnvironmentInterface::assertTransition()). However, detection of a transition occurring is necessarily
adapter-specific, since it depends on hooking into the underlying test tool. This package detects transitions
by dispatching events during the Cypress test run that plugins can listen to, and pushing detected transitions
onto the shared transition log via CypressAutomationInterface::pushTransition(TransitionInterface $transition): void.
The built-in NavigationTransition is pushed automatically by this adapter whenever the AUT's window fires a load
event; for plain page navigation, there is nothing you need to wire up. Anything else, such as a modal appearing or
disappearing, needs a plugin.
Writing a plugin
A plugin implements Tappet\Suite\Plugin\PluginInterface (from tappet/tappet core) and declares a map of
event class to listener. The most relevant event for transition detection is WindowBeforeLoadEvent, fired
before each AUT window load with access to $window, a Uniter FFI wrapper of the browser's Window object so
that JS methods/properties (e.g. $window->document, $window->MutationObserver) can be called/used from PHP.
Continuing the modal example from the core README, here's how tappet/tappet's own test suite detects
data-ui-modal elements toggling their hidden attribute, using a MutationObserver, and pushes the
corresponding ModalOpenTransition/ModalClosedTransition:
ModalOpenTransition/ModalClosedTransition and their matching ExpectModalOpen/ExpectModalClosed
arrangement/assertion classes are just application-level TransitionInterface/ArrangementInterface/
AssertionInterface implementations - see the core README's transitions section
for how those interfaces work. Nothing about them is Cypress-specific; only the detection plugin above is.
Registering a plugin
Register the plugin against the CypressSuite instance returned by tappet.{suite-name}.suite.php:
Custom behaviour extension
Other *InitEvent classes in Tappet\Cypress\Event (FieldActionInitEvent, FieldAssertionInitEvent,
InteractionInitEvent, MatchHandlerInitEvent, RegionAssertionInitEvent, StateAssertionInitEvent) follow
the same plugin-listener mechanism, but are for registering custom field actions, field assertions, interactions,
matchers, matchers, region assertions and state assertions respectively rather than for transition detection.
For example: