1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_ERROR_H_ 6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_ERROR_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 12 namespace automation { 13 class Error; 14 } 15 16 namespace webdriver { 17 18 // Error codes defined by the WebDriver wire protcol. 19 // If you add a code here, don't forget to add it to |ErrorCodeToString|. 20 enum ErrorCode { 21 kSuccess = 0, 22 kNoSuchElement = 7, 23 kNoSuchFrame = 8, 24 kUnknownCommand = 9, 25 kStaleElementReference = 10, 26 kElementNotVisible = 11, 27 kInvalidElementState = 12, 28 kUnknownError = 13, 29 kElementNotSelectable = 15, 30 kXPathLookupError = 19, 31 kNoSuchWindow = 23, 32 kInvalidCookieDomain = 24, 33 kUnableToSetCookie = 25, 34 kUnexpectedAlertOpen = 26, 35 kNoAlertOpenError = 27, 36 37 // HTTP status codes. 38 kSeeOther = 303, 39 kBadRequest = 400, 40 kSessionNotFound = 404, 41 kMethodNotAllowed = 405, 42 kInternalServerError = 500, 43 }; 44 45 // Represents a WebDriver error and the context within which the error occurred. 46 class Error { 47 public: 48 static Error* FromAutomationError(const automation::Error& error); 49 50 explicit Error(ErrorCode code); 51 52 Error(ErrorCode code, const std::string& details); 53 54 virtual ~Error(); 55 56 void AddDetails(const std::string& details); 57 58 ErrorCode code() const; 59 const std::string& details() const; 60 61 private: 62 ErrorCode code_; 63 std::string details_; 64 65 DISALLOW_COPY_AND_ASSIGN(Error); 66 }; 67 68 } // namespace webdriver 69 70 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_ERROR_H_ 71