Skip to content

Commit 8834781

Browse files
RenderMichaelsandeepsuryaprasad
authored andcommitted
[dotnet] Align WebDriver errors with specification (SeleniumHQ#14936)
1 parent 9c49426 commit 8834781

7 files changed

+226
-63
lines changed

dotnet/src/webdriver/Remote/HttpCommandExecutor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private Response CreateResponse(HttpResponseInfo responseInfo)
326326
}
327327
else
328328
{
329-
response.Status = WebDriverResult.UnhandledError;
329+
response.Status = WebDriverResult.UnknownError;
330330
response.Value = body;
331331
}
332332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// <copyright file="UnknownErrorException.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
22+
#nullable enable
23+
24+
namespace OpenQA.Selenium
25+
{
26+
/// <summary>
27+
/// An unknown error occurred in the remote end while processing the command.
28+
/// </summary>
29+
[Serializable]
30+
public class UnknownErrorException : WebDriverException
31+
{
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="UnknownErrorException"/> class with the specified message.
34+
/// </summary>
35+
/// <param name="message">The message of the exception.</param>
36+
public UnknownErrorException(string? message)
37+
: base(message)
38+
{
39+
}
40+
41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="UnknownErrorException"/> class with the specified message and inner exception.
43+
/// </summary>
44+
/// <param name="message">The message of the exception.</param>
45+
/// <param name="innerException">The inner exception for this exception.</param>
46+
public UnknownErrorException(string? message, Exception? innerException)
47+
: base(message, innerException)
48+
{
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// <copyright file="UnknownMethodException.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
22+
#nullable enable
23+
24+
namespace OpenQA.Selenium
25+
{
26+
/// <summary>
27+
/// Exception that is thrown when the requested command matched a known URL but did not match any method for that URL.
28+
/// </summary>
29+
[Serializable]
30+
public class UnknownMethodException : WebDriverException
31+
{
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="UnknownMethodException"/> class with the specified message.
34+
/// </summary>
35+
/// <param name="message">The message of the exception.</param>
36+
public UnknownMethodException(string? message) : base(message)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="UnknownMethodException"/> class with the specified message and inner exception.
42+
/// </summary>
43+
/// <param name="message">The message of the exception.</param>
44+
/// <param name="innerException">The inner exception for this exception.</param>
45+
public UnknownMethodException(string? message, Exception? innerException) : base(message, innerException)
46+
{
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// <copyright file="UnsupportedOperationException.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
22+
#nullable enable
23+
24+
namespace OpenQA.Selenium
25+
{
26+
/// <summary>
27+
/// Indicates that a command that should have executed properly cannot be supported for some reason.
28+
/// </summary>
29+
public class UnsupportedOperationException : WebDriverException
30+
{
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="UnsupportedOperationException"/> class with the specified message.
33+
/// </summary>
34+
/// <param name="message">The message of the exception.</param>
35+
public UnsupportedOperationException(string? message)
36+
: base(message)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="UnsupportedOperationException"/> class with the specified message and inner exception.
42+
/// </summary>
43+
/// <param name="message">The message of the exception.</param>
44+
/// <param name="innerException">The inner exception for this exception.</param>
45+
public UnsupportedOperationException(string? message, Exception? innerException)
46+
: base(message, innerException)
47+
{
48+
}
49+
}
50+
}

dotnet/src/webdriver/WebDriver.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecut
622622
{
623623
commandResponse = new Response
624624
{
625-
Status = WebDriverResult.UnhandledError,
625+
Status = WebDriverResult.UnknownError,
626626
Value = e
627627
};
628628
}
@@ -782,9 +782,6 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command
782782
case WebDriverResult.ElementNotSelectable:
783783
throw new InvalidElementStateException(errorMessage);
784784

785-
case WebDriverResult.UnhandledError:
786-
throw new WebDriverException(errorMessage);
787-
788785
case WebDriverResult.NoSuchDocument:
789786
throw new NoSuchElementException(errorMessage);
790787

@@ -854,6 +851,15 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command
854851
case WebDriverResult.InsecureCertificate:
855852
throw new InsecureCertificateException(errorMessage);
856853

854+
case WebDriverResult.UnknownError:
855+
throw new UnknownErrorException(errorMessage);
856+
857+
case WebDriverResult.UnknownMethod:
858+
throw new UnknownMethodException(errorMessage);
859+
860+
case WebDriverResult.UnsupportedOperation:
861+
throw new UnsupportedOperationException(errorMessage);
862+
857863
default:
858864
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", errorMessage, errorResponse.Status));
859865
}

dotnet/src/webdriver/WebDriverError.cs

+9-35
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,16 @@ namespace OpenQA.Selenium
2727
/// </summary>
2828
internal static class WebDriverError
2929
{
30-
/// <summary>
31-
/// Represents the detached shadow root error.
32-
/// </summary>
33-
public const string DetachedShadowRoot = "detached shadow root";
34-
3530
/// <summary>
3631
/// Represents the element click intercepted error.
3732
/// </summary>
3833
public const string ElementClickIntercepted = "element click intercepted";
3934

40-
/// <summary>
41-
/// Represents the element not selectable error.
42-
/// </summary>
43-
public const string ElementNotSelectable = "element not selectable";
44-
4535
/// <summary>
4636
/// Represents the element not interactable error.
4737
/// </summary>
4838
public const string ElementNotInteractable = "element not interactable";
4939

50-
/// <summary>
51-
/// Represents the element not visible error.
52-
/// </summary>
53-
/// TODO: Remove this string; it is no longer valid in the specification.
54-
public const string ElementNotVisible = "element not visible";
55-
5640
/// <summary>
5741
/// Represents the insecure certificate error.
5842
/// </summary>
@@ -68,17 +52,6 @@ internal static class WebDriverError
6852
/// </summary>
6953
public const string InvalidCookieDomain = "invalid cookie domain";
7054

71-
/// <summary>
72-
/// Represents the invalid coordinates error.
73-
/// </summary>
74-
public const string InvalidCoordinates = "invalid coordinates";
75-
76-
/// <summary>
77-
/// Represents the invalid element coordinates error.
78-
/// </summary>
79-
/// TODO: Remove this string; it is no longer valid in the specification.
80-
public const string InvalidElementCoordinates = "invalid element coordinates";
81-
8255
/// <summary>
8356
/// Represents the invalid element state error.
8457
/// </summary>
@@ -149,6 +122,11 @@ internal static class WebDriverError
149122
/// </summary>
150123
public const string StaleElementReference = "stale element reference";
151124

125+
/// <summary>
126+
/// Represents the detached shadow root error.
127+
/// </summary>
128+
public const string DetachedShadowRoot = "detached shadow root";
129+
152130
/// <summary>
153131
/// Represents the timeout error.
154132
/// </summary>
@@ -194,16 +172,11 @@ internal static class WebDriverError
194172
static WebDriverError()
195173
{
196174
resultMap = new Dictionary<string, WebDriverResult>();
197-
resultMap[DetachedShadowRoot] = WebDriverResult.DetachedShadowRoot;
198175
resultMap[ElementClickIntercepted] = WebDriverResult.ElementClickIntercepted;
199-
resultMap[ElementNotSelectable] = WebDriverResult.ElementNotSelectable;
200-
resultMap[ElementNotVisible] = WebDriverResult.ElementNotDisplayed;
201176
resultMap[ElementNotInteractable] = WebDriverResult.ElementNotInteractable;
202177
resultMap[InsecureCertificate] = WebDriverResult.InsecureCertificate;
203178
resultMap[InvalidArgument] = WebDriverResult.InvalidArgument;
204179
resultMap[InvalidCookieDomain] = WebDriverResult.InvalidCookieDomain;
205-
resultMap[InvalidCoordinates] = WebDriverResult.InvalidElementCoordinates;
206-
resultMap[InvalidElementCoordinates] = WebDriverResult.InvalidElementCoordinates;
207180
resultMap[InvalidElementState] = WebDriverResult.InvalidElementState;
208181
resultMap[InvalidSelector] = WebDriverResult.InvalidSelector;
209182
resultMap[InvalidSessionId] = WebDriverResult.NoSuchDriver;
@@ -218,14 +191,15 @@ static WebDriverError()
218191
resultMap[ScriptTimeout] = WebDriverResult.AsyncScriptTimeout;
219192
resultMap[SessionNotCreated] = WebDriverResult.SessionNotCreated;
220193
resultMap[StaleElementReference] = WebDriverResult.ObsoleteElement;
194+
resultMap[DetachedShadowRoot] = WebDriverResult.DetachedShadowRoot;
221195
resultMap[Timeout] = WebDriverResult.Timeout;
222196
resultMap[UnableToSetCookie] = WebDriverResult.UnableToSetCookie;
223197
resultMap[UnableToCaptureScreen] = WebDriverResult.UnableToCaptureScreen;
224198
resultMap[UnexpectedAlertOpen] = WebDriverResult.UnexpectedAlertOpen;
225199
resultMap[UnknownCommand] = WebDriverResult.UnknownCommand;
226-
resultMap[UnknownError] = WebDriverResult.UnhandledError;
227-
resultMap[UnknownMethod] = WebDriverResult.UnknownCommand;
228-
resultMap[UnsupportedOperation] = WebDriverResult.UnhandledError;
200+
resultMap[UnknownError] = WebDriverResult.UnknownError;
201+
resultMap[UnknownMethod] = WebDriverResult.UnknownMethod;
202+
resultMap[UnsupportedOperation] = WebDriverResult.UnsupportedOperation;
229203
}
230204

231205
/// <summary>

0 commit comments

Comments
 (0)