woocommerce/packages/js/e2e-utils-playwright/zh-cn/README.md
2026-04-15 10:18:01 +08:00

76 lines
No EOL
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# WooCommerce 端到端测试工具
此包包含使用 Playwright 编写 WooCommerce 专用端到端测试的工具。
> [!警告]
>
> 此包仍在积极开发中。
> 文档可能不是最新的0.x 版本可能会引入破坏性变更。
## 安装
```bash
npm install @woocommerce/e2e-utils-playwright --save-dev
```
## 用法
示例:
```js
import { addAProductToCart } from '@woocommerce/e2e-utils-playwright';
test('can add products to cart', async ({ page }) => {
const product = {
id: 1,
name: 'Test Product',
};
await addAProductToCart(page, product.id);
await page.goto('/cart/');
await expect(page.locator('td.product-name')).toContainText(product.name);
});
```
## API 客户端
此包提供了一个 API 客户端工具,用于向 WooCommerce REST API 发送认证请求。
### 基本认证示例
```js
import { createClient } from '@woocommerce/e2e-utils-playwright';
const client = createClient('http://localhost:8889/', {
type: 'basic',
username: 'admin',
password: 'password',
});
const response = await client.get('wc/v3/products');
console.log(response.data);
```
### OAuth1 示例
```js
import { createClient } from '@woocommerce/e2e-utils-playwright';
const client = createClient('http://localhost:8889/', {
type: 'oauth1',
consumerKey: 'ck_xxx',
consumerSecret: 'cs_xxx',
});
const response = await client.get('wc/v3/products');
console.log(response.data);
```
支持的方法:`get(path, params, debug)`, `post(path, data, debug)`, `put(path, data, debug)`, `delete(path, params, debug)`
## 为此包做贡献
这是 WooCommerce 项目中的一个独立包,该项目采用 monorepo 结构组织。
要了解更多关于为此包或整个 WooCommerce 项目做贡献的信息,请阅读项目的主要[贡献者指南](https://developer.woocommerce.com/docs/category/contributing/)。