1
0

error.t 1.8 KB

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