1
0

error.t 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use Test::Exception;
  6. use Test::LWP::UserAgent;
  7. use IO::Socket::INET;
  8. BEGIN: {
  9. unless (use_ok('Selenium::Remote::Driver')) {
  10. BAIL_OUT("Couldn't load Selenium::Remote::Driver");
  11. exit;
  12. }
  13. }
  14. UNAVAILABLE_BROWSER: {
  15. my $tua = Test::LWP::UserAgent->new;
  16. $tua->map_response(qr{status}, HTTP::Response->new(200, 'OK'));
  17. $tua->map_response(qr{session}, HTTP::Response->new(
  18. 500,
  19. 'Internal Server Error',
  20. ['Content-Type' => 'application/json'],
  21. '{"status":13,"sessionId":null,"value":{"message":"The path to..."} }'
  22. ));
  23. throws_ok(
  24. sub {
  25. Selenium::Remote::Driver->new_from_caps(
  26. ua => $tua,
  27. desired_capabilities => {
  28. browserName => 'chrome'
  29. }
  30. );
  31. }, qr/Could not create new session.*path to/,
  32. 'Errors in browser configuration are passed to user'
  33. );
  34. }
  35. LOCAL: {
  36. throws_ok(
  37. sub {
  38. Selenium::Remote::Driver->new_from_caps( port => 80 );
  39. }, qr/Selenium server did not return proper status/,
  40. 'Error message for not finding a selenium server is helpful'
  41. );
  42. }
  43. SAUCE: {
  44. SKIP: {
  45. my $host = 'ondemand.saucelabs.com';
  46. my $port = 80;
  47. my $sock = IO::Socket::INET->new(
  48. PeerAddr => $host,
  49. PeerPort => $port,
  50. );
  51. skip 'Cannot reach saucelabs for Sauce error case ', 1
  52. unless $sock;
  53. throws_ok(
  54. sub {
  55. Selenium::Remote::Driver->new_from_caps(
  56. remote_server_addr => $host,
  57. port => $port,
  58. desired_capabilities => {
  59. browserName => 'invalid'
  60. }
  61. );
  62. }, qr/Sauce Labs/, 'Saucelabs errors are passed to user');
  63. }
  64. }
  65. done_testing;