Chrome.pm 1.2 KB

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