Chrome.pm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package Selenium::Driver::Chrome;
  2. use strict;
  3. use warnings;
  4. no warnings 'experimental';
  5. use feature qw/signatures/;
  6. use Carp qw{confess};
  7. use File::Which;
  8. #ABSTRACT: Tell Selenium::Client how to spawn chromedriver
  9. =head1 Mode of Operation
  10. Spawns a chromedriver server on the provided port (which the caller will assign randomly)
  11. Relies on chromedriver being in your $PATH
  12. Pipes log output to ~/.selenium/perl-client/$port.log
  13. =head1 SUBROUTINES
  14. =head2 build_spawn_opts($class,$object)
  15. Builds a command string which can run the driver binary.
  16. All driver classes must build this.
  17. =cut
  18. sub _driver {
  19. return 'chromedriver';
  20. }
  21. sub build_spawn_opts($class,$object) {
  22. $object->{driver_class} = $class;
  23. $object->{driver_version} //= '';
  24. $object->{log_file} //= "$object->{client_dir}/perl-client/selenium-$object->{port}.log";
  25. $object->{driver_file} = File::Which::which($class->_driver());
  26. die "Could not find driver!" unless $object->{driver_file};
  27. my @config = ('--port='.$object->{port});
  28. # Build command string
  29. $object->{command} //= [
  30. $object->{driver_file},
  31. @config,
  32. ];
  33. return $object;
  34. }
  35. 1;