-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures.v
More file actions
31 lines (26 loc) · 1006 Bytes
/
Copy pathfixtures.v
File metadata and controls
31 lines (26 loc) · 1006 Bytes
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
module webdriver
// Test-runner fixtures: convenience wrappers that handle browser
// setup/teardown so `v test` functions stay focused on assertions.
// BrowserFn is a test body that receives a launched browser.
pub type BrowserFn = fn (mut b Browser) !
// with_browser launches a browser, runs `body`, and always closes the browser
// afterward (even if `body` errors). Any error from `body` is propagated.
pub fn with_browser(kind BrowserKind, opts LaunchOptions, body BrowserFn) ! {
mut b := launch(kind, opts)!
defer {
b.close()
}
body(mut b)!
}
// with_edge is with_browser specialized to Edge.
pub fn with_edge(opts LaunchOptions, body BrowserFn) ! {
with_browser(.edge, opts, body)!
}
// run_or_screenshot runs `body`; on failure it saves a screenshot to `path`
// (best effort) and re-raises the error — handy for debugging failed tests.
pub fn (mut b Browser) run_or_screenshot(path string, body BrowserFn) ! {
body(mut b) or {
b.wd.save_screenshot(path) or {}
return err
}
}