PhantomJS.pm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package Selenium::PhantomJS;
  2. # ABSTRACT: Use GhostDriver without a Selenium server
  3. use Moo;
  4. use Selenium::CanStartBinary::FindBinary qw/coerce_simple_binary/;
  5. extends 'Selenium::Remote::Driver';
  6. =head1 SYNOPSIS
  7. my $driver = Selenium::PhantomJS->new;
  8. =head1 DESCRIPTION
  9. This class allows you to use PhantomJS via Ghostdriver without needing
  10. the JRE or a selenium server running. When you refrain from passing
  11. the C<remote_server_addr> and C<port> arguments, we will search for
  12. the phantomjs 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 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. =attr binary
  28. Optional: specify the path to your binary. If you don't specify
  29. anything, we'll try to find it on our own via L<File::Which/which>.
  30. =cut
  31. has 'binary' => (
  32. is => 'lazy',
  33. coerce => \&coerce_simple_binary,
  34. default => sub { 'phantomjs' },
  35. predicate => 1
  36. );
  37. =attr binary_port
  38. Optional: specify the port that we should bind to. If you don't
  39. specify anything, we'll default to the driver's default port. Since
  40. there's no a priori guarantee that this will be an open port, this is
  41. _not_ necessarily the port that we end up using - if the port here is
  42. already bound, we'll search above it until we find an open one.
  43. See L<Selenium::CanStartBinary/port> for more details, and
  44. L<Selenium::Remote::Driver/port> after instantiation to see what the
  45. actual port turned out to be.
  46. =cut
  47. has 'binary_port' => (
  48. is => 'lazy',
  49. default => sub { 8910 }
  50. );
  51. with 'Selenium::CanStartBinary';
  52. 1;