Chrome.pm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package Selenium::Chrome;
  2. # ABSTRACT: A convenience package for creating a Chrome instance
  3. use Moo;
  4. use Selenium::CanStartBinary::FindBinary qw/coerce_simple_binary/;
  5. extends 'Selenium::Remote::Driver';
  6. =head1 SYNOPSIS
  7. my $driver = Selenium::Chrome->new;
  8. =head1 DESCRIPTION
  9. This class allows you to use the ChromeDriver without needing the JRE
  10. or a selenium server running. When you refrain from passing the
  11. C<remote_server_addr> and C<port> arguments, we will search for the
  12. chromedriver executable binary in your $PATH. We'll try to start the
  13. binary connect to it, shutting it down at the end of the test.
  14. If the chromedriver binary is not found, we'll fall back to the
  15. default L<Selenium::Remote::Driver> behavior of assuming defaults of
  16. 127.0.0.1:4444 after waiting a few seconds.
  17. If you specify a remote server address, or a port, we'll assume you
  18. know what you're doing and take no additional behavior.
  19. If you're curious whether your Selenium::Chrome instance is using a
  20. separate ChromeDriver binary, or through the selenium server, you can
  21. check the C<binary_mode> attr after instantiation.
  22. =cut
  23. has '+browser_name' => (
  24. is => 'ro',
  25. default => sub { 'chrome' }
  26. );
  27. # By shadowing the parent's port function, we can set the port in
  28. # _build_binary_mode's builder
  29. has '+port' => (
  30. is => 'lazy'
  31. );
  32. has 'binary' => (
  33. is => 'lazy',
  34. coerce => \&coerce_simple_binary,
  35. default => sub { 'chromedriver' },
  36. predicate => 1
  37. );
  38. has 'binary_port' => (
  39. is => 'lazy',
  40. default => sub { 9515 }
  41. );
  42. with 'Selenium::CanStartBinary';
  43. sub DEMOLISH {
  44. my ($self) = @_;
  45. $self->shutdown_binary;
  46. }
  47. 1;