agent-browser 0.3.1 → 0.3.3

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.
@@ -1,216 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { parseCommand } from './protocol.js';
3
-
4
- // Helper to create command JSON string
5
- const cmd = (obj: object) => JSON.stringify(obj);
6
-
7
- describe('parseCommand', () => {
8
- describe('navigation', () => {
9
- it('should parse navigate command', () => {
10
- const result = parseCommand(cmd({ id: '1', action: 'navigate', url: 'https://example.com' }));
11
- expect(result.success).toBe(true);
12
- if (result.success) {
13
- expect(result.command.action).toBe('navigate');
14
- expect(result.command.url).toBe('https://example.com');
15
- }
16
- });
17
-
18
- it('should reject navigate without url', () => {
19
- const result = parseCommand(cmd({ id: '1', action: 'navigate' }));
20
- expect(result.success).toBe(false);
21
- });
22
- });
23
-
24
- describe('click', () => {
25
- it('should parse click command', () => {
26
- const result = parseCommand(cmd({ id: '1', action: 'click', selector: '#btn' }));
27
- expect(result.success).toBe(true);
28
- if (result.success) {
29
- expect(result.command.action).toBe('click');
30
- expect(result.command.selector).toBe('#btn');
31
- }
32
- });
33
-
34
- it('should reject click without selector', () => {
35
- const result = parseCommand(cmd({ id: '1', action: 'click' }));
36
- expect(result.success).toBe(false);
37
- });
38
- });
39
-
40
- describe('type', () => {
41
- it('should parse type command', () => {
42
- const result = parseCommand(
43
- cmd({ id: '1', action: 'type', selector: '#input', text: 'hello' })
44
- );
45
- expect(result.success).toBe(true);
46
- if (result.success) {
47
- expect(result.command.action).toBe('type');
48
- expect(result.command.selector).toBe('#input');
49
- expect(result.command.text).toBe('hello');
50
- }
51
- });
52
- });
53
-
54
- describe('fill', () => {
55
- it('should parse fill command', () => {
56
- const result = parseCommand(
57
- cmd({ id: '1', action: 'fill', selector: '#input', value: 'hello' })
58
- );
59
- expect(result.success).toBe(true);
60
- if (result.success) {
61
- expect(result.command.action).toBe('fill');
62
- expect(result.command.value).toBe('hello');
63
- }
64
- });
65
- });
66
-
67
- describe('wait', () => {
68
- it('should parse wait with selector', () => {
69
- const result = parseCommand(cmd({ id: '1', action: 'wait', selector: '#loading' }));
70
- expect(result.success).toBe(true);
71
- });
72
-
73
- it('should parse wait with timeout', () => {
74
- const result = parseCommand(cmd({ id: '1', action: 'wait', timeout: 5000 }));
75
- expect(result.success).toBe(true);
76
- });
77
-
78
- it('should parse wait with text', () => {
79
- const result = parseCommand(cmd({ id: '1', action: 'wait', text: 'Welcome' }));
80
- expect(result.success).toBe(true);
81
- });
82
- });
83
-
84
- describe('screenshot', () => {
85
- it('should parse screenshot command', () => {
86
- const result = parseCommand(cmd({ id: '1', action: 'screenshot', path: 'test.png' }));
87
- expect(result.success).toBe(true);
88
- });
89
-
90
- it('should parse screenshot with fullPage', () => {
91
- const result = parseCommand(cmd({ id: '1', action: 'screenshot', fullPage: true }));
92
- expect(result.success).toBe(true);
93
- });
94
- });
95
-
96
- describe('cookies', () => {
97
- it('should parse cookies_get', () => {
98
- const result = parseCommand(cmd({ id: '1', action: 'cookies_get' }));
99
- expect(result.success).toBe(true);
100
- });
101
-
102
- it('should parse cookies_set', () => {
103
- const result = parseCommand(
104
- cmd({
105
- id: '1',
106
- action: 'cookies_set',
107
- cookies: [{ name: 'session', value: 'abc123' }],
108
- })
109
- );
110
- expect(result.success).toBe(true);
111
- });
112
-
113
- it('should parse cookies_clear', () => {
114
- const result = parseCommand(cmd({ id: '1', action: 'cookies_clear' }));
115
- expect(result.success).toBe(true);
116
- });
117
- });
118
-
119
- describe('storage', () => {
120
- it('should parse storage_get', () => {
121
- const result = parseCommand(cmd({ id: '1', action: 'storage_get', type: 'local' }));
122
- expect(result.success).toBe(true);
123
- });
124
-
125
- it('should parse storage_set', () => {
126
- const result = parseCommand(
127
- cmd({
128
- id: '1',
129
- action: 'storage_set',
130
- type: 'local',
131
- key: 'test',
132
- value: 'value',
133
- })
134
- );
135
- expect(result.success).toBe(true);
136
- });
137
- });
138
-
139
- describe('semantic locators', () => {
140
- it('should parse getbyrole', () => {
141
- const result = parseCommand(
142
- cmd({
143
- id: '1',
144
- action: 'getbyrole',
145
- role: 'button',
146
- subaction: 'click',
147
- })
148
- );
149
- expect(result.success).toBe(true);
150
- });
151
-
152
- it('should parse getbytext', () => {
153
- const result = parseCommand(
154
- cmd({
155
- id: '1',
156
- action: 'getbytext',
157
- text: 'Submit',
158
- subaction: 'click',
159
- })
160
- );
161
- expect(result.success).toBe(true);
162
- });
163
-
164
- it('should parse getbylabel', () => {
165
- const result = parseCommand(
166
- cmd({
167
- id: '1',
168
- action: 'getbylabel',
169
- label: 'Email',
170
- subaction: 'fill',
171
- value: 'test@test.com',
172
- })
173
- );
174
- expect(result.success).toBe(true);
175
- });
176
- });
177
-
178
- describe('tabs', () => {
179
- it('should parse tab_new', () => {
180
- const result = parseCommand(cmd({ id: '1', action: 'tab_new' }));
181
- expect(result.success).toBe(true);
182
- });
183
-
184
- it('should parse tab_list', () => {
185
- const result = parseCommand(cmd({ id: '1', action: 'tab_list' }));
186
- expect(result.success).toBe(true);
187
- });
188
-
189
- it('should parse tab_switch', () => {
190
- const result = parseCommand(cmd({ id: '1', action: 'tab_switch', index: 0 }));
191
- expect(result.success).toBe(true);
192
- });
193
-
194
- it('should parse tab_close', () => {
195
- const result = parseCommand(cmd({ id: '1', action: 'tab_close' }));
196
- expect(result.success).toBe(true);
197
- });
198
- });
199
-
200
- describe('invalid commands', () => {
201
- it('should reject unknown action', () => {
202
- const result = parseCommand(cmd({ id: '1', action: 'unknown' }));
203
- expect(result.success).toBe(false);
204
- });
205
-
206
- it('should reject missing id', () => {
207
- const result = parseCommand(cmd({ action: 'click', selector: '#btn' }));
208
- expect(result.success).toBe(false);
209
- });
210
-
211
- it('should reject invalid JSON', () => {
212
- const result = parseCommand('not json');
213
- expect(result.success).toBe(false);
214
- });
215
- });
216
- });