I know, I know, Cypress has just announced a game changing feature with cy.prompt() that is going to change the way we test - or at least approach how we think of it. You're going to use Natural Language all the way to test your new app? Read through my recommendations then!
As a Cypress Ambassador I was lucky enough to be using cy.prompt for the past weeks and here are a few tips to make your testing and usage go a bit smoothly.
1) Start your phrase with the action or assertion you want
Instead of giving it an instruction like:
When the page loads, check that the header is seen and then click on Create button
Would be better to:
Wait 8 seconds for the page to load
Assert that the header is visible
Click on create button
Now Cypress will translate your instructions more easily - a hardcoded wait, followed by an assertion, followed by a click.
2) Try to separate instructions
The previous step gave it away already! Cypress prompt works as any other LLM - give clear instructions of what you want to do and it'll have a better chance to execute it.
Do not mix assertions, with force clicks, with reloads in the same line of action! The prompt needs to go through, so in a way try to act as a prompt engineer and step by step you'll get there.
3) You can have up to 20 steps for each prompt you execute
20 is the limit, ok. But that doesn't mean that you need to have 20 steps each prompt. Also, the more steps you add, the prone it is to ask for clarifications or make mistakes.
Think of it as this: each plain English text line you introduce is an abstraction layer, right? Do want an over-complicated test, or a easy to read through, understandable (for non-developers specially) test?
Lesser is better in some cases!
4) Leave some tests in prompt in order to validate flaky behavior
Got a new feature? Want to avoid brittle in your E2E test? Want to check for any weird behavior here and there? Then cy.prompt is your way to go! You can always leave your tests in plain English to see if the BDD/TDD behavior stays the same.
Remember: it works in both local and CI - but it only supports Chrome or Chromium browsers (Edge/Electron). Any others are out (sorry Firefox!). Leave it a few days or weeks in your CI in prompt scenario and see what happens.
5) Portability first?
For me any test that is written in plain English has a natural advantage over each other. It doesn't need to be refactored into any other programming language. So if you already know that the application you're working now is starting to be ported into another modern framework, leave your tests in prompt format. Your devs will appreaciate!
6) It's always cached
Another advantage with cy.prompt is that once it runs, it will cache the steps in order to avoid LLM interaction. But if you change one line in your prompt - wait 15 seconds instead of 8, for example - it will execute all over again.
Remember this to focus on speed and reliability in your tests!

Top comments (0)