简体   繁体   English

来自 selenium 驱动程序的 session_id 和来自浏览器 cookie 的 session 值是不同的值

[英]session_id from selenium driver and session value from browser cookie are different values

I started test in debug mode where I opened some service main page, then I got session_id from selenium driver and compared it with session value from browser cookies (it was base64 encoded, so I decoded it) - they are different.我在调试模式下开始测试,我打开了一些服务主页,然后我从 selenium 驱动程序获得了 session_id,并将它与来自浏览器 cookies 的 session 值进行了比较(它是 base64 编码的,所以我解码了它) - 它们是不同的。 May be from articles I understood it wrong, but I thought that cookies should store the session id.可能来自我理解错误的文章,但我认为 cookies 应该存储 session id。 Could someone explain it?有人可以解释一下吗?

You're confusing two different types of sessions.您混淆了两种不同类型的会话。 Basically a session is a system state defined for particular client.基本上 session 是为特定客户端定义的系统 state。 Typically the server stores that state and associates it with some ID.通常服务器会存储 state 并将其与某个 ID 相关联。

So when you have selenium test there are two sessions (at least) in place.因此,当您进行 selenium 测试时,(至少)有两个会话。

  1. A session that is maintained between your test code and WebDriver (which is also a web service).在您的测试代码和 WebDriver 之间维护的 session (这也是一个 web 服务)。 That is one you pick with driver.session_id .那是你用driver.session_id选择的。 That session is defined on WebDriver side. session 是在 WebDriver 端定义的。

  2. A session that is maintained in application under test .在被测应用程序中维护的 session This is what you know from cookies put to your browser.这就是你从 cookies 中了解到的内容。

So they are not the same.所以他们不一样。 While session on webdriver serves to distinguish and define states of WebDriver clients (you can use the same driver service in parallel with multiple tests) the session in cookies serves for maintaining the application user state (usually associate a browser activity with a user registered in the app)虽然 webdriver 上的 session 用于区分和定义 WebDriver 客户端的状态(您可以在多个测试中并行使用相同的驱动程序服务),cookies 中的 session 用于维护应用程序用户 state(通常将浏览器活动与在应用程序)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果激活了多个驱动程序,是否可以获取使用 Selenium 和 Appium 打开的活动驱动程序的 session_id? - Is it possible to get session_id of active driver opened with Selenium and Appium if several drivers were activated? 在urllib2中使用selenium的会话cookie - Using a session cookie from selenium in urllib2 从Selenium会话接管浏览器 - Take over browser from selenium session 使用selenium web驱动程序复制浏览器会话 - replicate browser session with selenium web driver 将会话ID从Selenium传递到Python请求 - Passing session ID from Selenium to Python Requests “指定的 session ID 不存在或不再处于活动状态”来自 Edge 浏览器上 selenium 的异常, - “The specified session ID does not exist or is no longer active” Exception from selenium on Edge browser, selenium 如何从现有的 Web 浏览器页面自动捕获该值并在新会话中使用该值? - How can selenium automatically capture the value from an existing web browser page and use that value in the new session? 使用会话ID连接到当前的硒浏览器窗口 - Connecting to current selenium browser window with session id 硒铬驱动程序无此会话 - Selenium chrome driver No Such Session 如何打开新的 selenium chrome 驱动程序 session 使用 cookies 从以前的 Z21D6F40CFB5111982E4424AE 绕过网站登录凭据5082E457ZAE0 - How to open new selenium chrome driver session using cookies from previous session to bypass a websites login credentials
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM