PHP code example of tappet / cypress

1. Go to this page and download the library: Download tappet/cypress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tappet / cypress example snippets




declare(strict_types=1);

use Tappet\Cypress\Suite\CypressSuite;

$suite = new CypressSuite(
    cypressRoot: __DIR__ . '/tests/gui' // Points to the nested Cypress project created for Tappet.
);

$suite->addPlugin(new MyPlugin());

return $suite;


class TestPlugin implements PluginInterface
{
    public function getListeners(): array
    {
        return [
            WindowBeforeLoadEvent::class => function (EventInterface $event, CypressAutomationInterface $automation): void {
                $window = $event->getWindow();

                $observer = new $window->MutationObserver(
                    function ($mutations) use ($automation): void {
                        foreach ($mutations as $mutation) {
                            if ($mutation->type !== 'attributes' || $mutation->attributeName !== 'hidden') {
                                return;
                            }

                            $el = $mutation->target;
                            $handle = $el->getAttribute('data-ui-modal');

                            if (!$handle) {
                                return;
                            }

                            $isVisible = !$el->hasAttribute('hidden');

                            $automation->pushTransition(
                                $isVisible
                                    ? new ModalOpenTransition($handle)
                                    : new ModalClosedTransition($handle)
                            );
                        }
                    }
                );

                $window->document->addEventListener(
                    'DOMContentLoaded',
                    function () use ($observer, $window): void {
                        $observer->observe($window->document->body, [
                            'subtree' => true,
                            'attributes' => true,
                            'attributeFilter' => ['hidden'],
                        ]);
                    }
                );
            },
        ];
    }
}



declare(strict_types=1);

use Tappet\Cypress\Suite\CypressSuite;

$suite = new CypressSuite(__DIR__);

$suite->addPlugin(new TestPlugin());

return $suite;



declare(strict_types=1);

namespace MyApp\Tests\Tappet\Plugin;

use MyApp\Tests\Tappet\MatchHandler\BadgeMatchHandler;
use Tappet\Common\Event\EventInterface;
use Tappet\Cypress\Automation\CypressAutomationInterface;
use Tappet\Cypress\Event\MatchHandlerInitEvent;
use Tappet\Suite\Plugin\PluginInterface;

/**
 * @implements PluginInterface<CypressAutomationInterface>
 */
class MyPlugin implements PluginInterface
{
    public function getListeners(): array
    {
        return [
            MatchHandlerInitEvent::class => function (EventInterface $event): void {
                /** @var MatchHandlerInitEvent $event */
                $event->registerMatchHandler('badge', new BadgeMatchHandler($event->getAutomation()));
            },
        ];
    }
}