Remote-Connection.t 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use strict;
  2. use warnings;
  3. use Test::More;
  4. use Test::Fatal;
  5. use Test::LWP::UserAgent;
  6. BEGIN: {
  7. unless (use_ok('Selenium::Remote::RemoteConnection')) {
  8. BAIL_OUT("Couldn't load Selenium::Remote::RemoteConnection");
  9. exit;
  10. }
  11. }
  12. REDIRECT: {
  13. my $tua = Test::LWP::UserAgent->new(
  14. max_redirect => 0
  15. );
  16. $tua->map_response(qr/redirect/, HTTP::Response->new(303, undef, ['Location' => 'http://localhost/elsewhere']));
  17. $tua->map_response(qr/elsewhere/, HTTP::Response->new(200, 'OK', undef, ''));
  18. my $conn = Selenium::Remote::RemoteConnection->new(
  19. remote_server_addr => 'localhost',
  20. port => '',
  21. ua => $tua
  22. );
  23. my $redirect_endpoint = {
  24. method => 'GET',
  25. url => 'http://localhost/redirect'
  26. };
  27. is( exception { $conn->request($redirect_endpoint) }, undef,
  28. '303 redirects no longer kill us');
  29. }
  30. WD_CONTEXT: {
  31. my $tua = Test::LWP::UserAgent->new;
  32. my $hit_custom_context = 0;
  33. my $response = sub {
  34. is($_[0]->uri, 'http://addr:port/test/anything', 'can construct url with custom wd_context' );
  35. $hit_custom_context++;
  36. return HTTP::Response->new(200, 'OK', undef, '')
  37. };
  38. $tua->map_response(qr/test/, $response);
  39. my $conn = Selenium::Remote::RemoteConnection->new(
  40. remote_server_addr => 'addr',
  41. port => 'port',
  42. wd_context_prefix => '/test',
  43. ua => $tua
  44. );
  45. my $endpoint = { method => 'GET', url => 'anything' };
  46. $conn->request($endpoint);
  47. ok($hit_custom_context, 'wd_context is set up properly');
  48. }
  49. done_testing;