hound icon indicating copy to clipboard operation
hound copied to clipboard

Cannot Reconnect to Active Webdriver Session

Open afjackman opened this issue 8 years ago • 5 comments

It appears that there's a disconnect between Hound's internal list of sessions and the webdriver's list of sessions. When I call Hound.Session.active_sessions() I get a list of sessions running on the webdriver. But when I try to change to one of them change_session_to(session["id"]) it creates a new session.

Looking a bit more closely at Hound.SessionServer.change_current_session_for_pid, I see that between iex sessions, the list of sessions it identifies becomes emptied (since it apparently uses ETS and doesn't restore a list upon resume or anything). Additionally, it's a bit confusing to see that the session id returned by calls like start_session is actually not the name of the session and seemingly also can't be used for change_session_to.

My immediate goal is to reconnect to an active session. Is there something I'm not seeing here?

afjackman avatar Jun 24 '16 18:06 afjackman

@tzveeJ I'll update the implementation to use ETS table to store sessions in the next couple days (Open to it if anyone wants to pick it up). right now sessions are stored in a name and only map to the session's name and not the ID.

Ideal implementation should be change_session_to being able to accept session name as atom (elixir-named sessions) or session name as id (directly referring to the id on the webdriver).

HashNuke avatar Jun 26 '16 13:06 HashNuke

Excellent - looking forward to it. Personally, I don't need Hound's internal naming system - it's perfectly easy to use the session ID returned and almost seems as though it would be more intuitive to just always use session ID as opposed to even having a concept of a name. But that's just me - I'm looking forward to either solution.

afjackman avatar Jun 27 '16 15:06 afjackman

I have started to work on this, but I am struggling with some aspects of this library.

In particular, I believe that the API for Hound.Helpers.Session was written with a noble goal but an unfortunate result - confusion and unreliability. Some of the issues include:

  • SessionServer attempts to kill sessions if a process dies. But sometimes it fails to do so, stranding a session. There's no API in Hound.Helpers.Session to fix this and the developer is therefore unaware that it is even necessary.
  • In many use cases (mine!), a developer won't want sessions to be destroyed if a process dies.
  • The session name is redundant - we have an ID already.
  • The session names are only available to the specific process that created the session.
  • The session names are lost between elixir sessions

These are my proposed changes:

Original Hound.Helpers.Session API def change_session_to(session_name, opts \ []) do def change_to_default_session do def in_browser_session(session_name, func) do def start_session(opts \ []) do def end_session(pid \ self()) do def current_session_id do def current_session_name do

New Hound.Helpers.Session API def active_sessions() do # Exposed from Hound.Session def change_session_to(session_id) do # Notice this is a simple session_id now, and won't awkwardly create a new session if it doesn't exist - it will raise an error def perform_in_session(session_id, func) do # Changed the name of the function, this modification is not required def start_session(opts \ []) do # No change def end_session(session_id \ nil) do # This ends the specific session ID or the session associated with the process if nil def current_session_id() do # No change

I have already done quite a bit of work with this but I will await further instruction.

afjackman avatar Aug 03 '16 06:08 afjackman

Pull request #123

afjackman avatar Aug 05 '16 03:08 afjackman

Not sure if it's the same issue, but I cannot use navigate_to with selenium now:

image

Daniel-Xu avatar Dec 06 '16 18:12 Daniel-Xu