用自然语言编写 Cypress 测试,使用 Cy.prompt()
Write Cypress Tests in Natural Language with Cy.prompt()

原始链接: https://www.cypress.io/blog/cy-prompt-experimental-launch

## Cypress推出AI驱动的测试功能 `cy.prompt()` Cypress发布了`cy.prompt()`,一项实验性功能,将AI辅助直接融入其测试流程。针对现有AI测试工具的不足——不稳定、不透明和缺乏可靠性,`cy.prompt()`允许用户用自然语言编写测试,将用户旅程的描述转化为可执行的Cypress命令。 此功能极大地加快了测试创建速度,降低了对编码知识的门槛。产品经理和质量保证专家可以直接参与,促进协作并提高测试覆盖率。重要的是,`cy.prompt()`优先考虑透明度;每一步都可以在命令日志中看到,并且可以“弹出”为标准的Cypress代码进行编辑和维护。 除了易用性之外,`cy.prompt()`还引入了自愈能力,自动调整选择器以适应UI更改,并减少测试维护。这种AI驱动的弹性确保了测试即使在前端更新后也能保持稳定和可靠。 目前,`cy.prompt()` 随Cypress Cloud帐户免费提供,旨在结合AI的速度和人工编写测试的信任与治理,标志着朝着更易访问和更强大的端到端测试迈出了重要一步。

Cypress.io 推出 `Cy.prompt()`,一项新功能,允许用户使用自然语言编写测试。这不仅仅是便利性的问题,它代表了测试创建方式的转变,旨在弥合期望的覆盖范围和实际测试代码之间的差距。 Hacker News 上的早期讨论强调了该工具的潜在力量,一些人认为它最适合用于初始测试生成,然后进行手动完善以确保确定性。一个关键的好处是,AI 能够适应应用程序的变化*而无需*重新生成测试——这是传统测试中常见的痛点。 此外,用户推测它充当一种模糊测试的形式,以不同的方式测试相同的功能,由于其非确定性,可能发现隐藏的错误。
相关文章

原文

You've seen the previews. You’ve heard the buzz. And now it’s official: cy.prompt() is live and available to everyone as an experimental feature. Announced live on stage at CypressConf 2025 by founder Brian Mann, cy.prompt()’s entrance into the Cypress API marks a first step into the future of AI-assisted testing.

Update: The recording of Brian Mann's CypressConf 2025 talk is now available.


The Problem

Modern AI has promised to make test automation easier, but until now, the reality has often fell short. Many AI-based testing tools weren’t built with testing in mind. They often guess at app behavior, generate scripts without evaluating them in a live browser, and mask test intent behind opaque layers. This can lead to flakiness, slow execution, and poor debuggability, especially when the AI becomes the judge of correctness instead of the test author. With cy.prompt(), Cypress takes a different approach by putting AI directly into your Cypress workflow in a way that’s fast, reliable, and transparent. 

Write Tests in Natural Language, in Seconds

With cy.prompt(), you can go from an idea to a running test in seconds by simply describing the user journey in plain language.

cy.prompt([
  "Visit https://aicotravel.co",
  "Type 'Paris' in the destination field",
  "Click on the first search result",
  "Select 4 days from the duration dropdown",
  "Press the **Create Itinerary** button"
])

Each step is translated into real Cypress commands like cy.visit(), cy.get(), and cy.click(), and executed in the browser with full visibility in the Command Log. 

This is not just a convenience feature. It is a new way of thinking about test creation that closes the distance between the coverage you need and the code that runs it (without exponentially increasing capacity).

Best of all, it is built to be fast, resilient, and responsive to changes in your application. That means you are not paying a big performance penalty for the convenience of natural language. Your tests still run with the speed and reliability you expect from Cypress.

Unlike some AI testing tools that require separate plugins or external applications, cy.prompt() is built directly into the Cypress app you use every day. Once you are on Cypress v15.4.0, you can get started by simply adding the experimental flag in your Cypress config and signing into your Cypress Cloud account within the App.

const { defineConfig } = require('cypress')

module.exports = defineConfig({
 e2e: {
   experimentalPromptCommand: true,
 },
})

There are no new frameworks to learn, no additional services to integrate, and no context-switching. You write your tests in the same Cypress testing environment, just with a new superpower at your disposal.

A Shared Language of Quality

One of the most exciting aspects of cy.prompt() is how it opens up test automation to a much broader audience. You no longer need deep JavaScript or Cypress expertise to write a meaningful test. If you understand the user journey, you can turn it into an automated test case.

Think about the possibilities: a product manager can write down acceptance criteria for a new feature, and that description can go straight into a Cypress test. It’s like writing your BDD-style Given/When/Then scenarios directly in the test suite. In fact, cy.prompt() lets you use BDD-style or Gherkin-like statements as test steps, aligning everyone from engineers to stakeholders on the behavior being verified. 

By lowering the barrier to automation, cy.prompt() turns testing into a team sport. QA specialists, product owners, support engineers – anyone who knows the feature can help write its tests. This not only increases coverage (more perspectives = more scenarios covered) but also fosters collaboration. 

The Speed of AI with the Peace of Mind of Human Governance

A crucial design principle of Cypress’s approach to AI is keeping you in the driver’s seat. With cy.prompt(), you always have the ability to view what’s happening in your tests. Each prompt step shows up in the Cypress Command Log, and you can click or hover to inspect exactly what happened at every step of the test run. There’s no mysterious “black box” doing magic in the background, you see every selector it chose and every action it performed, just as if you wrote the code yourself.

Most importantly, you can retrieve that code that was generated by cy.prompt() whenever you want. Cypress provides an option to eject the generated test steps into a regular test script that you can edit, commit, and maintain like any other code.

You decide how to use AI in your workflow. If you prefer to leverage cy.prompt()for boosting test authoring only, then you can eject the code. If you want to realize the full power of the command, you can commit your test code with cy.prompt() in place and realize self-healing at run time. This empowers your team to leverage AI-assisted testing in a way that fits cleanly into established processes, with no loss of trust or traceability.

Self-Healing Tests, Less Maintenance

We’ve all experienced the pain of brittle tests that break with the slightest UI change. These false failures erode confidence in your test suite over time. cy.prompt() tackles this problem head-on by introducing self-healing capabilities that make tests more resilient to front-end changes.

When Cypress generates steps from your prompt, it doesn’t rely on static selectors alone. Instead, it uses AI to understand the intent of each action and locate elements in a more adaptable way. If your markup changes, Cypress can update selectors automatically, no manual edits required.

The result is a significant reduction in test maintenance, freeing you to focus on building new tests and features. And because this self-healing runs with full visibility, every adjustment is shown in the Command Log. It’s like having a smart assistant that says, “I couldn’t find the login button by the old selector, but I noticed a new one that matches the description, so I clicked that.”

This makes your tests more robust without compromising clarity or trust. Instead of masking issues, they guard against false negatives while staying true to the user flows you’ve described. For large CI test suites, the impact is game-changing: fewer broken builds, less manual triage, and a more stable delivery pipeline.

AI-Powered Resilience You Can Trust

With cy.prompt(), Cypress is not just generating tests, it’s making them smarter and more resilient. Tests written in natural language capture the high-level intent of what should happen. Cypress uses that intent to keep the test on track, even when the underlying UI changes.

This adaptability gives cy.prompt() an edge in reliability. Tests can recover gracefully from changes that would normally break a rigid script. Cypress’s approach is rooted in collaboration between AI and testers. The AI handles the tedious parts (finding elements, adjusting to minor changes, suggesting selectors) while you guide the intent and verify outcomes.

If a real issue surfaces, like a regression or unexpected behavior, your test fails as it should. But for incidental changes, Cypress helps the test succeed without rewriting code. 

This kind of AI-powered stability means teams can move faster with confidence. When tests are easy to author and built to adapt, you can cover more ground in less time and trust that green test results reflect real app quality, not lucky escapes or brittle paths.


We believe cy.prompt() is a major leap forward in how teams approach end-to-end testing. By combining Cypress’s renowned reliability with the flexibility of AI and natural language, we’re enabling faster authoring, broader participation, and sturdier tests all at once. cy.prompt() is available now as a public experimental feature. It is free to use during this experimental phase. All you need is a Cypress Cloud account (even the free tier). Signing up gives you a free trial of our full enterprise feature set, so while you’re there, explore how Cypress Cloud can support the rest of your testing workflow.

For full details on how cy.prompt() works and how to enable it, check out our docs.

Brian Mann also gave a first look at our next step in AI-assisted testing, Studio AI, during his CypressConf Founder’s Session. If you’re interested in early access, sign up here.

联系我们 contact @ memedata.com