Greetings kixsnap and welcome to the Monastery. I bring you glad tidings of great joy for all mankind.

Yes, you can use Selenium::Remote::Driver in a parallel application. One of the more convoluted small helper apps I have built was a program that ran continuously offline looping through records from a DB and making a series of calls for each using S::R::D and Firefox. The program had been running for several months when I left that assignment.

Things that might be different between my environment then and yours:

=pod # $ DISPLAY=:99 perl script.pl You need to set the C<DISPLAY> env variable because this script uses h +eadless Firefox instances run by Selenium. =cut use strict; use warnings; use MCE::Shared; use MCE::Loop; use Tie::Cycle; my $pid = $$; END { report() if $$ == $pid } # only parent process reports results # Overall results hash, shared between processes my $results = MCE::Shared->hash(); # Process the data my %data = get_data(); # in this case, was keyed by HTTP method for my $method ( keys %data ) { MCE::Loop->init( chunk_size => 100, max_workers => 8 ); tie my $screen, 'MCE::Shared', { module => 'Tie::Cycle' }, [ 0 .. +7 ]; # We have a fixed number of screens in our virtual X buffer; # this range should match the number of MCE worker processes mce_loop { my ( $mce, $chunk_ref, $chunk_id ) = @_; my $driver = get_selenium_driver(); # or maybe an obj that already knows what SRD commands to run # Set the screen ID for a Firefox instance (for Selenium) $ENV{'DISPLAY'} = ':99.' . $screen; for ( @{ $chunk_ref } ) { my %this_job_data = %{ $_ }; if ( $this_job_data{skip} ) { $results->incr('SKIP'); next; } $driver->do_the_thing( $this_job_data ); $results->incr('OK'); $results->incr($this_job_data->{something}); } } @{ $data{ $method } }; MCE::Loop->finish; } ## sub report { # do something with $results } __END__

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Selenium::Remote::Driver and threads by 1nickt
in thread Selenium::Remote::Driver and threads by kixsnap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.