Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: driver.Manage().Cookies.AddCookie(); with Native aot(c#) #13363

Closed
katanakatana123 opened this issue Dec 26, 2023 · 10 comments · Fixed by #14574
Closed

[🐛 Bug]: driver.Manage().Cookies.AddCookie(); with Native aot(c#) #13363

katanakatana123 opened this issue Dec 26, 2023 · 10 comments · Fixed by #14574

Comments

@katanakatana123
Copy link

katanakatana123 commented Dec 26, 2023

What happened?

when i use driver.Manage().Cookies.AddCookie(); i got the error OpenQA.Selenium.WebDriverArgumentException: invalid argument: missing 'name',
i think the problem comes from here

protected virtual Response Execute(string driverCommandToExecute, Dictionary<string, object> parameters)
, when native aot cannot resolve json class

How can we reproduce the issue?

driver.Manage().Cookies.AddCookie();

Relevant log output

OpenQA.Selenium.WebDriverArgumentException: invalid argument: missing 'name',

Operating System

window 10

Selenium version

newest

What are the browser(s) and version(s) where you see this issue?

120

What are the browser driver(s) and version(s) where you see this issue?

120

Are you using Selenium Grid?

No response

Copy link

@katanakatana123, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

You can't add a cookie that doesn't exist. You need at least a name and value.
https://www.selenium.dev/documentation/webdriver/interactions/cookies/?tab=csharp#add-cookie

@nvborisenko shouldn't this fail for not sending a cookie instance to the method?

@titusfortner titusfortner closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2023
@nvborisenko
Copy link
Member

The issue is reproduced, thanks for the report.

It is related to Native AOT.

driver.Url = "https://google.com";

driver.Manage().Cookies.AddCookie(new Cookie("a", "b"));
Unhandled Exception: OpenQA.Selenium.WebDriverArgumentException: invalid argument: missing 'name'
  (Session info: chrome=120.0.6099.130)
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response, String) + 0x511
   at OpenQA.Selenium.WebDriver.Execute(String, Dictionary`2) + 0x65
   at OpenQA.Selenium.CookieJar.AddCookie(Cookie) + 0x6a

@nvborisenko
Copy link
Member

Ah, we have logs! :)

00:54:05.780 DEBUG HttpCommandExecutor: Executing command: [0e18a5deeb9cd0f0b4b44625d29d74f2]: addCookie {"cookie":{}}
00:54:05.781 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:57283/session/0e18a5deeb9cd0f0b4b44625d29d74f2/cookie', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
  Accept: application/json; charset=utf-8
  Content-Type: application/json; charset=utf-8
}
00:54:05.784 TRACE HttpCommandExecutor: << StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 903
  Content-Type: application/json; charset=utf-8
}
00:54:05.784 DEBUG HttpCommandExecutor: Response: ( InvalidArgument: System.Collections.Generic.Dictionary`2[System.String,System.Object])

Here we can see that AddCookie command serialized improperly.

@titusfortner titusfortner added this to the 4.17 milestone Dec 26, 2023
@nvborisenko
Copy link
Member

nvborisenko commented Dec 27, 2023

As a workaround you can mark your method, which invokes AddCookie method, with the following attribute:

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Cookie))]

I see even more places in selenium code base where json serialization doesn't work properly with Native AOT.

Hoping #13097 will resolve it.

@NCLnclNCL
Copy link

As a workaround you can mark your method, which invokes AddCookie method, with the following attribute:

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Cookie))]

I see even more places in selenium code base where json serialization doesn't work properly with Native AOT.

Hoping #13097 will resolve it.

thank, it working,

@nvborisenko
Copy link
Member

Removing it from 4.17 milestone. This is rare case, when we want to be friends with, but cannot do it in discoverable future. I would like to keep it as opened, hoping #13097 resolve it.

@nvborisenko nvborisenko removed this from the 4.17 milestone Jan 17, 2024
@nvborisenko nvborisenko reopened this Sep 6, 2024
@nvborisenko
Copy link
Member

nvborisenko commented Oct 17, 2024

Hi @NCLnclNCL, are you able to help us to test the preview version of selenium package which seems to be AOT compatible (excluding CDP)? We are looking for everybody who is interested in it. @katanakatana123 and you?

@nvborisenko
Copy link
Member

It should be fixed by #14574

@nvborisenko
Copy link
Member

Verified, will be available in v4.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants