AI Summary1. * - Interactive elements, headings (reflects user perception) 2. - Form controls with labels 3. * - Inputs without labels
Install
Copy this and paste it into Claude Code, Cursor, or any AI assistant:
I want to add the "rhdh — Cursor Rules" prompt rules to my project. Repository: https://github.com/redhat-developer/rhdh Please read the repo to find the rules/prompt file, then: 1. Download it to the correct location (.cursorrules, .windsurfrules, .github/prompts/, or project root — based on the file type) 2. If there's an existing rules file, merge the new rules in rather than overwriting 3. Confirm what was added
Description
The repo formerly known as janus-idp/backstage-showcase
Quick Examples
`typescript // ✅ GOOD - Semantic locators await page.getByRole('button', { name: 'Submit' }).click(); await page.getByLabel('Username').fill('admin'); await page.getByPlaceholder('Search...').type('test'); await expect(page.getByText('Welcome')).toBeVisible(); // ✅ GOOD - Filtering and chaining await page.getByRole('row') .filter({ hasText: 'Guest User' }) .getByRole('button', { name: 'Edit' }) .click(); // ❌ BAD - Using getByText for interactive elements await page.getByText('Submit').click(); // Use getByRole('button', { name: 'Submit' }) instead // ❌ BAD - Implementation-dependent selectors await page.locator('.MuiButton-label').click(); await page.locator('div:nth-child(3)').click(); await page.locator('//*[@id="form"]/div[2]/input').fill('test'); `
Locator Priority (Use in Order)
• page.getByRole(role, { name }) - Interactive elements, headings (reflects user perception) • page.getByLabel(text) - Form controls with labels • page.getByPlaceholder(text) - Inputs without labels • page.getByText(text) - Non-interactive content only (avoid for buttons/links - use getByRole instead) • page.getByAltText(text) - Images • page.getByTitle(text) - Elements with title attribute • page.getByTestId(id) - When semantic locators unavailable (uses data-testid attribute only) • page.locator(selector) - Avoid CSS/XPath unless necessary
Anti-Patterns
• ❌ CSS class selectors (.MuiButton-label, [class="MuiTableCell"], .MuiDataGrid-) • ❌ Long XPath chains • ❌ nth-child without semantic context • ❌ Using force: true to bypass checks • ❌ Mixing locator strategies inconsistently • ❌ Using getByText for buttons or links (use getByRole instead) • ❌ Targeting dynamically generated text (dynamic status, timestamps) • ❌ Configuring custom test ID attributes (stick with data-testid only) • ❌ Selecting elements without scoping (may match from wrong card/dialog)
Assertions with Auto-Waiting
Playwright assertions automatically wait and retry (default: 5 seconds) until conditions are met. No manual waits needed. `typescript // ✅ Auto-waiting assertions await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible(); await expect(page.getByLabel('Status')).toHaveText('Submitted'); await expect(page.getByRole('list')).toHaveCount(5); // ❌ Unnecessary manual waiting await page.waitForSelector('.status'); // Don't do this, expect() waits automatically ` Common assertions: toBeVisible(), toBeHidden(), toBeEnabled(), toBeDisabled(), toBeChecked(), toHaveText(), toContainText(), toHaveValue(), toHaveCount(), toHaveAttribute() Auto-checks before actions: Visible, Stable (not animating), Enabled, Editable, Receives Events (not obscured)
Discussion
Health Signals
My Fox Den
Community Rating
Sign in to rate this booster
Works With
Any AI assistant that accepts custom rules or system prompts