cy.prompt() Changes UI Testing Forever. How it works under the hood




The Pain We’ve All Felt

If you’ve ever tested a Shadow DOM component or a slotted element, you know the pain.

Finding the right selector sometimes feels like archaeology – digging through browser dev tools, retries, custom commands in the dev console, and then one day… a UI redesign breaks it all again…

I’ve personally spent hours writing helpers just to find one stubborn element inside a Shadow Root which was slotted at the same time.
And every time, I thought:

“There must be a simpler way to tell the test what I mean.”



The Breakthrough – cy.prompt()

I think some QA Gods and #cypress product team heard me. Now, there is cy.prompt() !
With cy.prompt(), you can literally describe what to test, and Cypress with AI assistance will translate it into executable test code.

//test-login.spec.js

cy.prompt([
  "Navigate to '/login' // with baseUrl set
  "Fill email in the shadow email input and submit"
  "Verify error message 'Password is required' is displaying below the password input field in the shadow DOM"
]);

Enter fullscreen mode

Exit fullscreen mode

Cypress runs this step, finds stable selectors under the hood, and caches them for speed.
If the DOM changes, it can self-heal by regenerating selectors automatically.

No more guessing, no more brittle selectors, no more “why did this break again?”.



Shadow DOM & Slotted Elements Example

Before I had to write custom Cypress commands just to get correct slotted UI element from a Shadow DOM. And my code looked like this:

Cypress-custom-command-for-slotted-element

And then I had to use that in my test

Cypress-test-with-slotted-element

And now…wait for it…

//test-login.spec.js

cy.prompt("Fill email in the shadow email input and submit");

Enter fullscreen mode

Exit fullscreen mode

Same action, one line — and it understands nested DOM structures too.
That’s what makes this release so huge.



🥒 Works with Gherkin & Cucumber

If you’re using Cucumber and have a perfect-written Gherkin from you PM or PO, this is where it gets really interesting.

Cypress can now map your plain English steps directly to real actions.

gherkin

Given I log in with a valid user

Enter fullscreen mode

Exit fullscreen mode

can become:

cy.prompt("Log in with a valid user")
Enter fullscreen mode

Exit fullscreen mode

But I would still recommend to use the Golden Rule: Don’t mix business rules and test code in plain text.

You still want your custom commands and good test design – cy.prompt() is a boost, not a replacement.



Quick Comparison

Before

  • Complex, verbose test code
  • Heavy selector maintenance
  • Manual test updates
  • Cucumber integration needs mapping

After

  • One clear, natural-language step
  • Auto-generated, cached selectors
  • AI-assisted self-healing
  • AI maps English → test commands
  • AI suggestions if your prompt is weak for execution
  • Cashed runs if DOM not changed → better test performance



Current Limitations

It’s not magic (yet):

  1. Works only with UI, not API assertions.
  2. Still experimental — needs your feedback.
  3. Generated code should be reviewed before committing.

But even now, it’s a massive leap forward in software test automation experience, though!


cy.prompt() feels like the moment automation starts listening to us.
It bridges natural language, AI, and test logic — while keeping the power of Cypress intact.

As someone who fought Shadow DOM selectors for years, I can honestly say that I’ve never written reliable UI tests this fast before.

Finding out what’s next for cy.prompt()

Would you use cy.prompt() in your daily workflows or wait until it matures a bit more?

Follow my Telegram Channel for more insights. I share everything there first: Software Tester’s Notes

And my YouTube Channel:



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *