---
title: Cypress 与 Selenium：您应该选择哪一个？ | TestingBot
description: Cypress 与 Selenium 的正面对比：架构、语言支持、浏览器覆盖范围、并行执行、调试和迁移。可在 TestingBot 云端的
  6100+ 款真实浏览器上运行任意一个。
source_url:
  html: https://zh.testingbot.com/cypress-vs-selenium
  md: https://zh.testingbot.com/cypress-vs-selenium.md
---

框架比较 · 2026 
# Cypress vs Selenium

Cypress 和 Selenium 对浏览器测试采取了截然相反的方式：一个在浏览器内部运行，另一个则从外部驱动浏览器。本指南将从架构、语言、浏览器覆盖范围、并行化和调试等方面对它们进行全面比较，并提供代码示例和结论，让您在五分钟内即可付诸行动。

[在 TestingBot 上运行这两个程序](https://zh.testingbot.com/users/sign_up) [跳转至对比](https://zh.testingbot.com#comparison)

- **浏览器和设备:** 6100+
- **云并行:** 100×
- **正常运行时间服务级别协议:** 99.9%

## 被世界上一些最具创新性的公司所信任

 30 秒回答 
## 你应该选哪一个？

 ![Cypress](https://zh.testingbot.com/assets/support/cypress-409c9fd3f79115ed7676aa1df4f6a217dc4402b3366a61984924aec7b4fefa97.svg) 选择 Cypress，如果……

您的团队使用 JavaScript 或 TypeScript 编写代码，您在 Chrome、Edge 或 Firefox 上测试现代 Web 应用，并且您希望获得最佳的开发者体验，包括内置重试、时间旅行调试以及自带的测试运行器。

 ![Selenium](https://zh.testingbot.com/assets/support/selenium-266ecc0599068fc6eca0bcd9174fb46053c95cebe1c66f7a50c480f3f1a52929.svg) 如果……，请选择 Selenium。

您的团队使用 Java、C# 或 Ruby 编写代码，您需要支持旧版浏览器（Internet Explorer、Safari）、通过 Appium 使用真实移动设备，或者需要 Cypress 无法处理的多标签和跨域流程。

如果……，请两者都选。

您希望使用 Cypress 进行快速的组件和前端测试，并使用 Selenium 实现广泛的跨浏览器和移动设备覆盖。TestingBot 可以在同一个网格上、并行地、在一个仪表板中运行两者。

 背景 
## Cypress 和 Selenium 是什么？

两种框架，两种架构。目标相同：驱动浏览器实现端到端测试自动化。

 ![Cypress](https://zh.testingbot.com/assets/support/cypress-409c9fd3f79115ed7676aa1df4f6a217dc4402b3366a61984924aec7b4fefa97.svg)

### Cypress

发布于 2017 年 · Cypress.io · MIT

Cypress 是一个 JavaScript 端到端测试框架，它在浏览器内部运行您的测试，与您的应用程序处于同一个运行循环中。这种架构使它能够直接访问 DOM，并开箱即用地实现自动等待和时间旅行快照。

由于它运行在浏览器内部，Cypress 拥有出色的开发者体验：自带的测试运行器、实时重载和可视化调试器。同样的架构也将它限制在 JavaScript 和 TypeScript、一组固定的浏览器以及单标签流程之内。

- 仅支持 JavaScript 和 TypeScript
- 自动重试、时间旅行调试、cy.intercept
- Chrome、Edge、Firefox、Electron · 不支持 IE / Safari

 ![Selenium](https://zh.testingbot.com/assets/support/selenium-266ecc0599068fc6eca0bcd9174fb46053c95cebe1c66f7a50c480f3f1a52929.svg)

### Selenium

发布于 2004 年 · 开源 · Apache 2.0

Selenium 是最初的浏览器自动化框架，也是 W3C WebDriver 标准的基础。Selenium WebDriver 通过供应商提供的驱动程序（chromedriver、geckodriver、safaridriver、edgedriver）使用相同的网络协议从外部驱动任何浏览器。

二十年的生态系统成熟意味着它为每一种主流语言提供绑定、拥有深度 IDE 集成、成熟的 Page Object 模式，以及通过 Appium 进行的真实移动设备测试，而 Appium 正是构建在同一协议之上的。

- Java / Python / C# / Ruby / JavaScript / Kotlin
- W3C WebDriver 标准，适用于所有浏览器
- Chrome、Firefox、Safari、Edge、IE 11 · 通过 Appium 支持真实移动设备

 正面交锋 
## Cypress 与 Selenium：并排比较

在 CI 中选择、迁移或同时运行两者时需要考虑的各个重要维度。

Cypress versus Selenium feature comparison| 方面 | Cypress | Selenium |
| --- | --- | --- |
| First release | 2017 | 2004 |
| Maintained by | Cypress.io | Open-source community + W3C |
| Languages | JavaScript / TypeScript only | Java, Python, C#, Ruby, JS, Kotlin |
| Architecture | Runs inside the browser | Drives the browser via WebDriver |
| Browsers | Chrome, Edge, Firefox, Electron | Chrome, Firefox, Safari, Edge, IE 11 |
| Mobile testing | Viewport emulation only | Real iOS + Android via Appium |
| Auto-waiting | Built-in retries | Manual waits or WebDriverWait |
| Network stubbing | First-class (cy.intercept) | BiDi (Selenium 4) or proxy |
| Multiple tabs / windows | Not supported | Window switching API |
| Cross-origin | cy.origin() (constrained) | Native |
| Test runner | Built in | Bring your own (JUnit, pytest, Mocha…) |
| Debugging | Time-travel snapshots + runner | IDE + driver logs |
| Parallel execution | Cypress Cloud (paid) or a grid | Selenium Grid |
| Developer experience | Real-time reload, in-browser | Functional, IDE-based |
| Ecosystem maturity | Growing fast since 2017 | 20 years of integrations |
| Free for open source on TestingBot | ✓ | ✓ |

功能说明反映了截至 2026 年的 Cypress 13.x 和 Selenium 4.x。这两个框架均运行在 TestingBot 的云端，Cypress 通过 testingbot-cypress-cli 运行，Selenium 通过 WebDriver hub 运行。

 两者的测试相同 
## 登录并断言结果

使用内置重试（Cypress）和显式等待（Selenium）的登录流程。两者均在同一个 TestingBot 测试网格上运行。

Cypress + TypeScript login.cy.ts

```typescript
// run via: testingbot-cypress run
describe('login', () => {
  it('redirects to the dashboard', () => {
    cy.visit('https://app.example.com/login');

    // auto-retries until actionable
    cy.get('#username').type('jane@example.com');
    cy.get('#password').type('••••••••');
    cy.contains('button', 'Sign in').click();

    cy.url().should('include', '/dashboard');
    cy.contains('h1', /welcome, jane/i).should('be.visible');
  });
});
```

Selenium + Python test\_login.py

```python
# Driver points at TestingBot remote URL
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def test_login_redirects_to_dashboard(driver):
    driver.get('https://app.example.com/login')

    driver.find_element(By.NAME, 'username').send_keys('jane@example.com')
    driver.find_element(By.NAME, 'password').send_keys('••••••••')
    driver.find_element(By.CSS_SELECTOR, 'button[type=submit]').click()

    # explicit wait
    WebDriverWait(driver, 10).until(EC.url_contains('/dashboard'))
    welcome = driver.find_element(By.TAG_NAME, 'h1')
    assert 'Welcome, Jane' in welcome.text
```

Cypress 规范通过 [testingbot-cypress-cli](https://zh.testingbot.com/support/web-automate/cypress) 运行；Selenium 测试连接到 [WebDriver hub](https://zh.testingbot.com/support/web-automate/selenium)。两者都显示在同一个 TestingBot 仪表板中。

 决策矩阵 
## 何时选择哪个

### 选择 Cypress 时

- 您的技术栈以 JavaScript 或 TypeScript 为先，并且您希望测试运行器、断言和重试功能随框架一同提供。
- 您正在 Chrome、Edge 或 Firefox 上测试现代 Web 应用，没有 Internet Explorer 或 Safari 的需求。
- 您看重开发者体验：时间旅行调试、实时重载和可读的失败快照。
- 您希望使用 cy.intercept 实现一流的网络桩，而无需外挂代理。
- 您的流程保持在单个标签内，并且大多在单个源内（cy.origin 有所帮助，但有一定限制）。

[在 TestingBot 上运行 Cypress](https://zh.testingbot.com/features/automation/cypress)

### 选择 Selenium 时

- 您的团队使用 Java、C#、Ruby 或 Python 编写代码，并且您希望完整的绑定一致性，而不是以 JavaScript 为先的 API。
- 您需要在 Internet Explorer 11、Safari 或 Cypress 不支持的浏览器构建上进行测试。
- 您测试真实的 iOS 和 Android 设备，而 Appium 复用了 Selenium 所构建于其上的 WebDriver 协议。
- 您的测试会打开多个标签或窗口，或者跨越多个源，而 Cypress 仅能部分处理这些情况。
- 您拥有成熟的 Page Object 库或 BDD 框架（Cucumber、SpecFlow），不想重写它们。

[在 TestingBot 上运行 Selenium](https://zh.testingbot.com/features/automation/selenium)

 TestingBot 同时支持这两种模式 
## 停止选择，在同一网格上运行两者

通过 testingbot-cypress-cli 运行 Cypress，并将 Selenium 指向 WebDriver hub。您的测试将共享相同的 6100+ 浏览器和设备、相同的仪表板、相同的并行槽位和相同的欧盟数据驻留，且无需 Cypress Cloud 订阅。

- 无需 Cypress Cloud 计划即可实现 Cypress 并行化
- 两个框架的并排测试历史记录
- 免费开源——这两个框架都是如此

[免费开始](https://zh.testingbot.com/users/sign_up) [申请演示](https://testingbot.com/demo)

testingbot.com / run both

// Cypress

$ npm i -D testingbot-cypress-cli

$ testingbot-cypress run # reads testingbot.json

# Selenium

webdriver.Remote(  
command\_executor='https://hub.testingbot.com/wd/hub'  
)

 常问问题 
## 常见问题解答

团队在选择（或在这些框架之间迁移）这些框架之前会提出的问题。

Cypress 比 Selenium 更好吗？

两者没有谁普遍更好；它们适合不同的团队。对于测试现代 Web 应用的 JavaScript 和 TypeScript 团队，Cypress 在开发者体验上胜出：内置重试、时间旅行调试以及自带的测试运行器。Selenium 在广度上胜出：更多语言、包括 Internet Explorer 和 Safari 在内的所有浏览器、通过 Appium 支持真实移动设备，以及多标签和跨域流程。在其约束范围内追求人体工程学时选择 Cypress；追求覆盖范围和灵活性时选择 Selenium。

我应该从 Selenium 迁移到 Cypress 吗？

仅当您的需求符合 Cypress 的约束时才值得迁移。如果您的测试套件基于 JavaScript，针对 Chrome、Edge 或 Firefox，并且保持在单个标签内，那么 Cypress 的重试和调试功能通常足以证明这次迁移是值得的。如果您依赖 Java、C# 或 Ruby，需要测试 Internet Explorer 或 Safari，驱动真实移动设备，或者需要多标签和跨域流程，那么迁移会让您损失一些功能。许多团队会同时保留两者：Cypress 用于前端测试，Selenium 用于广泛的跨浏览器和移动设备覆盖。

Cypress 是否支持 Selenium 支持的所有浏览器？

不。Cypress 运行在基于 Chromium 的浏览器（Chrome、Edge、Electron）和 Firefox 上，并提供实验性的 WebKit 支持。它无法驱动 Internet Explorer 或真实的 Safari。Selenium 通过供应商提供的驱动程序驱动实际的浏览器二进制文件，包括 Internet Explorer 11 和 Safari。如果您需要 IE 或 Safari 覆盖范围，那么在两者之中 Selenium 是唯一的选择。

Cypress 可以测试移动应用吗？

本身并不支持。Cypress 提供视口调整功能来模拟移动屏幕，但它无法驱动原生 iOS 或 Android 应用。要进行真正的移动应用测试，您需要 [Appium](https://zh.testingbot.com/features/automation/appium)、[XCUITest](https://zh.testingbot.com/features/automation/xcuitest)、[Espresso](https://zh.testingbot.com/features/automation/espresso) 或 [Maestro](https://zh.testingbot.com/features/automation/maestro)。Appium 复用了 Selenium 所构建于其上的 WebDriver 协议。TestingBot 可在真实的 iOS 和 Android 设备上运行所有这些工具。

我需要 Cypress Cloud 才能并行运行 Cypress 吗？

不。Cypress 自身的并行化和录制功能通过 Cypress Cloud 运行，这是一项付费订阅。TestingBot 是一个替代方案：testingbot-cypress-cli 会打包您的规范、上传它们，并在云端网格上跨 Chrome、Edge 和 Firefox 并行运行，提供实时日志和视频，且无需 Cypress Cloud 计划。您可以在 testingbot.json 中设置并行数量。

Cypress 和 Selenium 可以共享同一个 CI 管道吗？

可以。两者都在 CI/CD 中运行，并将结果报告回 TestingBot 上的同一位置。一种常见的设置是在同一个管道中运行 Cypress 进行快速的前端规范测试，并运行 Selenium 实现广泛的跨浏览器和移动设备覆盖，两者都指向 TestingBot 网格，使用相同的凭据和构建名称。

我可以在 TestingBot 上运行 Cypress 和 Selenium 吗？

是的，两者都运行在同一个 TestingBot 云平台上。Cypress 通过 `testingbot-cypress-cli` npm 包运行，使用 `testingbot.json` 文件进行配置，并通过 `testingbot-cypress run` 启动。Selenium 通过 `webdriver.Remote` 连接到 `https://hub.testingbot.com/wd/hub`。两者的测试都显示在同一个仪表板中，共享并行槽位，并受益于相同的欧盟数据驻留、视频录制和 CI/CD 集成。两者都对开源项目免费开放。

想深入了解？请参阅专门的 [Cypress](https://zh.testingbot.com/features/automation/cypress) 和 [Selenium](https://zh.testingbot.com/features/automation/selenium) 页面。

## Related comparisons
[Cypress vs Playwright](https://zh.testingbot.com/cypress-vs-playwright) [Playwright vs Selenium](https://zh.testingbot.com/playwright-vs-selenium)

### 注册免费试用

在 TestingBot 的云端运行 Cypress、Selenium 或两者都运行。无需 Cypress Cloud 订阅。

[开始免费试用](https://zh.testingbot.com/users/sign_up)

您可能喜欢的资源

[![Tutorial on debugging Cypress tests](https://zh.testingbot.com/assets/resources/articles/10-7ae9f6d9435bea1c54ec815ad535dc4a590086e6165263a9eba3441635d55726.webp)](https://testingbot.com/resources/articles/how-to-debug-cypress-tests)
### [Tutorial on debugging Cypress tests](https://testingbot.com/resources/articles/how-to-debug-cypress-tests)

This article will focus on how to debug your Cypress tests with Cypress debugger and other developer tools.

[阅读更多](https://testingbot.com/resources/articles/how-to-debug-cypress-tests)

[![Selenium and Generative AI](https://zh.testingbot.com/assets/resources/articles/28-af707bf052844eb00f861bb6ebba57e6be4479dde1c78a5df4e70d2f597a8b18.webp)](https://testingbot.com/resources/articles/generative-ai-selenium)
### [Selenium and Generative AI](https://testingbot.com/resources/articles/generative-ai-selenium)

Generate realistic looking test data to be used with your Selenium Automated Tests.

[阅读更多](https://testingbot.com/resources/articles/generative-ai-selenium)

[![Cypress and Cucumber Browser Testing](https://zh.testingbot.com/assets/resources/articles/6-495c5e14cb4bf1e282858fc7e2cfcbe89775e3790b88d34c15bf9a6f36d387d4.webp)](https://testingbot.com/resources/articles/cypress-cucumber-testing)
### [Cypress and Cucumber Browser Testing](https://testingbot.com/resources/articles/cypress-cucumber-testing)

Cypress and Cucumber is a great combination to write clean and precise end-to-end browser tests.

[阅读更多](https://testingbot.com/resources/articles/cypress-cucumber-testing)
