in reply to Selenium::Remote::Driver and threads

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.