PluginBench
Skill
Review
Audit score 70

hyva-playwright-test

hyva-themes/hyva-ai-tools

How to install hyva-playwright-test

npx skills add https://github.com/hyva-themes/hyva-ai-tools --skill hyva-playwright-test
Claude Code
Cursor
Windsurf
Cline
Full instructions (SKILL.md)

Source of truth, from hyva-themes/hyva-ai-tools.


name: hyva-playwright-test description: Write Playwright tests for Hyvä themes with Alpine.js components. This skill should be used when writing e2e tests, creating page objects, or debugging selector issues in Playwright tests for Hyvä Magento storefronts. Trigger phrases include "write playwright test", "playwright alpine", "test hyva page", "e2e test", "playwright selector".

Writing Playwright Tests for Hyvä + Alpine.js

Overview

Hyvä replaces Luma's KnockoutJS/RequireJS/jQuery with Alpine.js + Tailwind CSS. Playwright's strict mode (rejects locators matching multiple elements) conflicts with Alpine.js DOM patterns where hidden elements exist throughout the page. This skill documents pitfalls and solutions discovered while writing Playwright tests for Hyvä storefronts.

The #1 Rule: Hidden Alpine Elements

Hyvä templates scatter elements like <div x-show="displayErrorMessage" class="message error"> throughout the DOM. These are invisible but present, so a bare selector like .message.error matches both hidden and visible instances, causing Playwright strict mode violations.

Always scope page-level messages to the #messages container:

// WRONG — matches hidden Alpine x-show elements throughout DOM
await expect(page.locator('.message.success')).toContainText('Added to cart');
await expect(page.locator('.message-error')).toContainText('Error');

// RIGHT — scoped to the visible messages container
await expect(page.locator('#messages .message.success')).toContainText('Added to cart');
await expect(page.locator('#messages .message-error, #messages .message.error')).toContainText('Error');

Never use: bare .message, .message.error, .message.success, or div.message as selectors.

Exception — inline page messages: Not all .message elements are flash messages. The search results "no results" notice (.message.notice) renders as static inline content inside #maincontent, not inside the #messages container. For these inline messages, the bare class selector is correct.

Selector Strategy

Follow Playwright's recommended locator priority:

  1. getByRole() — always prefer — closest to how users perceive the page. Avoids text ambiguity where the same text appears in headings, links, breadcrumbs, and sr-only spans.
  2. getByLabel() — for form controls (checkboxes, inputs with associated labels).
  3. getByText() — for non-interactive elements, scoped to a container (e.g., page.locator('#maincontent').getByText(...)).
  4. getByPlaceholder(), getByAltText() — for inputs and images respectively.
  5. getByTestId() — when Hyvä provides data-testid attributes or when adding custom test IDs.
  6. CSS selectors — last resort, only when user-facing locators aren't available. Prefer aria-* attribute selectors (e.g., [aria-label="pagination"], [aria-current="page"]) over class-based selectors. When CSS is necessary, scope to a unique container (e.g., #messages .message.success).

Avoid: :visible pseudo-selector — per Playwright docs, "it's usually better to find a more reliable way to uniquely identify the element." Scope to a container or use role/attribute selectors instead. Only use :visible as an absolute last resort when the DOM provides no other way to distinguish elements.

Alpine.js Interaction Patterns

