> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/contributor/contributor-zh/gong-xian-zhe-zhi-nan/testing-standards/testing-e2e.md).

# 测试端到端

{% hint style="info" %}
本节目前处于进行中（WIP）状态。
{% endhint %}

本节描述开发者将如何测试与 e2e 测试相关的代码库。

## 测试栈

我们所有的 UI 测试都必须使用 [Cypress](https://www.cypress.io/) 作为主要测试框架，并结合 [Synpress](https://github.com/Synthetixio/synpress) 用于钱包支持。测试代码必须使用 [Typescript](https://www.typescriptlang.org/) 编写，并使用 [ts-jest](https://github.com/kulshekhar/ts-jest) 运行，以获得类型检查支持。

## 目录结构

新测试必须放在 `tests/e2e` 目录中，位于根路径下。文件将以其所测试的流程命名，也就是说，如果 e2e 测试文件要测试 `合集发布` 流程，则文件名必须是 `collection-publication.spec.cy.ts`.

## 运行频率

通过 GitHub Actions 计划运行。频率待定。

## 测试什么

* dApp 中最相关的用户交互（商品发布、NFT 购买等）

## 如何测试

我们的所有测试都必须遵循 **Given-When-Then** （GWT）

以下示例：

1. **假设** 用户访问 `https://example.cypress.io`
2. **当** 他们点击标记为 `类型`
3. 并且他们在 `[data-testid="action-email"]` 输入框中输入 "<fake@email.com>"
4. **然后** URL 应包含 `/commands/actions`
5. 并且 `[data-testid="action-email"]` 输入框的值应为 "<fake@email.com>"

应写为：

```jsx
describe('假设用户访问 https://example.cypress.io', () => {
  beforeEach(() => {
    cy.visit('https://example.cypress.io')
  })

  describe('当点击标记为 type 的链接时', () => {
    beforeEach(() => {
      cy.contains('type').click()
    })

    describe('并在 action-email 输入框中输入电子邮件时', () => {
      beforeEach(() => {
        // 获取一个输入框，并在其中输入
        cy.get('.action-email').type('fake@email.com')
      })

      it('那么 URL 应包含 /commands/actions', () => {
        // 应该位于一个新的 URL 上，其中
        // 包含 '/commands/actions'
        cy.url().should('include', '/commands/actions')
      })

      it('并且 action-email 输入框的值应包含输入的电子邮件', () => {
        // 验证值已更新
        cy.get('.action-email').should('have.value', 'fake@email.com')
      })
    })
  })
})
```

## 测试智能合约

如需测试智能合约，请参阅 Solidity 标准文档。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/contributor/contributor-zh/gong-xian-zhe-zhi-nan/testing-standards/testing-e2e.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
