1 // Copyright (c) 2012 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_CHROMEDRIVER_CHROME_STATUS_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_STATUS_H_
7 
8 #include <string>
9 
10 // WebDriver standard status codes.
11 enum StatusCode {
12   kOk = 0,
13   kInvalidSessionId = 6,
14   kNoSuchElement = 7,
15   kNoSuchFrame = 8,
16   kUnknownCommand = 9,
17   kStaleElementReference = 10,
18   kElementNotVisible = 11,
19   kInvalidElementState = 12,
20   kUnknownError = 13,
21   kJavaScriptError = 17,
22   kXPathLookupError = 19,
23   kTimeout = 21,
24   kNoSuchWindow = 23,
25   kInvalidCookieDomain = 24,
26   kUnableToSetCookie = 25,
27   kUnexpectedAlertOpen = 26,
28   kNoSuchAlert = 27,
29   kScriptTimeout = 28,
30   kInvalidSelector = 32,
31   kSessionNotCreated = 33,
32   kMoveTargetOutOfBounds = 34,
33   kElementNotInteractable = 60,
34   kInvalidArgument = 61,
35   kNoSuchCookie = 62,
36   kElementClickIntercepted = 64,
37   kUnsupportedOperation = 405,
38   // Chrome-specific status codes.
39   kChromeNotReachable = 100,
40   kNoSuchExecutionContext,
41   kDisconnected,
42   kForbidden = 103,
43   kTabCrashed,
44   kTargetDetached,
45   kUnexpectedAlertOpen_Keep,
46 };
47 
48 // Represents a WebDriver status, which may be an error or ok.
49 class Status {
50  public:
51   explicit Status(StatusCode code);
52   Status(StatusCode code, const std::string& details);
53   Status(StatusCode code, const Status& cause);
54   Status(StatusCode code, const std::string& details, const Status& cause);
55   ~Status();
56 
57   void AddDetails(const std::string& details);
58 
59   bool IsOk() const;
60   bool IsError() const;
61 
62   StatusCode code() const;
63 
64   const std::string& message() const;
65 
66   const std::string& stack_trace() const;
67 
68  private:
69   StatusCode code_;
70   std::string msg_;
71   std::string stack_trace_;
72 };
73 
74 // Returns the standard error code string associated with a StatusCode, as
75 // defined by W3C (https://w3c.github.io/webdriver/#dfn-error-code).
76 const char* StatusCodeToString(StatusCode code);
77 
78 #endif  // CHROME_TEST_CHROMEDRIVER_CHROME_STATUS_H_
79