Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by zerocred (Beadle)
on Mar 21, 2010 at 16:35 UTC ( [id://829960]=note: print w/replies, xml ) Need Help??


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

http://groups.google.com/group/selenium-users/browse_frm/thread/40c943d3e8813af9/ed18dee8c7781dbe?lnk=gst&q=reuse+browser+session#ed18dee8c7781dbe
public void startBrowser(String pstrBaseUrl, String pstrTimeou +tInMilliseconds) throws Exception { browser = new DefaultSelenium("localhost", 4444, "*chrome", ps +trBaseUrl); browser.start(); browser.setTimeout(pstrTimeoutInMilliseconds); }
in the code in message 5. Unless I'm misunderstanding what is going on - (I dunno much about Java)

This one is better:

http://groups.google.com/group/selenium-users/browse_frm/thread/403b2b93e6e0e2b2/e16702ec4686cd1f?lnk=gst&q=reuse+browser+session+id#e16702ec4686cd1f
RemoteControlConfiguration rcc = new RemoteControlConfiguration(); rcc.reuseBrowserSessions(); SeleniumServer ss = new SeleniumServer(rcc); ss.start();

What is the RemoteControlConfiguration()? or is that a home made function somewhere

Replies are listed 'Best First'.
Re^3: Selenium RC - How to reuse bowser session?
by Anonymous Monk on Mar 21, 2010 at 17:00 UTC
    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});
      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.

Re^3: Selenium RC - How to reuse bowser session?
by zerocred (Beadle) on Mar 21, 2010 at 16:49 UTC

    Also "session_id = Optional argument that can be used to reuse session_ids between test runs. This can make for faster testing." is mentioned as arguments for:

    $sel = WWW::Selenium->new( %args )

    In some (old?) documentation here:

    http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/perl/WWW-Selenium.html#element_locators

    but not in cpan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://829960]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found