1
0

error.t 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use Test::Fatal;
  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. like( exception {
  24. Selenium::Remote::Driver->new_from_caps(
  25. ua => $tua,
  26. desired_capabilities => {
  27. browserName => 'chrome'
  28. }
  29. );
  30. }, qr/Could not create new session.*path to/,
  31. 'Errors in browser configuration are passed to user' );
  32. }
  33. LOCAL: {
  34. like( exception {
  35. Selenium::Remote::Driver->new_from_caps(
  36. port => 80
  37. );
  38. }, qr/Selenium server did not return proper status/,
  39. 'Error message for not finding a selenium server is helpful' );
  40. }
  41. SAUCE: {
  42. SKIP: {
  43. my $host = 'ondemand.saucelabs.com';
  44. my $port = 80;
  45. my $sock = IO::Socket::INET->new(
  46. PeerAddr => $host,
  47. PeerPort => $port,
  48. );
  49. skip 'Cannot reach saucelabs for Sauce error case ', 1
  50. unless $sock;
  51. like(exception {
  52. Selenium::Remote::Driver->new_from_caps(
  53. remote_server_addr => $host,
  54. port => $port,
  55. desired_capabilities => {
  56. browserName => 'invalid'
  57. }
  58. );
  59. }, qr/Sauce Labs/,
  60. 'Saucelabs errors are passed to user');
  61. }
  62. }
  63. done_testing;