PhantomJS.pm 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package Selenium::PhantomJS;
  2. # ABSTRACT: A convenience package for creating a PhantomJS instance
  3. use Moo;
  4. with 'Selenium::BinaryModeBuilder';
  5. extends 'Selenium::Remote::Driver';
  6. =head1 SYNOPSIS
  7. my $driver = Selenium::PhantomJS->new;
  8. =cut
  9. use constant PHANTOMJS_PORT => 8910;
  10. has '+browser_name' => (
  11. is => 'ro',
  12. default => sub { 'phantomjs' }
  13. );
  14. # By shadowing the parent's port function, we can set the port in
  15. # _build_binary_mode's builder
  16. has '+port' => (
  17. is => 'lazy'
  18. );
  19. has 'binary_mode' => (
  20. is => 'ro',
  21. init_arg => undef,
  22. builder => 1
  23. );
  24. has 'binary_name' => (
  25. is => 'lazy',
  26. default => sub { 'phantomjs' }
  27. );
  28. has 'binary_port' => (
  29. is => 'lazy',
  30. default => sub { 8910 }
  31. );
  32. sub DEMOLISH {
  33. my ($self) = @_;
  34. if ($self->binary_mode) {
  35. my $port = $self->port;
  36. my $ua = LWP::UserAgent->new;
  37. $ua->get('127.0.0.1:' . $port . '/wd/hub/shutdown');
  38. }
  39. }
  40. 1;