1
0

PhantomJS.pm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package Selenium::PhantomJS;
  2. # ABSTRACT: A convenience package for creating a PhantomJS instance
  3. use Moo;
  4. extends 'Selenium::Remote::Driver';
  5. =head1 SYNOPSIS
  6. my $driver = Selenium::PhantomJS->new;
  7. =head1 DESCRIPTION
  8. This class allows you to use PhantomJS through Ghostdriver without
  9. needing the JRE or a selenium server running. When you refrain from
  10. passing the C<remote_server_addr> and C<port> arguments, we will
  11. search for the phantomjs executable binary in your $PATH. We'll try
  12. to start the binary connect to it, shutting it down at the end of the
  13. test.
  14. If the binary is not found, we'll fall back to the default
  15. 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::PhantomJS instance is using a
  20. separate PhantomJS binary, or through the selenium server, you can check
  21. the C<binary_mode> attr after instantiation.
  22. =cut
  23. has '+browser_name' => (
  24. is => 'ro',
  25. default => sub { 'phantomjs' }
  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. default => sub { 'phantomjs' },
  35. predicate => 1
  36. );
  37. has 'binary_port' => (
  38. is => 'lazy',
  39. default => sub { 8910 }
  40. );
  41. sub DEMOLISH {
  42. my ($self) = @_;
  43. $self->shutdown_binary;
  44. }
  45. with 'Selenium::CanStartBinary';
  46. 1;