Skip to content

Commit 25d2caf

Browse files
authored
Merge branch 'trunk' into 13803-implementation-fix
2 parents b4c8be9 + 02f3ca7 commit 25d2caf

File tree

10 files changed

+164
-113
lines changed

10 files changed

+164
-113
lines changed

dotnet/src/webdriver/CookieJar.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ public void AddCookie(Cookie cookie)
7474
/// Delete the cookie by passing in the name of the cookie
7575
/// </summary>
7676
/// <param name="name">The name of the cookie that is in the browser</param>
77-
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langword="null"/>.</exception>
77+
/// <exception cref="ArgumentException">If <paramref name="name"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
7878
public void DeleteCookieNamed(string name)
7979
{
80-
if (name is null)
80+
if (string.IsNullOrWhiteSpace(name))
8181
{
82-
throw new ArgumentNullException(nameof(name));
82+
throw new ArgumentException("Cookie name cannot be null or empty", nameof(name));
8383
}
8484

85-
Dictionary<string, object> parameters = new Dictionary<string, object>();
86-
parameters.Add("name", name);
85+
Dictionary<string, object> parameters = new() { { "name", name } };
86+
8787
driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
8888
}
8989

@@ -115,11 +115,12 @@ public void DeleteAllCookies()
115115
/// </summary>
116116
/// <param name="name">name of the cookie that needs to be returned</param>
117117
/// <returns>A Cookie from the name; or <see langword="null"/> if not found.</returns>
118+
/// <exception cref="ArgumentException">If <paramref name="name"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
118119
public Cookie? GetCookieNamed(string name)
119120
{
120121
if (string.IsNullOrWhiteSpace(name))
121122
{
122-
throw new ArgumentException("Cookie name cannot be empty", nameof(name));
123+
throw new ArgumentException("Cookie name cannot be null or empty", nameof(name));
123124
}
124125

125126
try

dotnet/src/webdriver/ICookieJar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface ICookieJar
6161
/// Deletes the cookie with the specified name from the page.
6262
/// </summary>
6363
/// <param name="name">The name of the cookie to be deleted.</param>
64-
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langword="null"/>.</exception>
64+
/// <exception cref="ArgumentException">If <paramref name="name"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
6565
void DeleteCookieNamed(string name);
6666

6767
/// <summary>

dotnet/test/common/CookieImplementationTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,28 @@ public void DeleteAllCookiesDifferentUrls()
620620
AssertCookieIsPresentWithName(cookie2.Name);
621621
}
622622

623+
[Test]
624+
[TestCase(null)]
625+
[TestCase("")]
626+
[TestCase(" ")]
627+
public void ShouldThrowWhenGetInvalidCookieByName(string cookieName)
628+
{
629+
var getCookieAction = () => driver.Manage().Cookies.GetCookieNamed(cookieName);
630+
631+
Assert.That(getCookieAction, Throws.ArgumentException);
632+
}
633+
634+
[Test]
635+
[TestCase(null)]
636+
[TestCase("")]
637+
[TestCase(" ")]
638+
public void ShouldThrowWhenDeleteInvalidCookieByName(string cookieName)
639+
{
640+
var deleteCookieAction = () => driver.Manage().Cookies.DeleteCookieNamed(cookieName);
641+
642+
Assert.That(deleteCookieAction, Throws.ArgumentException);
643+
}
644+
623645
//------------------------------------------------------------------
624646
// Tests below here are not included in the Java test suite
625647
//------------------------------------------------------------------

javascript/grid-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"dependencies": {
7-
"@apollo/client": "3.12.4",
7+
"@apollo/client": "3.12.5",
88
"@emotion/react": "11.14.0",
99
"@emotion/styled": "11.14.0",
1010
"@mui/icons-material": "5.15.18",

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,11 @@ class Options {
19371937
* when the cookie has been deleted.
19381938
*/
19391939
deleteCookie(name) {
1940+
// Validate the cookie name is non-empty and properly trimmed.
1941+
if (!name?.trim()) {
1942+
throw new error.InvalidArgumentError('Cookie name cannot be empty')
1943+
}
1944+
19401945
return this.driver_.execute(new command.Command(command.Name.DELETE_COOKIE).setParameter('name', name))
19411946
}
19421947

javascript/node/selenium-webdriver/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"ws": "^8.18.0"
3030
},
3131
"devDependencies": {
32-
"@eslint/js": "^9.17.0",
32+
"@eslint/js": "^9.18.0",
3333
"clean-jsdoc-theme": "^4.3.0",
34-
"eslint": "^9.17.0",
35-
"eslint-config-prettier": "^9.1.0",
34+
"eslint": "^9.18.0",
35+
"eslint-config-prettier": "^10.0.1",
3636
"eslint-plugin-mocha": "^10.5.0",
3737
"eslint-plugin-n": "^17.15.1",
3838
"eslint-plugin-no-only-tests": "^3.3.0",

javascript/node/selenium-webdriver/safari.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ class Options extends Capabilities {
7878
this.options_[TECHNOLOGY_PREVIEW_OPTIONS_KEY] = !!useTechnologyPreview
7979
return this
8080
}
81+
82+
/**
83+
* Enables diagnostic logging for Safari.
84+
*
85+
* This method sets the `safari:diagnose` option to `true` in the current configuration.
86+
* It is used to enable additional logging or diagnostic features specific to Safari.
87+
*
88+
* @returns {Options} Returns the current instance
89+
*/
90+
enableLogging() {
91+
this.set('safari:diagnose', true)
92+
return this
93+
}
8194
}
8295

8396
/**

javascript/node/selenium-webdriver/test/cookie_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ suite(function (env) {
5454
})
5555
})
5656

57-
it('throw error if name is null', async function () {
57+
it('Get Cookie: throw error if name is null', async function () {
5858
const cookie = createCookieSpec()
5959
await driver.manage().addCookie(cookie)
6060
await assert.rejects(async () => await driver.manage().getCookie(null), {
@@ -63,6 +63,15 @@ suite(function (env) {
6363
})
6464
})
6565

66+
it('Delete cookie: throw error if name is null', async function () {
67+
const cookie = createCookieSpec()
68+
await driver.manage().addCookie(cookie)
69+
await assert.rejects(async () => await driver.manage().deleteCookie(null), {
70+
name: 'InvalidArgumentError',
71+
message: `Cookie name cannot be empty`,
72+
})
73+
})
74+
6675
it('can get all cookies', async function () {
6776
const cookie1 = createCookieSpec()
6877
const cookie2 = createCookieSpec()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium",
3-
"packageManager": "[email protected].2",
3+
"packageManager": "[email protected].4",
44
"workspaces": [
55
"javascript/grid-ui",
66
"javascript/node/selenium-webdriver"

0 commit comments

Comments
 (0)