Chrome.pm 1.5 KB

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