|
17 | 17 | // under the License. |
18 | 18 | // </copyright> |
19 | 19 |
|
| 20 | +using System; |
20 | 21 | using System.Collections.Generic; |
21 | 22 |
|
| 23 | +#nullable enable |
| 24 | + |
22 | 25 | namespace OpenQA.Selenium |
23 | 26 | { |
24 | 27 | /// <summary> |
@@ -167,54 +170,52 @@ internal static class WebDriverError |
167 | 170 | /// </summary> |
168 | 171 | public const string UnsupportedOperation = "unsupported operation"; |
169 | 172 |
|
170 | | - private static readonly Dictionary<string, WebDriverResult> resultMap; |
171 | | - |
172 | | - static WebDriverError() |
| 173 | + private static readonly Dictionary<string, WebDriverResult> resultMap = new Dictionary<string, WebDriverResult> |
173 | 174 | { |
174 | | - resultMap = new Dictionary<string, WebDriverResult>(); |
175 | | - resultMap[ElementClickIntercepted] = WebDriverResult.ElementClickIntercepted; |
176 | | - resultMap[ElementNotInteractable] = WebDriverResult.ElementNotInteractable; |
177 | | - resultMap[InsecureCertificate] = WebDriverResult.InsecureCertificate; |
178 | | - resultMap[InvalidArgument] = WebDriverResult.InvalidArgument; |
179 | | - resultMap[InvalidCookieDomain] = WebDriverResult.InvalidCookieDomain; |
180 | | - resultMap[InvalidElementState] = WebDriverResult.InvalidElementState; |
181 | | - resultMap[InvalidSelector] = WebDriverResult.InvalidSelector; |
182 | | - resultMap[InvalidSessionId] = WebDriverResult.NoSuchDriver; |
183 | | - resultMap[JavaScriptError] = WebDriverResult.UnexpectedJavaScriptError; |
184 | | - resultMap[MoveTargetOutOfBounds] = WebDriverResult.MoveTargetOutOfBounds; |
185 | | - resultMap[NoSuchAlert] = WebDriverResult.NoAlertPresent; |
186 | | - resultMap[NoSuchCookie] = WebDriverResult.NoSuchCookie; |
187 | | - resultMap[NoSuchElement] = WebDriverResult.NoSuchElement; |
188 | | - resultMap[NoSuchFrame] = WebDriverResult.NoSuchFrame; |
189 | | - resultMap[NoSuchWindow] = WebDriverResult.NoSuchWindow; |
190 | | - resultMap[NoSuchShadowRoot] = WebDriverResult.NoSuchShadowRoot; |
191 | | - resultMap[ScriptTimeout] = WebDriverResult.AsyncScriptTimeout; |
192 | | - resultMap[SessionNotCreated] = WebDriverResult.SessionNotCreated; |
193 | | - resultMap[StaleElementReference] = WebDriverResult.ObsoleteElement; |
194 | | - resultMap[DetachedShadowRoot] = WebDriverResult.DetachedShadowRoot; |
195 | | - resultMap[Timeout] = WebDriverResult.Timeout; |
196 | | - resultMap[UnableToSetCookie] = WebDriverResult.UnableToSetCookie; |
197 | | - resultMap[UnableToCaptureScreen] = WebDriverResult.UnableToCaptureScreen; |
198 | | - resultMap[UnexpectedAlertOpen] = WebDriverResult.UnexpectedAlertOpen; |
199 | | - resultMap[UnknownCommand] = WebDriverResult.UnknownCommand; |
200 | | - resultMap[UnknownError] = WebDriverResult.UnknownError; |
201 | | - resultMap[UnknownMethod] = WebDriverResult.UnknownMethod; |
202 | | - resultMap[UnsupportedOperation] = WebDriverResult.UnsupportedOperation; |
203 | | - } |
| 175 | + { ElementClickIntercepted, WebDriverResult.ElementClickIntercepted }, |
| 176 | + { ElementNotInteractable, WebDriverResult.ElementNotInteractable }, |
| 177 | + { InsecureCertificate, WebDriverResult.InsecureCertificate }, |
| 178 | + { InvalidArgument, WebDriverResult.InvalidArgument }, |
| 179 | + { InvalidCookieDomain, WebDriverResult.InvalidCookieDomain }, |
| 180 | + { InvalidElementState, WebDriverResult.InvalidElementState }, |
| 181 | + { InvalidSelector, WebDriverResult.InvalidSelector }, |
| 182 | + { InvalidSessionId, WebDriverResult.NoSuchDriver }, |
| 183 | + { JavaScriptError, WebDriverResult.UnexpectedJavaScriptError }, |
| 184 | + { MoveTargetOutOfBounds, WebDriverResult.MoveTargetOutOfBounds }, |
| 185 | + { NoSuchAlert, WebDriverResult.NoAlertPresent }, |
| 186 | + { NoSuchCookie, WebDriverResult.NoSuchCookie }, |
| 187 | + { NoSuchElement, WebDriverResult.NoSuchElement }, |
| 188 | + { NoSuchFrame, WebDriverResult.NoSuchFrame }, |
| 189 | + { NoSuchWindow, WebDriverResult.NoSuchWindow }, |
| 190 | + { NoSuchShadowRoot, WebDriverResult.NoSuchShadowRoot }, |
| 191 | + { ScriptTimeout, WebDriverResult.AsyncScriptTimeout }, |
| 192 | + { SessionNotCreated, WebDriverResult.SessionNotCreated }, |
| 193 | + { StaleElementReference, WebDriverResult.ObsoleteElement }, |
| 194 | + { DetachedShadowRoot, WebDriverResult.DetachedShadowRoot }, |
| 195 | + { Timeout, WebDriverResult.Timeout }, |
| 196 | + { UnableToSetCookie, WebDriverResult.UnableToSetCookie }, |
| 197 | + { UnableToCaptureScreen, WebDriverResult.UnableToCaptureScreen }, |
| 198 | + { UnexpectedAlertOpen, WebDriverResult.UnexpectedAlertOpen }, |
| 199 | + { UnknownCommand, WebDriverResult.UnknownCommand }, |
| 200 | + { UnknownError, WebDriverResult.UnknownError }, |
| 201 | + { UnknownMethod, WebDriverResult.UnknownMethod }, |
| 202 | + { UnsupportedOperation, WebDriverResult.UnsupportedOperation } |
| 203 | + }; |
204 | 204 |
|
205 | 205 | /// <summary> |
206 | 206 | /// Converts a string error to a <see cref="WebDriverResult"/> value. |
207 | 207 | /// </summary> |
208 | 208 | /// <param name="error">The error string to convert.</param> |
209 | 209 | /// <returns>The converted <see cref="WebDriverResult"/> value.</returns> |
| 210 | + /// <exception cref="ArgumentNullException">If <paramref name="error"/> is <see langword="null"/>.</exception> |
210 | 211 | public static WebDriverResult ResultFromError(string error) |
211 | 212 | { |
212 | | - if (!resultMap.ContainsKey(error)) |
| 213 | + if (!resultMap.TryGetValue(error, out WebDriverResult result)) |
213 | 214 | { |
214 | | - error = UnsupportedOperation; |
| 215 | + return WebDriverResult.UnsupportedOperation; |
215 | 216 | } |
216 | 217 |
|
217 | | - return resultMap[error]; |
| 218 | + return result; |
218 | 219 | } |
219 | 220 | } |
220 | 221 | } |
0 commit comments