Edge.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package Selenium::Edge;
  2. use strict;
  3. use warnings;
  4. # ABSTRACT: Use EdgeDriver without a Selenium server
  5. use Moo;
  6. use Selenium::CanStartBinary::FindBinary qw/coerce_simple_binary/;
  7. extends 'Selenium::Remote::Driver';
  8. =head1 SYNOPSIS
  9. my $driver = Selenium::Edge->new;
  10. # when you're done
  11. $driver->shutdown_binary;
  12. =for Pod::Coverage has_binary
  13. =head1 DESCRIPTION
  14. This class allows you to use the EdgeDriver without needing the JRE
  15. or a selenium server running. When you refrain from passing the
  16. C<remote_server_addr> and C<port> arguments, we will search for the
  17. edgedriver executable binary in your $PATH. We'll try to start the
  18. binary connect to it, shutting it down at the end of the test.
  19. If the MicrosoftWebDriver binary is not found, we'll fall back to the
  20. default L<Selenium::Remote::Driver> behavior of assuming defaults of
  21. 127.0.0.1:4444 after waiting a few seconds.
  22. If you specify a remote server address, or a port, we'll assume you
  23. know what you're doing and take no additional behavior.
  24. If you're curious whether your Selenium::Edge instance is using a
  25. separate MicrosoftWebDriver binary, or through the selenium server, you can
  26. check the C<binary_mode> attr after instantiation.
  27. =cut
  28. has '+browser_name' => (
  29. is => 'ro',
  30. default => sub { 'MicrosoftEdge' }
  31. );
  32. =attr binary
  33. Optional: specify the path to your binary. If you don't specify
  34. anything, we'll try to find it on our own via L<File::Which/which>.
  35. =cut
  36. has 'binary' => (
  37. is => 'lazy',
  38. coerce => \&coerce_simple_binary,
  39. default => sub { 'msedgedriver.exe' },
  40. predicate => 1
  41. );
  42. =attr binary_port
  43. Optional: specify the port that we should bind to. If you don't
  44. specify anything, we'll default to the driver's default port. Since
  45. there's no a priori guarantee that this will be an open port, this is
  46. _not_ necessarily the port that we end up using - if the port here is
  47. already bound, we'll search above it until we find an open one.
  48. See L<Selenium::CanStartBinary/port> for more details, and
  49. L<Selenium::Remote::Driver/port> after instantiation to see what the
  50. actual port turned out to be.
  51. =cut
  52. has 'binary_port' => (
  53. is => 'lazy',
  54. default => sub { 17556 }
  55. );
  56. has '_binary_args' => (
  57. is => 'lazy',
  58. builder => sub {
  59. my ($self) = @_;
  60. my $context = $self->wd_context_prefix;
  61. $context =~ s{^/}{};
  62. return ' --port=' . $self->port . ' --url-base=' . $context . ' ';
  63. }
  64. );
  65. with 'Selenium::CanStartBinary';
  66. =attr custom_args
  67. Optional: specify any additional command line arguments you'd like
  68. invoked during the binary startup. See
  69. L<Selenium::CanStartBinary/custom_args> for more information.
  70. =attr startup_timeout
  71. Optional: specify how long to wait for the binary to start itself and
  72. listen on its port. The default duration is arbitrarily 10 seconds. It
  73. accepts an integer number of seconds to wait: the following will wait
  74. up to 20 seconds:
  75. Selenium::Edge->new( startup_timeout => 20 );
  76. See L<Selenium::CanStartBinary/startup_timeout> for more information.
  77. =method shutdown_binary
  78. Call this method instead of L<Selenium::Remote::Driver/quit> to ensure
  79. that the binary executable is also closed, instead of simply closing
  80. the browser itself. If the browser is still around, it will call
  81. C<quit> for you. After that, it will try to shutdown the browser
  82. binary by making a GET to /shutdown and on Windows, it will attempt to
  83. do a C<taskkill> on the binary CMD window.
  84. $self->shutdown_binary;
  85. It doesn't take any arguments, and it doesn't return anything.
  86. We do our best to call this when the C<$driver> option goes out of
  87. scope, but if that happens during global destruction, there's nothing
  88. we can do.
  89. =attr fixed_ports
  90. Optional: Throw instead of searching for additional ports; see
  91. L<Selenium::CanStartBinary/fixed_ports> for more info.
  92. =cut
  93. 1;