Permalink
Browse files

adding ghostdriver

  • Loading branch information...
1 parent ea367e2 commit 18613c5abee174e2b2741ef8b1811f4436c104e7 Pranav Verma committed Aug 21, 2012
Showing with 15,250 additions and 0 deletions.
  1. +22 −0 ghostdriver/LICENSE.BSD
  2. +72 −0 ghostdriver/README.md
  3. +32 −0 ghostdriver/TODO.md
  4. +230 −0 ghostdriver/src/errors.js
  5. +61 −0 ghostdriver/src/main.js
  6. +191 −0 ghostdriver/src/request_handlers/request_handler.js
  7. +97 −0 ghostdriver/src/request_handlers/router_request_handler.js
  8. +182 −0 ghostdriver/src/request_handlers/session_manager_request_handler.js
  9. +545 −0 ghostdriver/src/request_handlers/session_request_handler.js
  10. +64 −0 ghostdriver/src/request_handlers/status_request_handler.js
  11. +334 −0 ghostdriver/src/request_handlers/webelement_request_handler.js
  12. +200 −0 ghostdriver/src/session.js
  13. +70 −0 ghostdriver/src/third_party/parseuri.js
  14. +214 −0 ghostdriver/src/third_party/patch_require.js
  15. +15 −0 ghostdriver/src/third_party/webdriver-atoms/active_element.js
  16. +6 −0 ghostdriver/src/third_party/webdriver-atoms/back.js
  17. +124 −0 ghostdriver/src/third_party/webdriver-atoms/clear.js
  18. +16 −0 ghostdriver/src/third_party/webdriver-atoms/clear_local_storage.js
  19. +16 −0 ghostdriver/src/third_party/webdriver-atoms/clear_session_storage.js
  20. +133 −0 ghostdriver/src/third_party/webdriver-atoms/click.js
  21. +15 −0 ghostdriver/src/third_party/webdriver-atoms/default_content.js
  22. +9,996 −0 ghostdriver/src/third_party/webdriver-atoms/deps.js
  23. +16 −0 ghostdriver/src/third_party/webdriver-atoms/execute_async_script.js
  24. +13 −0 ghostdriver/src/third_party/webdriver-atoms/execute_script.js
  25. +15 −0 ghostdriver/src/third_party/webdriver-atoms/execute_sql.js
  26. +45 −0 ghostdriver/src/third_party/webdriver-atoms/find_element.js
  27. +45 −0 ghostdriver/src/third_party/webdriver-atoms/find_elements.js
  28. +6 −0 ghostdriver/src/third_party/webdriver-atoms/forward.js
  29. +46 −0 ghostdriver/src/third_party/webdriver-atoms/frame_by_id_or_name.js
  30. +15 −0 ghostdriver/src/third_party/webdriver-atoms/frame_by_index.js
  31. +15 −0 ghostdriver/src/third_party/webdriver-atoms/get_appcache_status.js
  32. +97 −0 ghostdriver/src/third_party/webdriver-atoms/get_attribute.js
  33. +103 −0 ghostdriver/src/third_party/webdriver-atoms/get_attribute_value.js
  34. +7 −0 ghostdriver/src/third_party/webdriver-atoms/get_current_position.js
  35. +7 −0 ghostdriver/src/third_party/webdriver-atoms/get_element_from_cache.js
  36. +15 −0 ghostdriver/src/third_party/webdriver-atoms/get_frame_window.js
  37. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_local_storage_item.js
  38. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_local_storage_keys.js
  39. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_local_storage_size.js
  40. +7 −0 ghostdriver/src/third_party/webdriver-atoms/get_location.js
  41. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_session_storage_item.js
  42. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_session_storage_keys.js
  43. +16 −0 ghostdriver/src/third_party/webdriver-atoms/get_session_storage_size.js
  44. +100 −0 ghostdriver/src/third_party/webdriver-atoms/get_size.js
  45. +103 −0 ghostdriver/src/third_party/webdriver-atoms/get_text.js
  46. +105 −0 ghostdriver/src/third_party/webdriver-atoms/get_top_left_coordinates.js
  47. +100 −0 ghostdriver/src/third_party/webdriver-atoms/get_value_of_css_property.js
  48. +6 −0 ghostdriver/src/third_party/webdriver-atoms/get_window_position.js
  49. +6 −0 ghostdriver/src/third_party/webdriver-atoms/get_window_size.js
  50. +100 −0 ghostdriver/src/third_party/webdriver-atoms/is_displayed.js
  51. +100 −0 ghostdriver/src/third_party/webdriver-atoms/is_enabled.js
  52. +7 −0 ghostdriver/src/third_party/webdriver-atoms/is_online.js
  53. +101 −0 ghostdriver/src/third_party/webdriver-atoms/is_selected.js
  54. +7 −0 ghostdriver/src/third_party/webdriver-atoms/lastupdate
  55. +16 −0 ghostdriver/src/third_party/webdriver-atoms/remove_local_storage_item.js
  56. +16 −0 ghostdriver/src/third_party/webdriver-atoms/remove_session_storage_item.js
  57. +16 −0 ghostdriver/src/third_party/webdriver-atoms/set_local_storage_item.js
  58. +16 −0 ghostdriver/src/third_party/webdriver-atoms/set_session_storage_item.js
  59. +6 −0 ghostdriver/src/third_party/webdriver-atoms/set_window_position.js
  60. +6 −0 ghostdriver/src/third_party/webdriver-atoms/set_window_size.js
  61. +124 −0 ghostdriver/src/third_party/webdriver-atoms/submit.js
  62. +124 −0 ghostdriver/src/third_party/webdriver-atoms/type.js
  63. +44 −0 ghostdriver/src/webdriver_atoms.js
  64. +181 −0 ghostdriver/src/webelementlocator.js
  65. +38 −0 ghostdriver/test/build.gradle
  66. BIN ghostdriver/test/gradle/wrapper/gradle-wrapper.jar
  67. +6 −0 ghostdriver/test/gradle/wrapper/gradle-wrapper.properties
  68. +164 −0 ghostdriver/test/gradlew
  69. +90 −0 ghostdriver/test/gradlew.bat
  70. +1 −0 ghostdriver/test/settings.gradle
  71. +37 −0 ghostdriver/test/src/test/java/ghostdriver/BaseTest.java
  72. +25 −0 ghostdriver/test/src/test/java/ghostdriver/ElementAttributesTest.java
  73. +68 −0 ghostdriver/test/src/test/java/ghostdriver/ElementFindingTest.java
  74. +38 −0 ghostdriver/test/src/test/java/ghostdriver/ElementMethodsTest.java
  75. +42 −0 ghostdriver/test/src/test/java/ghostdriver/FrameSwitchingTest.java
  76. +28 −0 ghostdriver/test/src/test/java/ghostdriver/GoogleSearchTest.java
  77. +5 −0 ghostdriver/test/src/test/java/ghostdriver/LocatorsTest.java
  78. +24 −0 ghostdriver/test/src/test/java/ghostdriver/NavigationTest.java
  79. +33 −0 ghostdriver/test/src/test/java/ghostdriver/ScriptExecutionTest.java
  80. +16 −0 ghostdriver/test/src/test/java/ghostdriver/TimeoutSettingTest.java
  81. +25 −0 ghostdriver/test/src/test/java/ghostdriver/WindowHandlesTest.java
  82. +68 −0 ghostdriver/tools/atoms_build_dir/build.desc
  83. +16 −0 ghostdriver/tools/import_atoms.README.md
  84. +58 −0 ghostdriver/tools/import_atoms.sh
  85. +1 −0 ghostdriver/tools/pack.sh
