-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
driver_options.cr
157 lines (133 loc) · 6.83 KB
/
driver_options.cr
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
module Marionette
module DriverOptions
extend self
def chrome_options(args = [] of String,
page_load_strategy : PageLoadStrategy? = nil,
extensions = [] of String | IO,
binary = nil,
debugger_address = nil,
experimental_options = {} of String => String,
logging_prefs = {} of String => String,
**capabilities)
caps = capabilities.to_h
caps = caps.merge({"pageLoadStrategy" => page_load_strategy.to_s}) if page_load_strategy
opts = {} of String => String | Array(String)
opts = opts.merge(experimental_options)
opts = opts.merge({"args" => args}) unless args.empty?
opts = opts.merge({"binary" => binary}) if binary
opts = opts.merge({"debuggerAddress" => debugger_address}) if debugger_address
loaded_extensions = [] of String
extensions.each do |ext|
case ext
in IO
loaded_extensions << Base64.encode(ext.rewind.gets_to_end)
in String
expanded = File.expand_path(ext)
if File.exists?(ext)
loaded_extensions << Base64.encode(File.read(expanded))
end
end
end
opts = opts.merge({"extensions" => loaded_extensions}) unless loaded_extensions.empty?
caps = caps.merge({"goog:loggingPrefs" => logging_prefs}) unless logging_prefs.empty?
caps.merge({"goog:chromeOptions" => opts})
end
def firefox_options(args = [] of String,
page_load_strategy : PageLoadStrategy? = nil,
binary = nil,
log_level = nil,
**capabilities)
caps = capabilities.to_h
caps = caps.merge({"pageLoadStrategy" => page_load_strategy.to_s}) if page_load_strategy
opts = {} of String => JSON::Any
opts = opts.merge({"args" => args}) unless args.empty?
opts = opts.merge({"binary" => binary}) if binary
opts = opts.merge({"log" => {"level" => log_level}}) if log_level
caps.merge({"moz:firefoxOptions" => opts})
end
def edge_options(args = [] of String,
page_load_strategy : PageLoadStrategy? = nil,
is_legacy = false,
browser_name = nil,
**capabilities)
caps = capabilities.to_h
opts = {} of String => JSON::Any
opts = opts.merge({"args" => args}) unless args.empty?
unless is_legacy
opts = opts.merge({"browserName" => browser_name}) if browser_name
end
caps.merge({"ms:edgeOptions" => opts})
end
def ie_options(args = [] of String,
browser_attach_timeout = nil,
element_scroll_behavior : ElementScrollBehavior? = nil,
ensure_clean_session = nil,
file_upload_dialog_timeout = nil,
force_create_process_api = nil,
force_shell_windows_api = nil,
full_page_screenshot = nil,
ignore_protected_mode_settings = nil,
ignore_zoom_level = nil,
initial_browser_url = nil,
native_events = nil,
persistent_hover = nil,
require_window_focus = nil,
use_per_process_proxy = nil,
validate_cookie_document_type = nil,
additional_options = {} of String => String,
**capabilities)
caps = capabilities.to_h
opts = {} of String => JSON::Any
opts = opts.merge({"id.browserCommandLineSwitches" => args.join(' ')}) unless args.empty?
opts = opts.merge({"browserAttachTimeout" => browser_attach_timeout}) if browser_attach_timeout
opts = opts.merge({"elementScrollBehavior" => element_scroll_behavior}) if element_scroll_behavior
opts = opts.merge({"ie.ensureCleanSession" => ensure_clean_session}) if ensure_clean_session
opts = opts.merge({"ie.fileUploadDialogTimeout" => file_upload_dialog_timeout}) if file_upload_dialog_timeout
opts = opts.merge({"ie.forceCreateProcessApi" => force_create_process_api}) if force_create_process_api
opts = opts.merge({"ie.forceShellWindowsApi" => force_shell_windows_api}) if force_shell_windows_api
opts = opts.merge({"ie.enableFullPageScreenshot" => full_page_screenshot}) if full_page_screenshot
opts = opts.merge({"ignoreProtectedModeSettings" => ignore_protected_mode_settings}) if ignore_protected_mode_settings
opts = opts.merge({"ignoreZoomSetting" => ignore_zoom_level}) if ignore_zoom_level
opts = opts.merge({"initialBrowserUrl" => initial_browser_url}) if initial_browser_url
opts = opts.merge({"nativeEvents" => native_events}) if native_events
opts = opts.merge({"enablePersistentHover" => persistent_hover}) if persistent_hover
opts = opts.merge({"requireWindowFocus" => require_window_focus}) if require_window_focus
opts = opts.merge({"ie.usePerProcessProxy" => use_per_process_proxy}) if use_per_process_proxy
opts = opts.merge({"ie.validateCookieDocumentType" => validate_cookie_document_type}) if validate_cookie_document_type
caps.merge({"se:ieOptions" => opts})
end
def webkit_gtk_options(args = [] of String,
binary = nil,
overlay_scrollbars = nil,
**capabilities)
caps = capabilities.to_h
opts = {} of String => JSON::Any
opts = opts.merge({"args" => args}) unless args.empty?
opts = opts.merge({"binary" => binary}) if binary
opts = opts.merge({"useOverlayScrollbars" => overlay_scrollbars}) if overlay_scrollbars
caps.merge({"webkitgtk:browserOptions" => opts})
end
def wpe_webkit_options(args = [] of String,
binary = nil,
**capabilities)
caps = capabilities.to_h
opts = {} of String => JSON::Any
opts = opts.merge({"args" => args}) unless args.empty?
opts = opts.merge({"binary" => binary}) if binary
caps.merge({"webkitgtk:browserOptions" => opts})
end
def opera_options(args = [] of String,
android_package_name = nil,
android_device_socket = nil,
android_command_line_file = nil,
**capabilities)
caps = capabilities.to_h
opts = {} of String => JSON::Any
opts = opts.merge({"args" => args}) unless args.empty?
opts = opts.merge({"androidPackage" => android_package_name}) if android_package_name
opts = opts.merge({"androidDeviceSocket" => android_device_socket}) if android_device_socket
opts = opts.merge({"androidCommandLineFile" => android_command_line_file}) if android_command_line_file
caps.merge({"operaOptions" => opts})
end
end
end