PatternProblemSolution
x-show hidden elementsStrict mode: multiple matchesScope to unique container (#messages), use role/attribute selectors
x-defer="intersect"Element not initialized until visiblescrollIntoViewIfNeeded() before interacting
x-if (template)Elements don't exist in DOM until condition trueClick the trigger first, then query children
x-model on inputsAlpine clears value after form submitDon't assert input value post-submit; verify via success message
x-text / x-html asyncCart badge updates asynchronouslyUse web-first assertions with timeout: not.toHaveText('0', { timeout: 15_000 })
x-show submenusHidden until hoverhover() on parent before clicking child
Alpine form revealFields hidden until checkbox checkedwaitFor({ state: 'visible' }) after checking the checkbox
press('Enter') on inputMay submit Alpine-bound form unexpectedlyPrefer explicit .click() on submit button

Assertions

Always use web-first assertions that auto-wait and retry:

// DO — auto-retries             // DON'T — no retry
await expect(loc).toBeVisible(); // expect(await loc.isVisible()).toBe(true);
await expect(loc).toContainText('X'); // expect(await loc.textContent()).toContain('X');

For async Alpine.js updates (cart counts, prices), use extended timeouts on the assertion — never waitForTimeout():

// Cart count updates asynchronously via Alpine x-text
await expect(page.locator('#menu-cart-icon span[x-text="summaryCount"]'))
  .not.toHaveText('0', { timeout: 15_000 });

Hyvä vs Luma Selector Differences

ElementHyvä SelectorLuma Selector
Pagination navgetByRole('navigation', { name: 'pagination' })ul.pages-items
Page linkgetByRole('link', { name: 'Page 2' }).pages-items li a
Active page[aria-current="page"]<strong> element
Filter buttongetByRole('button', { name: 'Color filter' }).filter-options-title
Cart icon badge#menu-cart-icon > span[x-text="summaryCount"].counter-number
Account menu#customer-menu + nav.customer-menu
Success message#messages .message.success.message-success
Error message#messages .message-error, #messages .message.error.message-error
Main menugetByRole('navigation', { name: 'Main menu' })nav.navigation
Footer navgetByRole('navigation', { name: 'Company Menu' }).getByRole('link', { name })nav ul li:nth-child(N) a
Product image#gallery img[itemprop="image"]#gallery img:visible
Add to Cart (card)getByRole('button', { name: /Add to Cart/ }).first()button.btn-primary:visible

References

See references/ for code examples. Load files relevant to the current task:

Always useful:

Page-specific (load when testing that page):

<!-- Copyright © Hyvä Themes https://hyva.io. All rights reserved. Licensed under OSL 3.0 -->

Related skills

More from hyva-themes/hyva-ai-tools and the wider catalog.

HY

hyva-exec-shell-cmd

hyva-themes/hyva-ai-tools

Utility skill to detect Magento development environment and determine command wrapper. This skill should be used by other skills that need to execute shell commands in the Magento environment. It detects Warden, docker-magento, DDEV, and local environments and provides the appropriate command wrapper.

662 installs
HY

hyva-alpine-component

hyva-themes/hyva-ai-tools

Write CSP-compatible Alpine.js components for Hyvä themes in Magento 2. This skill should be used when the user wants to create Alpine components, add interactivity to Hyvä templates, write JavaScript for Hyvä themes, or needs help with Alpine.js patterns that work with Content Security Policy. Trigger phrases include "create alpine component", "add interactivity", "alpine for hyva", "x-data component", "csp compatibility", "csp compliant javascript".

655 installs
HY

hyva-child-theme

hyva-themes/hyva-ai-tools

Create a Hyvä child theme in a Magento 2 project. This skill should be used when the user wants to create a new Hyvä child theme, set up a custom theme based on Hyvä, or initialize a new frontend theme directory structure. Trigger phrases include "create hyva child theme", "new hyva theme", "setup child theme", "create custom theme", "initialize theme".

648 installs
HY

hyva-compile-tailwind-css

hyva-themes/hyva-ai-tools

Compile Tailwind CSS for Hyvä themes in Magento 2. Use when the user wants to build styles, generate CSS, compile Tailwind, run Tailwind, or create production/development stylesheets for a Hyvä theme. Also use when Tailwind classes are not taking effect or some styles appear missing after template changes — this typically means CSS needs to be recompiled. Triggers include "compile tailwind", "build styles", "generate css", "styles not working", "styles are missing", "styles not applied".

636 installs
HY

hyva-ui-component

hyva-themes/hyva-ai-tools

Apply Hyva UI template-based components to a Hyvä theme. This skill should be used when the user wants to add, install, or apply a Hyva UI component (such as header, footer, gallery, menu, minicart, etc.) to their Hyvä theme. It lists available non-CMS components and their variants, displays component README instructions, and copies component files to the theme directory.

635 installs
HY

hyva-create-module

hyva-themes/hyva-ai-tools

Create a new Magento 2 module in app/code/. This skill should be used when the user wants to create a module, scaffold a new module, generate module boilerplate, or set up a custom module. It handles registration.php, composer.json, module.xml generation with configurable dependencies. Trigger phrases include "create module", "new module", "scaffold module", "generate module".

632 installs