View
@@ -0,0 +1,22 @@
+Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,72 @@
+# Ghost Driver
+
+Ghost Driver is a pure JavaScript implementation of the
+[WebDriver Wire Protocol](http://code.google.com/p/selenium/wiki/JsonWireProtocol)
+for [PhantomJS](http://phantomjs.org/).
+It's going to be a Remote WebDriver that uses PhantomJS as back-end.
+
+## Status
+
+* Under development
+* Far from complete
+* Only **~40%** of the WireProtocol currently implemented
+* You can monitor development progress [at this Google Spreadsheet](https://docs.google.com/spreadsheet/ccc?key=0Am63grtxc7bDdGNqX1ZPX2VoZlE2ZHZhd09lNDkzbkE)
+* Core released to get people interested and get contributions
+* Don't raise BUGS: send PULL REQUESTS pleaase!
+
+## Presentation and Slides
+
+In April 2012 I (Ivan De Marino) presented GhostDriver at the [Selenium Conference](http://www.seleniumconf.org/speakers/#IDM):
+[slides](http://detro.github.com/ghostdriver/slides/index.html)
+and
+[video](http://blog.ivandemarino.me/2012/05/01/Me-the-Selenium-Conference-2012).
+
+## Requirements
+
+* PhantomJS [ghostdriver-dev branch](https://github.com/detro/phantomjs/tree/ghostdriver-dev),
+taken from my (Ivan De Marino) port: [github.com/detro/phantomjs](https://github.com/detro/phantomjs).
+
+## How to use it
+
+Check out the [ghostdriver-dev branch](https://github.com/detro/phantomjs/tree/ghostdriver-dev)
+of PhantomJS, and build it (I assume you know Git).
+
+There is **plenty to do before this is usable**, but if you can't wait to try
+PhantomJS's speed when it acts as a RemoteWebDriver Server, do the following:
+
+1. Start GhostDriver on a terminal:
+
+ ```bash
+ $> phantomjs ghostdriver/src/main.js
+ Ghost Driver running on port 8080
+ ```
+
+2. Build and Launch the test suite (written in Java, built with [Gradle](http://www.gradle.org/)):
+
+ ```bash
+ $> cd ghostdriver/test
+ $> ./gradlew test
+ ```
+
+## Reasoning: pros and cons
+
+### Pros of using an Headless browser for your Selenium testing
+* Speed: makes development faster
+* Speed: makes THE developer happier
+* Speed: makes leaves more time for beer, video-games, cycling or whatever you fancy
+* ...
+
+### Cons of using an Headless browser for your Selenium testing
+* PhantomJS is not a "Real" Browser, but _"just"_ very very close to one
+
+## Contributions
+
+You can contribute testing it and reporting bugs and issues, or submitting Pull Requests.
+Any **help is welcome**, but bear in mind the following base principles:
+
+* Squash your commits by theme: I prefer a clean, readable log
+* Maintain consistency with the code-style you are surrounded by
+* If you are going to make a big, substantial change, let's discuss it first
+
+## License
+GhostDriver is distributed under [BSD License](http://www.opensource.org/licenses/BSD-2-Clause).
View
@@ -0,0 +1,32 @@
+# Top Priority
+
+* Decorate req/res objects OR extend SessionReqHand to better manage "after open is done" scenarios
+* Implement all the commands :)
+ * "/session/:sessionid/element" and "/session/:sessionid/elements" need to be handled into 1 (++gracefulness)
+
+
+# Mid Priority
+
+* Support for Proxying
+* Support for Screenshots
+* Proper Capabilities negotiation
+
+
+# Low Priority
+
+* Subclass "RemoteWebDriver" to make setup via simple API
+* Refactor all the Erros in "error.js" to allow an optional, custom Error Handling.
+ * This will help to comply with [Wire Protocol Error Handling](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Error_Handling)
+ * See "error.js/InvalidCommandMethod"
+* Add another kind of "Error", like "CommandFailed", that have a different error handling and report
+ * See [Wire Protocol Failed Commands Error Handling](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Failed_Commands)
+* More complex examples
+
+
+# Things to add to PhantomJS
+
+* Ability to read informations like Operating System, Architecture and so forth
+* Ability to handle "alert(), confirm() and prompt()"
+* PhantomJS "res.write()" doesn't set the 'Content-Length' header automatically :(
+* Add support for Frames and IFrames in PhantomJS
+ * And than add it to the driver
View
@@ -0,0 +1,230 @@
+/*
+This file is part of the GhostDriver project from Neustar inc.
+
+Copyright (c) 2012, Ivan De Marino <ivan.de.marino@gmail.com> - Neustar inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+//------------------------------------------------------- Invalid Request Errors
+//----- http://code.google.com/p/selenium/wiki/JsonWireProtocol#Invalid_Requests
+exports.INVALID_REQ = {
+ "UNKNOWN_COMMAND" : "Unknown Command",
+ "UNIMPLEMENTED_COMMAND" : "Unimplemented Command",
+ "VARIABLE_RESOURCE_NOT_FOUND" : "Variable Resource Not Found",
+ "INVALID_COMMAND_METHOD" : "Invalid Command Method",
+ "MISSING_COMMAND_PARAMETER" : "Missing Command Parameter"
+};
+
+var _invalidReqHandle = function(res) {
+ // Set the right Status Code
+ switch(this.name) {
+ case exports.INVALID_REQ.UNIMPLEMENTED_COMMAND:
+ res.statusCode = 501; //< 501 Not Implemented
+ break;
+ case exports.INVALID_REQ.INVALID_COMMAND_METHOD:
+ res.statusCode = 405; //< 405 Method Not Allowed
+ break;
+ case exports.INVALID_REQ.MISSING_COMMAND_PARAMETER:
+ res.statusCode = 400; //< 400 Bad Request
+ break;
+ default:
+ res.statusCode = 404; //< 404 Not Found
+ break;
+ }
+
+ res.setHeader("Content-Type", "text/plain");
+ res.writeAndClose(this.name + " - " + this.message);
+};
+
+// Invalid Request Error Handler
+exports.createInvalidReqEH = function(errorName, req) {
+ var e = new Error();
+
+ e.name = errorName;
+ e.message = "Request => " + JSON.stringify(req);
+ e.handle = _invalidReqHandle;
+
+ return e;
+};
+exports.handleInvalidReqEH = function(errorName, req, res) {
+ exports.createInvalidReqEH(errorName, req).handle(res);
+};
+
+// Invalid Request Unknown Command Error Handler
+exports.createInvalidReqUnknownCommandEH = function(req) {
+ return exports.createInvalidReqEH (
+ exports.INVALID_REQ.UNKNOWN_COMMAND,
+ req);
+};
+exports.handleInvalidReqUnknownCommandEH = function(req, res) {
+ exports.createInvalidReqUnknownCommandEH(req).handle(res);
+};
+
+// Invalid Request Unimplemented Command Error Handler
+exports.createInvalidReqUnimplementedCommandEH = function(req) {
+ return exports.createInvalidReqEH (
+ exports.INVALID_REQ.UNIMPLEMENTED_COMMAND,
+ req);
+};
+exports.handleInvalidReqUnimplementedCommandEH = function(req, res) {
+ exports.createInvalidReqUnimplementedCommandEH(req).handle(res);
+};
+
+// Invalid Request Variable Resource Not Found Error Handler
+exports.createInvalidReqVariableResourceNotFoundEH = function(req) {
+ return exports.createInvalidReqEH (
+ exports.INVALID_REQ.VARIABLE_RESOURCE_NOT_FOUND,
+ req);
+};
+exports.handleInvalidReqVariableResourceNotFoundEH = function(req, res) {
+ exports.createInvalidReqVariableResourceNotFoundEH(req).handle(res);
+};
+
+// Invalid Request Invalid Command Method Error Handler
+exports.createInvalidReqInvalidCommandMethodEH = function(req) {
+ return exports.createInvalidReqEH (
+ exports.INVALID_REQ.INVALID_COMMAND_METHOD,
+ req);
+};
+exports.handleInvalidReqInvalidCommandMethodEH = function(req, res) {
+ exports.createInvalidReqInvalidCommandMethodEH(req).handle(res);
+};
+
+// Invalid Request Missing Command Parameter Error Handler
+exports.createInvalidReqMissingCommandParameterEH = function(req) {
+ return exports.createInvalidReqEH (
+ exports.INVALID_REQ.MISSING_COMMAND_PARAMETER,
+ req);
+};
+exports.handleInvalidReqMissingCommandParameterEH = function(req, res) {
+ exports.createInvalidReqMissingCommandParameterEH(req).handle(res);
+};
+
+//-------------------------------------------------------- Failed Command Errors
+//------ http://code.google.com/p/selenium/wiki/JsonWireProtocol#Failed_Commands
+exports.FAILED_CMD_STATUS = {
+ "SUCCESS" : "Success",
+ "NO_SUCH_ELEMENT" : "NoSuchElement",
+ "NO_SUCH_FRAME" : "NoSuchFrame",
+ "UNKNOWN_COMMAND" : "UnknownCommand",
+ "STALE_ELEMENT_REFERENCE" : "StaleElementReference",
+ "ELEMENT_NOT_VISIBLE" : "ElementNotVisible",
+ "INVALID_ELEMENT_STATE" : "InvalidElementState",
+ "UNKNOWN_ERROR" : "UnknownError",
+ "ELEMENT_IS_NOT_SELECTABLE" : "ElementIsNotSelectable",
+ "JAVA_SCRIPT_ERROR" : "JavaScriptError",
+ "XPATH_LOOKUP_ERROR" : "XPathLookupError",
+ "TIMEOUT" : "Timeout",
+ "NO_SUCH_WINDOW" : "NoSuchWindow",
+ "INVALID_COOKIE_DOMAIN" : "InvalidCookieDomain",
+ "UNABLE_TO_SET_COOKIE" : "UnableToSetCookie",
+ "UNEXPECTED_ALERT_OPEN" : "UnexpectedAlertOpen",
+ "NO_ALERT_OPEN_ERROR" : "NoAlertOpenError",
+ "SCRIPT_TIMEOUT" : "ScriptTimeout",
+ "INVALID_ELEMENT_COORDINATES" : "InvalidElementCoordinates",
+ "IME_NOT_AVAILABLE" : "IMENotAvailable",
+ "IME_ENGINE_ACTIVATION_FAILED" : "IMEEngineActivationFailed",
+ "INVALID_SELECTOR" : "InvalidSelector"
+};
+exports.FAILED_CMD_STATUS_CODES = {
+ "Success" : 0,
+ "NoSuchElement" : 7,
+ "NoSuchFrame" : 8,
+ "UnknownCommand" : 9,
+ "StaleElementReference" : 10,
+ "ElementNotVisible" : 11,
+ "InvalidElementState" : 12,
+ "UnknownError" : 13,
+ "ElementIsNotSelectable" : 15,
+ "JavaScriptError" : 17,
+ "XPathLookupError" : 19,
+ "Timeout" : 21,
+ "NoSuchWindow" : 23,
+ "InvalidCookieDomain" : 24,
+ "UnableToSetCookie" : 25,
+ "UnexpectedAlertOpen" : 26,
+ "NoAlertOpenError" : 27,
+ "ScriptTimeout" : 28,
+ "InvalidElementCoordinates" : 29,
+ "IMENotAvailable" : 30,
+ "IMEEngineActivationFailed" : 31,
+ "InvalidSelector" : 32
+};
+exports.FAILED_CMD_STATUS_CODES_NAMES = [];
+exports.FAILED_CMD_STATUS_CODES_NAMES[0] = "Success";
+exports.FAILED_CMD_STATUS_CODES_NAMES[7] = "NoSuchElement";
+exports.FAILED_CMD_STATUS_CODES_NAMES[8] = "NoSuchFrame";
+exports.FAILED_CMD_STATUS_CODES_NAMES[9] = "UnknownCommand";
+exports.FAILED_CMD_STATUS_CODES_NAMES[10] = "StaleElementReference";
+exports.FAILED_CMD_STATUS_CODES_NAMES[11] = "ElementNotVisible";
+exports.FAILED_CMD_STATUS_CODES_NAMES[12] = "InvalidElementState";
+exports.FAILED_CMD_STATUS_CODES_NAMES[13] = "UnknownError";
+exports.FAILED_CMD_STATUS_CODES_NAMES[15] = "ElementIsNotSelectable";
+exports.FAILED_CMD_STATUS_CODES_NAMES[17] = "JavaScriptError";
+exports.FAILED_CMD_STATUS_CODES_NAMES[19] = "XPathLookupError";
+exports.FAILED_CMD_STATUS_CODES_NAMES[21] = "Timeout";
+exports.FAILED_CMD_STATUS_CODES_NAMES[23] = "NoSuchWindow";
+exports.FAILED_CMD_STATUS_CODES_NAMES[24] = "InvalidCookieDomain";
+exports.FAILED_CMD_STATUS_CODES_NAMES[25] = "UnableToSetCookie";
+exports.FAILED_CMD_STATUS_CODES_NAMES[26] = "UnexpectedAlertOpen";
+exports.FAILED_CMD_STATUS_CODES_NAMES[27] = "NoAlertOpenError";
+exports.FAILED_CMD_STATUS_CODES_NAMES[28] = "ScriptTimeout";
+exports.FAILED_CMD_STATUS_CODES_NAMES[29] = "InvalidElementCoordinates";
+exports.FAILED_CMD_STATUS_CODES_NAMES[30] = "IMENotAvailable";
+exports.FAILED_CMD_STATUS_CODES_NAMES[31] = "IMEEngineActivationFailed";
+exports.FAILED_CMD_STATUS_CODES_NAMES[32] = "InvalidSelector";
+
+var _failedCommandHandle = function(res) {
+ // Generate response body
+ var body = {
+ "sessionId" : this.errorSessionId,
+ "status" : this.errorStatusCode,
+ "value" : {
+ "message" : this.message,
+ "screen" : this.errorScreenshot,
+ "class" : this.errorClassName
+ }
+ };
+
+ // Send it
+ res.statusCode = 500; //< 500 Internal Server Error
+ res.writeJSONAndClose(body);
+};
+
+// Failed Command Error Handler
+exports.createFailedCommandEH = function(errorName, errorMsg, req, session, className) {
+ var e = new Error();
+
+ e.name = errorName;
+ e.message = "Error Message => '" + errorMsg + "'\n" + " caused by Request => " + JSON.stringify(req);
+ e.errorStatusCode = exports.FAILED_CMD_STATUS_CODES[errorName] || 13; //< '13' Unkown Error
+ e.errorSessionId = session.getId() || null;
+ e.errorClassName = className || "unknown";
+ e.errorScreenshot = session.getCurrentWindow().renderBase64("png");
+ e.handle = _failedCommandHandle;
+
+ return e;
+};
+exports.handleFailedCommandEH = function(errorName, errorMsg, req, res, session, className) {
+ exports.createFailedCommandEH(errorName, errorMsg, req, session, className).handle(res);
+};
Oops, something went wrong.

0 comments on commit 18613c5

Please sign in to comment.