-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.v
More file actions
311 lines (246 loc) · 8.29 KB
/
Copy pathintegration_test.v
File metadata and controls
311 lines (246 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
module main
import x.json2 as json
import webdriver
// Integration test: Search on a website
fn test_search_flow() ! {
println('Running integration test: Search flow')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or { eprintln('Failed to quit: ${err}') }
}
// Navigate to example.com
wd.get('https://example.com')!
println('✓ Navigated to example.com')
// Verify page title
title := wd.execute_script('return document.title', [])!
assert title.str() == 'Example Domain'
println('✓ Page title verified: ${title}')
// Find and verify heading
heading := wd.find_element('css selector', 'h1')!
println('✓ Found h1 element: ${heading.element_id}')
// Get heading text using JavaScript
heading_text := wd.execute_script('return document.querySelector("h1").textContent', [])!
println('✓ Heading text: ${heading_text}')
println('✅ Search flow test passed!')
}
// Integration test: Cookie management
fn test_cookie_management() ! {
println('\nRunning integration test: Cookie management')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or {}
}
// Navigate to a page
wd.get('https://example.com')!
println('✓ Navigated to example.com')
// Add cookies
cookie1 := webdriver.Cookie{
name: 'session_id'
value: 'abc123'
path: '/'
domain: 'example.com'
}
wd.add_cookie(cookie1)!
println('✓ Added session_id cookie')
cookie2 := webdriver.Cookie{
name: 'user_pref'
value: 'dark_mode'
path: '/'
domain: 'example.com'
}
wd.add_cookie(cookie2)!
println('✓ Added user_pref cookie')
// Get all cookies
cookies := wd.get_cookies()!
println('✓ Retrieved ${cookies.len} cookies')
assert cookies.len >= 2
// Delete one cookie
wd.delete_cookie('user_pref')!
println('✓ Deleted user_pref cookie')
// Verify deletion
remaining_cookies := wd.get_cookies()!
assert remaining_cookies.len < cookies.len
println('✓ Verified cookie deletion')
// Delete all cookies
wd.delete_all_cookies()!
final_cookies := wd.get_cookies()!
assert final_cookies.len == 0
println('✓ Deleted all cookies')
println('✅ Cookie management test passed!')
}
// Integration test: Window management
fn test_window_management() ! {
println('\nRunning integration test: Window management')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or {}
}
wd.get('https://example.com')!
println('✓ Navigated to example.com')
// Get current window handle
handle := wd.get_window_handle()!
println('✓ Current window handle: ${handle}')
// Get all window handles
handles := wd.get_window_handles()!
println('✓ Total windows: ${handles.len}')
assert handles.len == 1
// Get window rect
rect := wd.get_window_rect()!
println('✓ Window size: ${rect.width}x${rect.height} at (${rect.x}, ${rect.y})')
// Resize window
new_rect := webdriver.WindowRect{
x: 0
y: 0
width: 1280
height: 720
}
wd.set_window_rect(new_rect)!
println('✓ Resized window to 1280x720')
// Verify resize
updated_rect := wd.get_window_rect()!
println('✓ New window size: ${updated_rect.width}x${updated_rect.height}')
println('✅ Window management test passed!')
}
// Integration test: JavaScript execution
fn test_javascript_execution() ! {
println('\nRunning integration test: JavaScript execution')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or {}
}
wd.get('https://example.com')!
println('✓ Navigated to example.com')
// Simple arithmetic
result1 := wd.execute_script('return 10 + 20', [])!
assert result1.int() == 30
println('✓ JavaScript arithmetic: 10 + 20 = ${result1}')
// String manipulation
result2 := wd.execute_script('return "Hello" + " " + "World"', [])!
assert result2.str() == 'Hello World'
println('✓ JavaScript string: ${result2}')
// With arguments
result3 := wd.execute_script('return arguments[0] * arguments[1]', [
json.Any(7),
json.Any(6),
])!
assert result3.int() == 42
println('✓ JavaScript with args: 7 * 6 = ${result3}')
// DOM manipulation
result4 := wd.execute_script('return document.querySelectorAll("p").length', [])!
println('✓ Found ${result4} paragraph elements')
// Get page URL
url := wd.execute_script('return window.location.href', [])!
println('✓ Current URL: ${url}')
println('✅ JavaScript execution test passed!')
}
// Integration test: Navigation
fn test_navigation_flow() ! {
println('\nRunning integration test: Navigation flow')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or {}
}
// Navigate to first page
wd.get('https://example.com')!
url1 := wd.execute_script('return window.location.href', [])!
println('✓ Page 1: ${url1}')
// Navigate to second page
wd.get('https://www.iana.org')!
url2 := wd.execute_script('return window.location.href', [])!
println('✓ Page 2: ${url2}')
// Go back
wd.back()!
url_back := wd.execute_script('return window.location.href', [])!
println('✓ Back to: ${url_back}')
// Go forward
wd.forward()!
url_forward := wd.execute_script('return window.location.href', [])!
println('✓ Forward to: ${url_forward}')
// Refresh
wd.refresh()!
println('✓ Page refreshed')
println('✅ Navigation flow test passed!')
}
// Integration test: Multiple elements
fn test_multiple_elements() ! {
println('\nRunning integration test: Multiple elements')
caps := webdriver.Capabilities{
browser_name: 'msedge'
accept_insecure_certs: true
edge_options: webdriver.EdgeOptions{
args: ['--headless=new']
binary: r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
}
}
wd := webdriver.new_edge_driver('http://127.0.0.1:9515', caps)!
defer {
wd.quit() or {}
}
wd.get('https://example.com')!
println('✓ Navigated to example.com')
// Find all paragraphs
paragraphs := wd.find_elements('css selector', 'p')!
println('✓ Found ${paragraphs.len} paragraph elements')
assert paragraphs.len > 0
// Find all links
links := wd.find_elements('css selector', 'a')!
println('✓ Found ${links.len} link elements')
// Find all divs
divs := wd.find_elements('css selector', 'div')!
println('✓ Found ${divs.len} div elements')
println('✅ Multiple elements test passed!')
}
fn main() {
println('========================================')
println('Running WebDriver Integration Tests')
println('========================================')
test_search_flow() or { eprintln('❌ Search flow test failed: ${err}') }
test_cookie_management() or { eprintln('❌ Cookie management test failed: ${err}') }
test_window_management() or { eprintln('❌ Window management test failed: ${err}') }
test_javascript_execution() or { eprintln('❌ JavaScript execution test failed: ${err}') }
test_navigation_flow() or { eprintln('❌ Navigation flow test failed: ${err}') }
test_multiple_elements() or { eprintln('❌ Multiple elements test failed: ${err}') }
println('\n========================================')
println('All integration tests completed!')
println('========================================')
}