Firefox.pm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. my $args = ' -no-remote';
  58. if( $self->marionette_enabled ) {
  59. $args .= ' -marionette';
  60. }
  61. return $args;
  62. }
  63. );
  64. has '+wd_context_prefix' => (
  65. is => 'ro',
  66. default => sub { '/hub' }
  67. );
  68. =attr marionette_binary_port
  69. Optional: specify the port that we should bind Marionette to. If you don't
  70. specify anything, we'll default to the driver's default port. Since
  71. there's no a priori guarantee that this will be an open port, this is
  72. _not_ necessarily the port that we end up using - if the port here is
  73. already bound, we'll search above it until we find an open one.
  74. See L<Selenium::CanStartBinary/port> for more details, and
  75. L<Selenium::Remote::Driver/port> after instantiation to see what the
  76. actual port turned out to be.
  77. =cut
  78. has 'marionette_binary_port' => (
  79. is => 'lazy',
  80. default => sub { 2828 }
  81. );
  82. =attr marionette_enabled
  83. Optional: specify whether Marionette should be enabled or not. The
  84. firefox binary must have been built with this funtionality.
  85. =cut
  86. has 'marionette_enabled' => (
  87. is => 'lazy',
  88. default => 0
  89. );
  90. with 'Selenium::CanStartBinary';
  91. =attr custom_args
  92. Optional: specify any additional command line arguments you'd like
  93. invoked during the binary startup. See
  94. L<Selenium::CanStartBinary/custom_args> for more information.
  95. =attr startup_timeout
  96. Optional: specify how long to wait for the binary to start itself and
  97. listen on its port. The default duration is arbitrarily 10 seconds. It
  98. accepts an integer number of seconds to wait: the following will wait
  99. up to 20 seconds:
  100. Selenium::Firefox->new( startup_timeout => 20 );
  101. See L<Selenium::CanStartBinary/startup_timeout> for more information.
  102. =cut
  103. 1;