appium-safari-driver icon indicating copy to clipboard operation
appium-safari-driver copied to clipboard

`POST /session/<session_id>/cookie` fails on 1st try...but succeeds after

Open Fman77 opened this issue 1 year ago • 1 comments

I'm using a python client of selenium, and registered the iOS device through a Selenium Node, and relaying the the commands to an Appium server through the relay configuration of Selenium.

Most of the commands run fine, creating a session, getting to a URL, deleting a cookie.

But when trying to ADD a cookie, the request is failing the 1st time:

[79eff3c3][SafariDriver@781c] Driver proxy active, passing request on via HTTP proxy
[79eff3c3][SafariDriver@781c] Matched '/session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie' to command name 'setCookie'
[79eff3c3][SafariDriver@781c] Proxying [POST /session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie] to [POST http://127.0.0.1:5100/session/56E7DCEA-A41A-411A-B5F0-11803DCDB905/cookie] with body: {"cookie":{"name":"someName","value":"someValue","domain":".google.com","path":"/","secure":true}}
[79eff3c3][SafariDriver@781c] Got response with status 405:
[79eff3c3][HTTP] <-- POST /session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie 400 4 ms - 845

I think that request isn't forwarded to safridriver, I looked at the logs and I don't see it.

Now the exact same subsequent request, without changing anything, works:

[79eff3c3][SafariDriver@781c] Driver proxy active, passing request on via HTTP proxy
[79eff3c3][SafariDriver@781c] Matched '/session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie' to command name 'setCookie'
[79eff3c3][SafariDriver@781c] Proxying [POST /session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie] to [POST http://127.0.0.1:5100/session/56E7DCEA-A41A-411A-B5F0-11803DCDB905/cookie] with body: {"cookie":{"name":"someName","value":"someValue","domain":".google.com","path":"/","secure":true}}
[79eff3c3][SafariDriver@781c] Got response with status 200: {"value":null}
[79eff3c3][HTTP] <-- POST /session/79eff3c3-feff-4732-ad72-89c18f910d9b/cookie 200 21 ms - 14

I see that request coming through in safari driver logs, and I then called get_cookies() method (which maps to /cookie but without a request BODY), and I see the cookie that I just set before.

Thanks for looking into it!

Fman77 avatar Jan 15 '25 23:01 Fman77

It looks as though SafariDriver is responding to Appium with a 405 Not Allowed HTTP response. Not much we can do about that! You may want to report it as an issue to SafariDriver. Perhaps a short wait would avoid the error? Perhaps you could wrap the call in some exception handling on the client side and retry? I'm not sure what the actual issue would be.

jlipps avatar Jan 21 '25 18:01 jlipps