in reply to Re^2: Selenium RC - How to reuse bowser session?
in thread Selenium RC - How to reuse bowser session?

Try manually setting/reusing
my $sel = ...->new( session_id => 'magic string', # OR $sel->{session_id} = 'magic string';
or, if getExistingBrowserSession exists
$sel->{session_id} = $sel->get_string("getExistingBrowserSession", $sel->{browser_start_comma +nd}, $sel->{browser_url});

Replies are listed 'Best First'.
Re^4: Selenium RC - How to reuse bowser session?
by zerocred (Beadle) on Mar 21, 2010 at 18:05 UTC
    Thanks that's great!
    This seems to sort of work, it does grab the same session if the session_id is in the constructor). I just found that I can get the existing session_id using

    $sel->retrieve_last_remote_control_logs();

    And can probably regex it out (I'm cut& pasting right now) - and store it somewhere if I leave the server running and relaunch my automation. Otherwise make a new session and then save teh session_id with that command or yours.

    Selenium complains if I give it a 'magic string' that is not a real existing session_id, but if I give it the id of a real, existing session that is up it seems happy to use it. That seems to mean it can't be started up with arbitary session_id the server has to generate one - but if that can be captured it can be reused

    However, selenium seems to require me to open a URL

    $sel->open_ok("$url");

    before it will allow clicking on anything. However this makes my site think I'm navigating away and makes a popup forcing me to choose to log out or abanodon the new attempts at hijacking the session! Needless to say, I didn't write the site I'm just trying to get it to do something quicker than I can type.

    Still this is progress!! - Thanks so much

    (off to bed now - I'll type up a full solution when I get it working)

      BTW I'm using Selenium RC server running on WinXP controlled from perl on Linux.

      Ok I have to use the option:

      auto_stop="0"

      In the $sel...->new(...) constructor and the subsequent connections. Don't call

      $sel->start;

      in the routine to reconnect to the existing session.

      I get Unknown command 'getExistingBrowserSession' if I use the function above - a great pity it looks like a very elegant way to get the session_id. My SeRC is on a WinXP box as the website only works on IE.

      The command

      $sel->retrieve_last_remote_control_logs();

      seems to return a bunch of stuff and the session_id is in there - so I can parse an existing session_id from that.

      I also found out how to avoid the website thinking I was navigating away - by using a open_ok() to a link that it is happy to navigate to without logging out - I tried that before but realized the date needs to be part of the link! That way I can maintain the session.