Cypress integration #671
Lisa-Danielle
started this conversation in
Ideas
Replies: 2 comments
|
hi @Lisa-Danielle not in the roadmap at the moment but PRs welcome! I'm happy to help you review |
0 replies
|
Stagehand + Cypress integration is an interesting combination — using Stagehand's AI-powered element targeting inside a Cypress test suite. A few approaches that could work: Option 1: Stagehand as a CLI fixture generator: // Use Stagehand to generate reliable CSS selectors/XPaths
// Then use those selectors in Cypress tests
const { Stagehand } = require("@browserbasehq/stagehand");
// Run this once during test setup to generate selectors
async function generateSelectors() {
const stagehand = new Stagehand();
await stagehand.init();
await stagehand.page.goto("https://yourapp.com/login");
// Ask Stagehand to find the right selector
const loginButton = await stagehand.page.getByAI("the login submit button");
const selector = await loginButton.evaluate(el => el.getAttribute('data-testid'));
// Write to a fixtures file for Cypress to use
writeSelectors({ loginButton: `[data-testid="${selector}"]` });
}Option 2: Stagehand for setup, Cypress for assertions: // cypress.config.js - run Stagehand setup before tests
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on('before:run', async () => {
// Use Stagehand to navigate complex setup flows
// (e.g., through wizard UIs, multi-step onboarding)
await runStagehandSetup();
});
},
},
});Option 3: Custom Cypress commands backed by Stagehand: // cypress/support/commands.js
Cypress.Commands.add('clickByAI', (description) => {
cy.task('stagehandClick', { description })
.then(selector => cy.get(selector).click());
});
// Usage in test:
cy.clickByAI('the submit order button in the checkout form');The value prop for Cypress integration: tests become resilient to UI refactors. Instead of brittle Is the goal faster test authoring, or more resilient existing tests? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hey! Any plans to integrate with Cypress?
All reactions