1
0

Firefox.pm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package Selenium::Firefox;
  2. # ABSTRACT: Use FirefoxDriver without a Selenium server
  3. use Moo;
  4. use Selenium::CanStartBinary::FindBinary qw/coerce_firefox_binary/;
  5. extends 'Selenium::Remote::Driver';
  6. =head1 SYNOPSIS
  7. my $driver = Selenium::Firefox->new;
  8. =head1 DESCRIPTION
  9. This class allows you to use the FirefoxDriver 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. Firefox executable in your $PATH. We'll try to start the binary
  13. connect to it, shutting it down at the end of the test.
  14. If the Firefox application is not found in the expected places, we'll
  15. fall back to the default L<Selenium::Remote::Driver> behavior of
  16. assuming defaults of 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::Firefox instance is using a
  20. separate Firefox 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 { 'firefox' }
  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 in the default installation
  30. paths for Firefox. If your Firefox is elsewhere, we probably won't be
  31. able to find it, so you may be well served by specifying it yourself.
  32. =cut
  33. has 'binary' => (
  34. is => 'lazy',
  35. coerce => \&coerce_firefox_binary,
  36. default => sub { 'firefox' },
  37. predicate => 1
  38. );
  39. =attr binary_port
  40. Optional: specify the port that we should bind to. If you don't
  41. specify anything, we'll default to the driver's default port. Since
  42. there's no a priori guarantee that this will be an open port, this is
  43. _not_ necessarily the port that we end up using - if the port here is
  44. already bound, we'll search above it until we find an open one.
  45. See L<Selenium::CanStartBinary/port> for more details, and
  46. L<Selenium::Remote::Driver/port> after instantiation to see what the
  47. actual port turned out to be.
  48. =cut
  49. has 'binary_port' => (
  50. is => 'lazy',
  51. default => sub { 9090 }
  52. );
  53. has '_binary_args' => (
  54. is => 'lazy',
  55. builder => sub {
  56. my ($self) = @_;
  57. return ' -no-remote';
  58. }
  59. );
  60. with 'Selenium::CanStartBinary';
  61. 1;