@bettergi/utils 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/dist/http.d.ts +6 -6
- package/dist/http.js +10 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,22 +126,32 @@ await assertRegionDisappearing(findButton, "点击购买按钮超时", () => fin
|
|
|
126
126
|
> 对常见鼠标操作的封装,如鼠标的平滑移动、鼠标滚轮滚动、鼠标拖拽等。
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
|
-
//
|
|
130
|
-
await
|
|
129
|
+
// 鼠标沿路径点移动并拖拽
|
|
130
|
+
await mouseMoveAlongWaypoints(
|
|
131
|
+
[
|
|
132
|
+
{ x: 100, y: 100 },
|
|
133
|
+
{ x: 200, y: 200 },
|
|
134
|
+
{ x: 300, y: 300 }
|
|
135
|
+
],
|
|
136
|
+
{ shouldDrag: true }
|
|
137
|
+
);
|
|
131
138
|
|
|
132
139
|
// 鼠标从 (745, 610) 拖拽到 (1280, 610)
|
|
133
140
|
await mouseDrag(745, 610, 1280, 610);
|
|
134
141
|
|
|
142
|
+
// 鼠标从 (745, 610) 平滑自然地移动 (1920, 1080)
|
|
143
|
+
await naturalMouseMove(745, 610, 1920, 1080);
|
|
144
|
+
|
|
135
145
|
// 鼠标滚轮向上滚动 175 像素
|
|
136
146
|
await mouseScrollUp(175);
|
|
137
147
|
|
|
138
148
|
// 鼠标滚轮向下滚动 175 像素
|
|
139
149
|
await mouseScrollDown(175);
|
|
140
150
|
|
|
141
|
-
// 鼠标滚轮向上滚动 99
|
|
151
|
+
// 鼠标滚轮向上滚动 99 行(默认: 175为背包物品行高)
|
|
142
152
|
await mouseScrollUpLines(99);
|
|
143
153
|
|
|
144
|
-
// 鼠标滚轮向下滚动 1
|
|
154
|
+
// 鼠标滚轮向下滚动 1 行(自定义: 115为商店物品行高)
|
|
145
155
|
await mouseScrollDownLines(1, 115);
|
|
146
156
|
```
|
|
147
157
|
|
|
@@ -201,12 +211,14 @@ tracker.complete(`任务完成`);
|
|
|
201
211
|
|
|
202
212
|
```ts
|
|
203
213
|
// 发送 GET 请求获取响应体内容
|
|
204
|
-
const body1 = await getForBody("https://
|
|
205
|
-
log.info(`GET 请求响应体内容${body1}`);
|
|
214
|
+
const body1 = await getForBody("https://jsonplaceholder.typicode.com/todos/1");
|
|
206
215
|
|
|
207
216
|
// 发送 POST 请求获取响应体内容
|
|
208
|
-
const body2 = await postForBody("https://
|
|
209
|
-
|
|
217
|
+
const body2 = await postForBody("https://jsonplaceholder.typicode.com/posts", {
|
|
218
|
+
title: "foo",
|
|
219
|
+
body: "bar",
|
|
220
|
+
userId: 1
|
|
221
|
+
});
|
|
210
222
|
```
|
|
211
223
|
|
|
212
224
|
### 文件操作
|
package/dist/http.d.ts
CHANGED
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
* 发送 HTTP 请求,获取响应体内容
|
|
3
3
|
* @param method 请求方法
|
|
4
4
|
* @param url 请求 URL
|
|
5
|
-
* @param body
|
|
5
|
+
* @param body 请求体(UTF-8 编码)
|
|
6
6
|
* @param headers 请求头
|
|
7
7
|
* @returns 响应体内容
|
|
8
8
|
*/
|
|
9
|
-
export declare const requestForBody: (method: Parameters<typeof http.request>[0], url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
|
|
9
|
+
export declare const requestForBody: (method: Parameters<typeof http.request>[0], url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
|
|
10
10
|
/**
|
|
11
11
|
* 发送 HTTP GET 请求,获取响应体内容
|
|
12
12
|
* @param url 请求 URL
|
|
13
|
-
* @param body
|
|
13
|
+
* @param body 请求体(UTF-8 编码)
|
|
14
14
|
* @param headers 请求头
|
|
15
15
|
* @returns 响应体内容
|
|
16
16
|
*/
|
|
17
|
-
export declare const getForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
|
|
17
|
+
export declare const getForBody: (url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
|
|
18
18
|
/**
|
|
19
19
|
* 发送 HTTP POST 请求,获取响应体内容
|
|
20
20
|
* @param url 请求 URL
|
|
21
|
-
* @param body
|
|
21
|
+
* @param body 请求体(UTF-8 编码)
|
|
22
22
|
* @param headers 请求头
|
|
23
23
|
* @returns 响应体内容
|
|
24
24
|
*/
|
|
25
|
-
export declare const postForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
|
|
25
|
+
export declare const postForBody: (url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
|
package/dist/http.js
CHANGED
|
@@ -2,33 +2,37 @@
|
|
|
2
2
|
* 发送 HTTP 请求,获取响应体内容
|
|
3
3
|
* @param method 请求方法
|
|
4
4
|
* @param url 请求 URL
|
|
5
|
-
* @param body
|
|
5
|
+
* @param body 请求体(UTF-8 编码)
|
|
6
6
|
* @param headers 请求头
|
|
7
7
|
* @returns 响应体内容
|
|
8
8
|
*/
|
|
9
9
|
export const requestForBody = async (method, url, body, headers) => {
|
|
10
|
-
|
|
10
|
+
if (body && typeof body === "object") {
|
|
11
|
+
body = JSON.stringify(body);
|
|
12
|
+
headers = { ...headers, "Content-Type": "application/json" };
|
|
13
|
+
}
|
|
14
|
+
const resp = await http.request(method, url, body ?? null, headers ? JSON.stringify(headers) : null);
|
|
11
15
|
if (resp.status_code >= 200 && resp.status_code < 400) {
|
|
12
16
|
return resp.body;
|
|
13
17
|
}
|
|
14
18
|
else {
|
|
15
|
-
throw new Error(`HTTP request failed with status ${resp.status_code}`);
|
|
19
|
+
throw new Error(`HTTP request failed with status ${resp.status_code}: ${resp.body}`);
|
|
16
20
|
}
|
|
17
21
|
};
|
|
18
22
|
/**
|
|
19
23
|
* 发送 HTTP GET 请求,获取响应体内容
|
|
20
24
|
* @param url 请求 URL
|
|
21
|
-
* @param body
|
|
25
|
+
* @param body 请求体(UTF-8 编码)
|
|
22
26
|
* @param headers 请求头
|
|
23
27
|
* @returns 响应体内容
|
|
24
28
|
*/
|
|
25
|
-
export const getForBody =
|
|
29
|
+
export const getForBody = (url, body, headers) => {
|
|
26
30
|
return requestForBody("GET", url, body, headers);
|
|
27
31
|
};
|
|
28
32
|
/**
|
|
29
33
|
* 发送 HTTP POST 请求,获取响应体内容
|
|
30
34
|
* @param url 请求 URL
|
|
31
|
-
* @param body
|
|
35
|
+
* @param body 请求体(UTF-8 编码)
|
|
32
36
|
* @param headers 请求头
|
|
33
37
|
* @returns 响应体内容
|
|
34
38
|
*/
|