From 3d36c353fc6260981e41ce1ffebec53620f8c3f6 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 12 Apr 2013 09:16:52 -0300 Subject: [PATCH 01/36] Initial import Selenium binding --- library/test/selenium/readme.md | 27 +++ library/test/selenium/selenium-safe.ecf | 19 ++ library/test/selenium/src.rc | 6 + library/test/selenium/src/command_executor.e | 120 ++++++++++++ .../converter/se_build_value_json_converter.e | 72 +++++++ .../se_capabilities_json_converter.e | 185 ++++++++++++++++++ .../converter/se_java_value_json_converter.e | 51 +++++ .../src/converter/se_json_converter.e | 27 +++ .../converter/se_os_value_json_converter.e | 73 +++++++ .../converter/se_response_json_converter.e | 73 +++++++ .../src/converter/se_status_json_converter.e | 101 ++++++++++ .../se_status_value_json_converter.e | 70 +++++++ .../test/selenium/src/helpers/json_helper.e | 72 +++++++ .../src/protocol/se_json_wire_protocol.e | 162 +++++++++++++++ .../protocol/se_json_wire_protocol_commands.e | 116 +++++++++++ .../selenium/src/response/se_build_value.e | 63 ++++++ .../selenium/src/response/se_java_value.e | 36 ++++ .../test/selenium/src/response/se_os_value.e | 64 ++++++ .../test/selenium/src/response/se_response.e | 61 ++++++ .../test/selenium/src/response/se_status.e | 99 ++++++++++ .../selenium/src/response/se_status_value.e | 53 +++++ library/test/selenium/src/se_capabilities.e | 149 ++++++++++++++ library/test/selenium/src/se_error.e | 24 +++ library/test/selenium/src/se_session.e | 27 +++ library/test/selenium/src/web_driver_cookie.e | 69 +++++++ library/test/selenium/src/web_driver_log.e | 26 +++ library/test/selenium/src/web_driver_proxy.e | 47 +++++ library/test/selenium/src/web_element.e | 10 + library/test/selenium/test/application.e | 82 ++++++++ library/test/selenium/test/test-safe.ecf | 20 ++ library/test/selenium/test/test.rc | 6 + 31 files changed, 2010 insertions(+) create mode 100644 library/test/selenium/readme.md create mode 100644 library/test/selenium/selenium-safe.ecf create mode 100644 library/test/selenium/src.rc create mode 100644 library/test/selenium/src/command_executor.e create mode 100644 library/test/selenium/src/converter/se_build_value_json_converter.e create mode 100644 library/test/selenium/src/converter/se_capabilities_json_converter.e create mode 100644 library/test/selenium/src/converter/se_java_value_json_converter.e create mode 100644 library/test/selenium/src/converter/se_json_converter.e create mode 100644 library/test/selenium/src/converter/se_os_value_json_converter.e create mode 100644 library/test/selenium/src/converter/se_response_json_converter.e create mode 100644 library/test/selenium/src/converter/se_status_json_converter.e create mode 100644 library/test/selenium/src/converter/se_status_value_json_converter.e create mode 100644 library/test/selenium/src/helpers/json_helper.e create mode 100644 library/test/selenium/src/protocol/se_json_wire_protocol.e create mode 100644 library/test/selenium/src/protocol/se_json_wire_protocol_commands.e create mode 100644 library/test/selenium/src/response/se_build_value.e create mode 100644 library/test/selenium/src/response/se_java_value.e create mode 100644 library/test/selenium/src/response/se_os_value.e create mode 100644 library/test/selenium/src/response/se_response.e create mode 100644 library/test/selenium/src/response/se_status.e create mode 100644 library/test/selenium/src/response/se_status_value.e create mode 100644 library/test/selenium/src/se_capabilities.e create mode 100644 library/test/selenium/src/se_error.e create mode 100644 library/test/selenium/src/se_session.e create mode 100644 library/test/selenium/src/web_driver_cookie.e create mode 100644 library/test/selenium/src/web_driver_log.e create mode 100644 library/test/selenium/src/web_driver_proxy.e create mode 100644 library/test/selenium/src/web_element.e create mode 100644 library/test/selenium/test/application.e create mode 100644 library/test/selenium/test/test-safe.ecf create mode 100644 library/test/selenium/test/test.rc diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md new file mode 100644 index 00000000..88828519 --- /dev/null +++ b/library/test/selenium/readme.md @@ -0,0 +1,27 @@ +Eiffel Selenium binding +================================================= + +## Overview + +This client is a binding for the REST API interface defined in the WebDriver protocol http://code.google.com/p/selenium/wiki/JsonWireProtocol. + +WARNING this API is still under development, and maybe it will change + +## Requirements + +* Get the server selenium-server-standalone-#.jar file provided here: http://code.google.com/p/selenium/downloads/list + +* Download and run that file, replacing # with the current server version. + + java -jar selenium-server-standalone-#.jar + (it only has a Firefox WebDriver by default) + + But you can add other drivers doing something like that (change PATH_TO to the corresponding value in your environment) + java -jar selenium-server-standalone-2.32.0.jar + -Dwebdriver.chrome.driver=%PATH_TO%\chromedriver.exe -Dwebdriver.ie.driver=%PATH_TO%\IEDriverServer.exe + +## Getting Started + +TODO + + diff --git a/library/test/selenium/selenium-safe.ecf b/library/test/selenium/selenium-safe.ecf new file mode 100644 index 00000000..b09d84cf --- /dev/null +++ b/library/test/selenium/selenium-safe.ecf @@ -0,0 +1,19 @@ + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + diff --git a/library/test/selenium/src.rc b/library/test/selenium/src.rc new file mode 100644 index 00000000..b0ec159c --- /dev/null +++ b/library/test/selenium/src.rc @@ -0,0 +1,6 @@ +#include + +STRINGTABLE +BEGIN + 1 "This Program was made using EiffelStudio using Visual Studio C++" +END diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e new file mode 100644 index 00000000..961a60ab --- /dev/null +++ b/library/test/selenium/src/command_executor.e @@ -0,0 +1,120 @@ +note + description: "{COMMAND_EXECUTOR} object that execute a command in the JSONWireProtocol" + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=SELINIUM", "protocol=JSONWireProtocol", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#Commands" + +class + COMMAND_EXECUTOR +inherit + JSON_HELPER + SE_JSON_WIRE_PROTOCOL_COMMANDS + +create + make + +feature -- Initialization + make (a_host : STRING_32) + do + host := a_host + end + +feature -- Status Report + is_available : BOOLEAN + -- Is the Seleniun server up and running? + local + resp: HTTP_CLIENT_RESPONSE + do +-- resp := execute_get (cmd_ping) +-- if resp.status = 200 then +-- Result := True +-- end + Result := true + end +feature -- Commands + + status : SE_RESPONSE + require + selinum_server_available : is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_status) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + new_session (capabilities : STRING_32) : SE_RESPONSE + require + selinum_server_available : is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_new_session, capabilities) + if attached resp.body as l_body then + Result := build_response(l_body) + end + end + + sessions : SE_RESPONSE + require + selinum_server_available : is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_sessions) + if attached resp.body as l_body then + Result := build_response(l_body) + end + end + + +feature {NONE} -- Implementation + execute_get (command_name:STRING_32) : HTTP_CLIENT_RESPONSE + local + h: LIBCURL_HTTP_CLIENT + http_session : HTTP_CLIENT_SESSION + do + create h.make + http_session := h.new_session (host) + Result := http_session.get (command_name, context_executor) + end + + execute_post (command_name:STRING_32; data: STRING_32) : HTTP_CLIENT_RESPONSE + local + h: LIBCURL_HTTP_CLIENT + http_session : HTTP_CLIENT_SESSION + do + create h.make + http_session := h.new_session (host) + Result := http_session.post (command_name, context_executor, data) + + end + + + build_response (a_message : STRING_32) : SE_RESPONSE + do + create Result.make_empty + initialize_converters (json) + if attached {SE_RESPONSE} json.object_from_json (a_message, "SE_RESPONSE") as l_response then + Result := l_response + end + Result.set_json_response (a_message) + end + + + context_executor : HTTP_CLIENT_REQUEST_CONTEXT + -- request context for each request + once + create Result.make + Result.headers.put ("application/json;charset=UTF-8", "Content-Type") + Result.headers.put ("application/json;charset=UTF-8", "Accept") + end + + host : STRING_32 +end diff --git a/library/test/selenium/src/converter/se_build_value_json_converter.e b/library/test/selenium/src/converter/se_build_value_json_converter.e new file mode 100644 index 00000000..9c55d318 --- /dev/null +++ b/library/test/selenium/src/converter/se_build_value_json_converter.e @@ -0,0 +1,72 @@ +note + description: "Summary description for {SE_BUILD_VALUE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_BUILD_VALUE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_BUILD_VALUE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {STRING_32} json_to_object (j.item (version_key),Void) as l_item then + Result.set_version(l_item) + end + if attached {STRING_32} json_to_object (j.item (revision_key), Void) as l_item then + Result.set_revision(l_item) + end + if attached {STRING_32} json_to_object (j.item (time_key),Void) as l_item then + Result.set_time(l_item) + end + + + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.version), version_key) + Result.put (json.value (o.revision), revision_key) + Result.put (json.value (o.time), time_key) + end + +feature {NONE} -- Implementation + + + + version_key: JSON_STRING + once + create Result.make_json ("version") + end + + time_key: JSON_STRING + once + create Result.make_json ("time") + end + + revision_key: JSON_STRING + once + create Result.make_json ("revision") + end + +end diff --git a/library/test/selenium/src/converter/se_capabilities_json_converter.e b/library/test/selenium/src/converter/se_capabilities_json_converter.e new file mode 100644 index 00000000..29349de4 --- /dev/null +++ b/library/test/selenium/src/converter/se_capabilities_json_converter.e @@ -0,0 +1,185 @@ +note + description: "Summary description for {SE_CAPABILITIES_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_CAPABILITIES_JSON_CONVERTER + +inherit + + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make + end + +feature -- Access + + object: SE_CAPABILITIES + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make + if attached {STRING_32} json_to_object (j.item (browser_name_key), Void) as l_item then + Result.set_browser_name(l_item) + end + if attached {STRING_32} json_to_object (j.item (version_key), Void) as l_item then + Result.set_version(l_item) + end + if attached {STRING_32} json_to_object (j.item (platform_key), Void) as l_item then + Result.set_platform(l_item) + end + if attached {BOOLEAN} json_to_object (j.item (javascriptenabled_key), Void) as l_item then + Result.set_javascript_enabled(l_item) + end + if attached {BOOLEAN} json_to_object (j.item (takesscreenshot_key), Void) as l_item then + Result.set_takes_screenshot(l_item) + end + if attached {BOOLEAN} json_to_object (j.item (handlesalerts_key ), Void) as l_item then + Result.set_handles_alerts(l_item) + end + if attached {BOOLEAN} json_to_object (j.item (locationcontextenabled_key ), Void) as l_item then + Result.set_location_context_enabled (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (applicationcacheenabled_key ), Void) as l_item then + Result.set_application_cache_enabled (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (browserconnectionenabled_key ), Void) as l_item then + Result.set_browser_connection_enabled (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (cssselectorsenabled_key ), Void) as l_item then + Result.set_css_selectors_enabled (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (webstorageenabled_key ), Void) as l_item then + Result.set_web_storage_enabled (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (rotatable_key ), Void) as l_item then + Result.set_rotatable (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (acceptsslcerts_key ), Void) as l_item then + Result.set_accept_ssl_certs (l_item) + end + if attached {BOOLEAN} json_to_object (j.item (nativeevents_key ), Void) as l_item then + Result.set_native_events (l_item) + end + +-- if attached {WEB_DRIVER_PROXY} json_to_object (j.item (proxy_key), {WEB_DRIVER_PROXY}) as lv then +-- Result.set_proxy(lv) +-- end + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.browser_name),browser_name_key) + Result.put (json.value (o.version),version_key) + Result.put (json.value (o.platform),platform_key) + Result.put (json.value (o.is_javascript_enabled),javascriptenabled_key) + Result.put (json.value (o.takes_screenshot),takesscreenshot_key) + Result.put (json.value (o.handles_alerts),handlesalerts_key) + Result.put (json.value (o.is_database_enabled),databaseenabled_key) + Result.put (json.value (o.is_location_context_enabled),locationcontextenabled_key) + Result.put (json.value (o.is_application_cache_enabled),applicationcacheenabled_key) + Result.put (json.value (o.is_browser_connection_enabled),browserconnectionenabled_key) + Result.put (json.value (o.is_css_selectors_enabled),cssselectorsenabled_key) + Result.put (json.value (o.is_web_storage_enabled),webstorageenabled_key) + Result.put (json.value (o.is_rotatable),rotatable_key) + Result.put (json.value (o.accept_ssl_certs),acceptsslcerts_key) + Result.put (json.value (o.native_events),nativeevents_key) + --Result.put (json.value (o.proxy),proxy_key) + end + +feature {NONE} -- Implementation + + browser_name_key: JSON_STRING + once + create Result.make_json ("browserName") + end + + version_key: JSON_STRING + once + create Result.make_json ("version") + end + + platform_key: JSON_STRING + once + create Result.make_json ("platform") + end + + javascriptEnabled_key: JSON_STRING + once + create Result.make_json ("javascriptEnabled") + end + + takesScreenshot_key: JSON_STRING + once + create Result.make_json ("takesScreenshot") + end + + handlesAlerts_key: JSON_STRING + once + create Result.make_json ("handlesAlerts") + end + + databaseEnabled_key: JSON_STRING + once + create Result.make_json ("databaseEnabled") + end + + locationContextEnabled_key: JSON_STRING + once + create Result.make_json ("locationContextEnabled") + end + + applicationCacheEnabled_key: JSON_STRING + once + create Result.make_json ("applicationCacheEnabled") + end + + browserConnectionEnabled_key: JSON_STRING + once + create Result.make_json ("browserConnectionEnabled") + end + + cssSelectorsEnabled_key: JSON_STRING + once + create Result.make_json ("cssSelectorsEnabled") + end + + webStorageEnabled_key: JSON_STRING + once + create Result.make_json ("webStorageEnabled") + end + + rotatable_key: JSON_STRING + once + create Result.make_json ("rotatable") + end + + acceptSslCerts_key: JSON_STRING + once + create Result.make_json ("acceptSslCerts") + end + + nativeEvents_key: JSON_STRING + once + create Result.make_json ("nativeEvents") + end + + proxy_key: JSON_STRING + once + create Result.make_json ("proxy") + end + +end diff --git a/library/test/selenium/src/converter/se_java_value_json_converter.e b/library/test/selenium/src/converter/se_java_value_json_converter.e new file mode 100644 index 00000000..2385a42d --- /dev/null +++ b/library/test/selenium/src/converter/se_java_value_json_converter.e @@ -0,0 +1,51 @@ +note + description: "Summary description for {SE_JAVA_VALUE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_JAVA_VALUE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_JAVA_VALUE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {STRING_32} json_to_object (j.item (version_key), Void) as l_item then + Result.set_version(l_item) + end + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.version), version_key) + end + +feature {NONE} -- Implementation + + + + version_key: JSON_STRING + once + create Result.make_json ("version") + end + +end diff --git a/library/test/selenium/src/converter/se_json_converter.e b/library/test/selenium/src/converter/se_json_converter.e new file mode 100644 index 00000000..24c3b45b --- /dev/null +++ b/library/test/selenium/src/converter/se_json_converter.e @@ -0,0 +1,27 @@ +note + description: "Summary description for {SE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + SE_JSON_CONVERTER + +inherit + JSON_CONVERTER + +feature -- Convertion + + json_to_object (j: detachable JSON_VALUE; a_type: detachable TYPE [detachable ANY]): detachable ANY + local + l_classname: detachable STRING + do + if a_type /= Void then + l_classname := a_type.name + if l_classname.item (1) = '!' then + l_classname := l_classname.substring (2, l_classname.count) + end + end + Result := json.object (j, l_classname) + end +end diff --git a/library/test/selenium/src/converter/se_os_value_json_converter.e b/library/test/selenium/src/converter/se_os_value_json_converter.e new file mode 100644 index 00000000..6da07888 --- /dev/null +++ b/library/test/selenium/src/converter/se_os_value_json_converter.e @@ -0,0 +1,73 @@ +note + description: "Summary description for {SE_OS_VALUE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_OS_VALUE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_OS_VALUE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {STRING_32} json_to_object (j.item (version_key), Void) as l_item then + Result.set_version(l_item) + end + if attached {STRING_32} json_to_object (j.item (name_key), Void) as l_item then + Result.set_name(l_item) + end + if attached {STRING_32} json_to_object (j.item (architecture_key), Void) as l_item then + Result.set_architecture(l_item) + end + + + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.architecture), architecture_key) + Result.put (json.value (o.name), name_key) + Result.put (json.value (o.version), version_key) + end + +feature {NONE} -- Implementation + + + + version_key: JSON_STRING + once + create Result.make_json ("version") + end + + name_key: JSON_STRING + once + create Result.make_json ("name") + end + + architecture_key: JSON_STRING + once + create Result.make_json ("arch") + end + + +end diff --git a/library/test/selenium/src/converter/se_response_json_converter.e b/library/test/selenium/src/converter/se_response_json_converter.e new file mode 100644 index 00000000..4e28414f --- /dev/null +++ b/library/test/selenium/src/converter/se_response_json_converter.e @@ -0,0 +1,73 @@ +note + description: "Summary description for {SE_RESPONSE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_RESPONSE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_RESPONSE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {STRING_32} json_to_object (j.item (session_key), Void) as l_item then + Result.set_session_id(l_item) + end + if attached {INTEGER_32} json_to_object (j.item (status_key), Void) as l_item then + Result.set_status(l_item) + end + if attached {JSON_VALUE} j.item (value_key) as l_item then + Result.set_value(l_item.representation) + end + + + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.session_id),session_key) + Result.put (json.value (o.status), status_key) + Result.put (json.value (o.value), value_key) + end + +feature {NONE} -- Implementation + + + + session_key: JSON_STRING + once + create Result.make_json ("sessionId") + end + + status_key: JSON_STRING + once + create Result.make_json ("status") + end + + value_key: JSON_STRING + once + create Result.make_json ("value") + end + + +end diff --git a/library/test/selenium/src/converter/se_status_json_converter.e b/library/test/selenium/src/converter/se_status_json_converter.e new file mode 100644 index 00000000..ae1c379e --- /dev/null +++ b/library/test/selenium/src/converter/se_status_json_converter.e @@ -0,0 +1,101 @@ +note + description: "A converter for SE_STATUS" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_STATUS_JSON_CONVERTER + +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object + end + +feature -- Access + + object: SE_STATUS + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result + if attached {INTEGER_8} json_to_object (j.item (status_key), Void) as l_ucs then + Result.set_status (l_ucs.out) + end + if attached {STRING_32} json_to_object (j.item (session_id_key), Void) as l_ucs then + Result.set_session_id (l_ucs) + end + if attached {STRING_32} json_to_object (j.item (state_key), Void) as l_ucs then + Result.set_state (l_ucs) + end + if attached {STRING_32} json_to_object (j.item (class_name_key), Void) as l_ucs then + Result.set_class_name (l_ucs) + end + if attached {INTEGER_32} json_to_object (j.item (hash_code_key), Void) as l_ucs then + Result.set_hash_code (l_ucs.out) + end + if attached {SE_STATUS_VALUE} json_to_object (j.item (value_key), {SE_STATUS_VALUE}) as lv then + Result.set_value(lv) + end + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.status), status_key) + Result.put (json.value (o.session_id), session_id_key) + Result.put (json.value (o.value), value_key) + Result.put (json.value (o.state), state_key) + Result.put (json.value (o.class_name), class_name_key) + Result.put (json.value (o.hash_code), hash_code_key) + end + +feature {NONE} -- Implementation + + + + + status_key: JSON_STRING + once + create Result.make_json ("status") + end + + session_id_key: JSON_STRING + once + create Result.make_json ("sessionId") + end + + value_key: JSON_STRING + once + create Result.make_json ("value") + end + + state_key: JSON_STRING + once + create Result.make_json ("state") + end + + class_name_key: JSON_STRING + once + create Result.make_json ("class") + end + + hash_code_key : JSON_STRING + once + create Result.make_json ("hCode") + end + +note + copyright: "2011-2012, Javier Velilla, Jocelyn Fiat and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" +end diff --git a/library/test/selenium/src/converter/se_status_value_json_converter.e b/library/test/selenium/src/converter/se_status_value_json_converter.e new file mode 100644 index 00000000..2f8ad543 --- /dev/null +++ b/library/test/selenium/src/converter/se_status_value_json_converter.e @@ -0,0 +1,70 @@ +note + description: "Summary description for {SE_STATUS_VALUE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_STATUS_VALUE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_STATUS_VALUE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {SE_OS_VALUE} json_to_object (j.item (os_key), {SE_OS_VALUE}) as l_item then + Result.set_os_value(l_item) + end + if attached {SE_JAVA_VALUE} json_to_object (j.item (java_key), {SE_JAVA_VALUE}) as l_item then + Result.set_java_value(l_item) + end + if attached {SE_BUILD_VALUE} json_to_object (j.item (build_key), {SE_BUILD_VALUE}) as l_item then + Result.set_build_value(l_item) + end + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.os_value), os_key) + Result.put (json.value (o.java_value), java_key) + Result.put (json.value (o.build_value), build_key) + end + +feature {NONE} -- Implementation + + + + os_key: JSON_STRING + once + create Result.make_json ("os") + end + + java_key: JSON_STRING + once + create Result.make_json ("java") + end + + build_key: JSON_STRING + once + create Result.make_json ("build") + end + +end diff --git a/library/test/selenium/src/helpers/json_helper.e b/library/test/selenium/src/helpers/json_helper.e new file mode 100644 index 00000000..88b8fb3f --- /dev/null +++ b/library/test/selenium/src/helpers/json_helper.e @@ -0,0 +1,72 @@ +note + description: "Summary description for {JSON_HELPER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + JSON_HELPER +inherit + + SHARED_EJSON + +feature -- Access + to_json (an_object : ANY) :detachable JSON_VALUE + local + parser: JSON_PARSER + do + initialize_converters (json) + if attached json.value (an_object) as lv then + Result := lv + end + end + + string_to_json ( str: STRING_32): detachable JSON_VALUE + local + parser: JSON_PARSER + do + initialize_converters (json) + create parser.make_parser (str) + if attached parser.parse_object as st and parser.is_parsed then + Result := st + end + end + + json_to_se_status (post: STRING_32): detachable SE_STATUS + local + parser: JSON_PARSER + do + initialize_converters (json) + create parser.make_parser (post) + if attached parser.parse_object as st and parser.is_parsed then + if attached {SE_STATUS} json.object (st, "SE_STATUS") as l_status then + Result := l_status + end + end + end + + json_to_se_capabilities (post: STRING_32): detachable SE_CAPABILITIES + local + parser: JSON_PARSER + do + initialize_converters (json) + create parser.make_parser (post) + if attached parser.parse_object as st and parser.is_parsed then + if attached {SE_CAPABILITIES} json.object (st, "SE_CAPABILITIES") as l_capabilities then + Result := l_capabilities + end + end + end + + initialize_converters (j: like json) + -- Initialize json converters + do + j.add_converter (create {SE_STATUS_JSON_CONVERTER}.make) + j.add_converter (create {SE_BUILD_VALUE_JSON_CONVERTER}.make) + j.add_converter (create {SE_JAVA_VALUE_JSON_CONVERTER}.make) + j.add_converter (create {SE_OS_VALUE_JSON_CONVERTER}.make) + j.add_converter (create {SE_STATUS_VALUE_JSON_CONVERTER}.make) + j.add_converter (create {SE_CAPABILITIES_JSON_CONVERTER}.make) + j.add_converter (create {SE_RESPONSE_JSON_CONVERTER}.make) + end +end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e new file mode 100644 index 00000000..dca15c36 --- /dev/null +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -0,0 +1,162 @@ +note + description: "Summary description for {SE_JSON_WIRE_PROTOCOL}." + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=SELINIUM", "protocol=http", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol" + +class + SE_JSON_WIRE_PROTOCOL + +inherit + + JSON_HELPER + + SE_JSON_WIRE_PROTOCOL_COMMANDS + +create + make, make_with_host + +feature -- Initialization + + make + -- + local + h: LIBCURL_HTTP_CLIENT + do + create h.make + host := "http://127.0.0.1:4444/wd/hub/" + initialize_executor + end + + make_with_host (a_host: STRING_32) + -- + local + h: LIBCURL_HTTP_CLIENT + do + create h.make + host := a_host + initialize_executor + end + +feature -- Commands + + status: detachable SE_STATUS + -- GET /status + -- Query the server's current status. + -- The server should respond with a general "HTTP 200 OK" response if it is alive and accepting commands. + -- The response body should be a JSON object describing the state of the server. + -- All server implementations should return two basic objects describing the server's current platform and when the server was built. + -- All fields are optional; if omitted, the client should assume the value is uknown. + -- Furthermore, server implementations may include additional fields not listed here. + local + response : SE_RESPONSE + do + if commnad_executor.is_available then + + response := commnad_executor.status + if attached response.json_response as l_response then + Result := json_to_se_status (l_response) + end + else + -- TODO log the error. + -- Handling error + -- the Selenium server is not running or not it is reachable + end + end + + create_session_with_desired_capabilities (capabilities: SE_CAPABILITIES): detachable SE_SESSION + -- POST /session + -- Create a new session. + -- The server should attempt to create a session that most closely matches the desired and required capabilities. + -- Required capabilities have higher priority than desired capabilities and must be set for the session to be created. + -- JSON Parameters: + -- desiredCapabilities - {object} An object describing the session's desired capabilities. + -- requiredCapabilities - {object} An object describing the session's required capabilities (Optional). + -- Returns: + -- A 302 See Other redirect to /session/:sessionId, where :sessionId is the ID of the newly created session. + -- Potential Errors: + -- SessionNotCreatedException - If a required capability could not be set. + local + response : SE_RESPONSE + do + -- TODO, update the status of the server + -- SE_STATUS + -- SE_ERROR + -- create an COMMAND_EXECUTOR + if commnad_executor.is_available then + + if attached to_json (capabilities) as l_json then + response := commnad_executor.new_session(desired_capabilities (l_json.representation)) + if attached response.json_response as r_value then + Result := build_session (r_value) + end + end + else + end + end + + + sessions : detachable LIST[SE_SESSION] + -- GET /sessions + -- Returns a list of the currently active sessions. Each session will be returned as a list of JSON objects with the following keys: + -- id string The session ID. + -- capabilities object An object describing the session's capabilities. + local + response : SE_RESPONSE + index : INTEGER + do + if commnad_executor.is_available then + response := commnad_executor.sessions + if attached response.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST[SE_SESSION]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_OBJECT} l_json_array.i_th (index) as json_obj then + if attached build_session (json_obj.representation) as l_session then + Result.force ( l_session) + end + end + index := index + 1 + end + end + else + -- TODO handle error + end + + end + +feature {NONE} -- Implementation + initialize_executor + do + create commnad_executor.make ( host ) + end + + host: STRING_32 + + desired_capabilities (capabilites: STRING_32): STRING_32 + do + create Result.make_from_string (desired_capabilities_template) + Result.replace_substring_all ("$DESIRED_CAPABILITIES", capabilites) + end + + desired_capabilities_template: STRING = "[ + { + "desiredCapabilities": $DESIRED_CAPABILITIES + } + ]" + + commnad_executor : COMMAND_EXECUTOR + + build_session (value : STRING_32): detachable SE_SESSION + do + if attached {JSON_OBJECT} string_to_json (value) as l_value then + if attached l_value.item ("sessionId") as ls and then attached l_value.item ("value") as lv and then attached json_to_se_capabilities (lv.representation) as lc then + create Result.make (ls.representation, lc) + end + end + end +end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e new file mode 100644 index 00000000..243fc733 --- /dev/null +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -0,0 +1,116 @@ +note + description: "Summary description for {SE_JSON_WIRE_PROTOCOL_COMMANDS}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_JSON_WIRE_PROTOCOL_COMMANDS + + +feature + cmd_ping : STRING = "" + --GET / expected a 200 ok + + cmd_status : STRING = "status" + --GET /status Query the server's current status. + + cmd_new_session : STRING = "session" + --POST /session Create a new session. + cmd_sessions : STRING = "sessions" + --GET /sessions Returns a list of the currently active sessions. +--GET /session/:sessionId Retrieve the capabilities of the specified session. +--DELETE /session/:sessionId Delete the session. +--POST /session/:sessionId/timeouts Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. +--POST /session/:sessionId/timeouts/async_script Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. +--POST /session/:sessionId/timeouts/implicit_wait Set the amount of time the driver should wait when searching for elements. +--GET /session/:sessionId/window_handle Retrieve the current window handle. +--GET /session/:sessionId/window_handles Retrieve the list of all window handles available to the session. +--GET /session/:sessionId/url Retrieve the URL of the current page. +--POST /session/:sessionId/url Navigate to a new URL. +--POST /session/:sessionId/forward Navigate forwards in the browser history, if possible. +--POST /session/:sessionId/back Navigate backwards in the browser history, if possible. +--POST /session/:sessionId/refresh Refresh the current page. +--POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. +--POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. +--GET /session/:sessionId/screenshot Take a screenshot of the current page. +--GET /session/:sessionId/ime/available_engines List all available engines on the machine. +--GET /session/:sessionId/ime/active_engine Get the name of the active IME engine. +--GET /session/:sessionId/ime/activated Indicates whether IME input is active at the moment (not if it's available. +--POST /session/:sessionId/ime/deactivate De-activates the currently-active IME engine. +--POST /session/:sessionId/ime/activate Make an engines that is available (appears on the listreturned by getAvailableEngines) active. +--POST /session/:sessionId/frame Change focus to another frame on the page. +--POST /session/:sessionId/window Change focus to another window. +--DELETE /session/:sessionId/window Close the current window. +--POST /session/:sessionId/window/:windowHandle/size Change the size of the specified window. +--GET /session/:sessionId/window/:windowHandle/size Get the size of the specified window. +--POST /session/:sessionId/window/:windowHandle/position Change the position of the specified window. +--GET /session/:sessionId/window/:windowHandle/position Get the position of the specified window. +--POST /session/:sessionId/window/:windowHandle/maximize Maximize the specified window if not already maximized. +--GET /session/:sessionId/cookie Retrieve all cookies visible to the current page. +--POST /session/:sessionId/cookie Set a cookie. +--DELETE /session/:sessionId/cookie Delete all cookies visible to the current page. +--DELETE /session/:sessionId/cookie/:name Delete the cookie with the given name. +--GET /session/:sessionId/source Get the current page source. +--GET /session/:sessionId/title Get the current page title. +--POST /session/:sessionId/element Search for an element on the page, starting from the document root. +--POST /session/:sessionId/elements Search for multiple elements on the page, starting from the document root. +--POST /session/:sessionId/element/active Get the element on the page that currently has focus. +--GET /session/:sessionId/element/:id Describe the identified element. +--POST /session/:sessionId/element/:id/element Search for an element on the page, starting from the identified element. +--POST /session/:sessionId/element/:id/elements Search for multiple elements on the page, starting from the identified element. +--POST /session/:sessionId/element/:id/click Click on an element. +--POST /session/:sessionId/element/:id/submit Submit a FORM element. +--GET /session/:sessionId/element/:id/text Returns the visible text for the element. +--POST /session/:sessionId/element/:id/value Send a sequence of key strokes to an element. +--POST /session/:sessionId/keys Send a sequence of key strokes to the active element. +--GET /session/:sessionId/element/:id/name Query for an element's tag name. +--POST /session/:sessionId/element/:id/clear Clear a TEXTAREA or text INPUT element's value. +--GET /session/:sessionId/element/:id/selected Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. +--GET /session/:sessionId/element/:id/enabled Determine if an element is currently enabled. +--GET /session/:sessionId/element/:id/attribute/:name Get the value of an element's attribute. +--GET /session/:sessionId/element/:id/equals/:other Test if two element IDs refer to the same DOM element. +--GET /session/:sessionId/element/:id/displayed Determine if an element is currently displayed. +--GET /session/:sessionId/element/:id/location Determine an element's location on the page. +--GET /session/:sessionId/element/:id/location_in_view Determine an element's location on the screen once it has been scrolled into view. +--GET /session/:sessionId/element/:id/size Determine an element's size in pixels. +--GET /session/:sessionId/element/:id/css/:propertyName Query the value of an element's computed CSS property. +--GET /session/:sessionId/orientation Get the current browser orientation. +--POST /session/:sessionId/orientation Set the browser orientation. +--GET /session/:sessionId/alert_text Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. +--POST /session/:sessionId/alert_text Sends keystrokes to a JavaScript prompt() dialog. +--POST /session/:sessionId/accept_alert Accepts the currently displayed alert dialog. +--POST /session/:sessionId/dismiss_alert Dismisses the currently displayed alert dialog. +--POST /session/:sessionId/moveto Move the mouse by an offset of the specificed element. +--POST /session/:sessionId/click Click any mouse button (at the coordinates set by the last moveto command). +--POST /session/:sessionId/buttondown Click and hold the left mouse button (at the coordinates set by the last moveto command). +--POST /session/:sessionId/buttonup Releases the mouse button previously held (where the mouse is currently at). +--POST /session/:sessionId/doubleclick Double-clicks at the current mouse coordinates (set by moveto). +--POST /session/:sessionId/touch/click Single tap on the touch enabled device. +--POST /session/:sessionId/touch/down Finger down on the screen. +--POST /session/:sessionId/touch/up Finger up on the screen. +--POST /session/:sessionId/touch/move Finger move on the screen. +--POST /session/:sessionId/touch/scroll Scroll on the touch screen using finger based motion events. +--POST /session/:sessionId/touch/scroll Scroll on the touch screen using finger based motion events. +--POST /session/:sessionId/touch/doubleclick Double tap on the touch screen using finger motion events. +--POST /session/:sessionId/touch/longclick Long press on the touch screen using finger motion events. +--POST /session/:sessionId/touch/flick Flick on the touch screen using finger motion events. +--POST /session/:sessionId/touch/flick Flick on the touch screen using finger motion events. +--GET /session/:sessionId/location Get the current geo location. +--POST /session/:sessionId/location Set the current geo location. +--GET /session/:sessionId/local_storage Get all keys of the storage. +--POST /session/:sessionId/local_storage Set the storage item for the given key. +--DELETE /session/:sessionId/local_storage Clear the storage. +--GET /session/:sessionId/local_storage/key/:key Get the storage item for the given key. +--DELETE /session/:sessionId/local_storage/key/:key Remove the storage item for the given key. +--GET /session/:sessionId/local_storage/size Get the number of items in the storage. +--GET /session/:sessionId/session_storage Get all keys of the storage. +--POST /session/:sessionId/session_storage Set the storage item for the given key. +--DELETE /session/:sessionId/session_storage Clear the storage. +--GET /session/:sessionId/session_storage/key/:key Get the storage item for the given key. +--DELETE /session/:sessionId/session_storage/key/:key Remove the storage item for the given key. +--GET /session/:sessionId/session_storage/size Get the number of items in the storage. +--POST /session/:sessionId/log Get the log for a given log type. +--GET /session/:sessionId/log/types Get available log types. +--GET /session/:sessionId/application_cache/status Get the status of the html5 application cache. +end diff --git a/library/test/selenium/src/response/se_build_value.e b/library/test/selenium/src/response/se_build_value.e new file mode 100644 index 00000000..f0cd4dfd --- /dev/null +++ b/library/test/selenium/src/response/se_build_value.e @@ -0,0 +1,63 @@ +note + description: "Object that describe the build information from the current server" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_BUILD_VALUE + +create + make, + make_empty + +feature{NONE} -- Initialization + make ( a_version : STRING_32; a_revision: STRING_32; a_time: STRING_32) + do + set_version(a_version) + set_revision (a_revision) + set_time (a_time) + end + + make_empty + do + + end + +feature -- Access + version : detachable STRING_32 + -- A generic release label (i.e. "2.0rc3") + + revision : detachable STRING_32 + --The revision of the local source control client from which the server was built + + time : detachable STRING_32 + --A timestamp from when the server was built. + +feature -- Change Element + set_version (a_version : STRING_32) + -- Set version with `a_version' + do + version := a_version + ensure + version_assigned : version ~ a_version + end + + + set_revision (a_revision : STRING_32) + -- Set revision with `a_revision' + do + revision := a_revision + ensure + revision_assigned : revision ~ a_revision + end + + + set_time (a_time : STRING_32) + -- Set time with `a_time' + do + time := a_time + ensure + time_assigned : time ~ a_time + end +end diff --git a/library/test/selenium/src/response/se_java_value.e b/library/test/selenium/src/response/se_java_value.e new file mode 100644 index 00000000..3daffd14 --- /dev/null +++ b/library/test/selenium/src/response/se_java_value.e @@ -0,0 +1,36 @@ +note + description: "Object that describe the current verion of Java" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_JAVA_VALUE + +create + make, + make_empty + +feature -- Initialization + make ( a_version : STRING_32) + do + set_version (a_version) + end + make_empty + do + + end + +feature -- Access + version : detachable STRING_32 + -- current Java version + +feature -- Change Element + set_version (a_version: STRING_32) + --Set version with `a_version' + do + version := a_version + ensure + version_assigned : version ~ a_version + end +end diff --git a/library/test/selenium/src/response/se_os_value.e b/library/test/selenium/src/response/se_os_value.e new file mode 100644 index 00000000..13d44843 --- /dev/null +++ b/library/test/selenium/src/response/se_os_value.e @@ -0,0 +1,64 @@ +note + description: "Object that describe the OS information from the current server" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_OS_VALUE + +create + make, + make_empty + + +feature{NONE} -- Initialization + make ( an_architecture : STRING_32; a_name: STRING_32; a_version: STRING_32) + do + set_version(a_version) + set_name (a_name) + set_architecture (an_architecture) + end + + make_empty + do + + end + +feature -- Access + architecture : detachable STRING_32 + -- The current system architecture. + + name : detachable STRING_32 + -- The name of the operating system the server is currently running on: "windows", "linux", etc. + + version : detachable STRING_32 + --The operating system version. + +feature -- Change Element + set_version (a_version : STRING_32) + -- Set version with `a_version' + do + version := a_version + ensure + version_assigned : version ~ a_version + end + + + set_name (a_name : STRING_32) + -- Set name with `a_name' + do + name := a_name + ensure + name_assigned : name ~ a_name + end + + + set_architecture (an_architecture : STRING_32) + -- Set architecture with `an_architecture' + do + architecture := an_architecture + ensure + architecture_assigned : architecture ~ an_architecture + end +end diff --git a/library/test/selenium/src/response/se_response.e b/library/test/selenium/src/response/se_response.e new file mode 100644 index 00000000..8e444e63 --- /dev/null +++ b/library/test/selenium/src/response/se_response.e @@ -0,0 +1,61 @@ +note + description: "Object that represent Command responses from Seleniun JSONWireProtocol" + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=SELINIUM", "protocol=JsonWireProtocol", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#Responses" + +class + SE_RESPONSE + +create + make, + make_empty + +feature -- Initialization + make (a_session_id : STRING_32; a_status: INTEGER_32; a_value : STRING_32) + do + session_id := a_session_id + status := a_status + value := a_value + end + + make_empty + do + + end +feature -- Access + session_id : detachable STRING_32 + -- An opaque handle used by the server to determine where to route session-specific commands. + -- This ID should be included in all future session-commands in place of the :sessionId path segment variable. + + status : INTEGER_32 + -- A status code summarizing the result of the command. A non-zero value indicates that the command failed. + + value : detachable STRING_32 + -- The response JSON value. + +feature -- Change Element + set_session_id ( a_session_id : STRING_32) + do + session_id := a_session_id + end + + set_status ( a_status : INTEGER_32) + do + status := a_status + end + + set_value (a_value : STRING_32) + do + value := a_value + end + +feature -- JSON Response + json_response : detachable STRING_32 + + set_json_response ( a_response : STRING_32) + do + json_response := a_response + end +end diff --git a/library/test/selenium/src/response/se_status.e b/library/test/selenium/src/response/se_status.e new file mode 100644 index 00000000..ecc8b060 --- /dev/null +++ b/library/test/selenium/src/response/se_status.e @@ -0,0 +1,99 @@ +note + description: "Object representation of JSON response describing the state of the server" + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=status", "protocol=http", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/status" + +class + SE_STATUS +inherit + ANY + redefine + out + end + +feature -- Access + status: detachable STRING_32 + session_id: detachable STRING_32 + state: detachable STRING_32 + class_name: detachable STRING_32 + value : detachable SE_STATUS_VALUE + hash_code: detachable STRING_32 + +feature -- Change Element + set_status (a_status : STRING_32) + do + status := a_status + end + + set_session_id (a_session_id : STRING_32) + do + session_id := a_session_id + end + + set_state (a_state : STRING_32) + do + state := a_state + end + + set_class_name (a_class_name : STRING_32) + do + class_name := a_class_name + end + + set_value (a_value : SE_STATUS_VALUE) + do + value := a_value + end + + set_hash_code (a_hash_code : STRING_32) + do + hash_code := a_hash_code + end + + out : STRING + do + create Result.make_from_string ("Response : ") + if attached status as l_satus then + Result.append ("[Status:") + Result.append (l_satus.out) + Result.append ("]") + Result.append (" ") + end + if attached session_id as l_session_id then + Result.append ("[SessionId:") + Result.append (l_session_id.out) + Result.append ("]") + Result.append (" ") + end + if attached state as l_state then + Result.append ("[State:") + Result.append (l_state.out) + Result.append ("]") + Result.append (" ") + end + if attached value as l_value then + Result.append ("[value:") + Result.append (l_value.out) + Result.append ("]") + Result.append (" ") + end + + if attached class_name as l_class_name then + Result.append ("[Class Name:") + Result.append (l_class_name.out) + Result.append ("]") + Result.append (" ") + end + + if attached hash_code as l_hash_code then + Result.append ("[hCode:") + Result.append (l_hash_code.out) + Result.append ("]") + Result.append (" ") + end + + + end +end diff --git a/library/test/selenium/src/response/se_status_value.e b/library/test/selenium/src/response/se_status_value.e new file mode 100644 index 00000000..8a785740 --- /dev/null +++ b/library/test/selenium/src/response/se_status_value.e @@ -0,0 +1,53 @@ +note + description: "Summary description for {STATUS}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_STATUS_VALUE +create + make, + make_empty + +feature {NONE}-- Initialization + make (an_os_value : SE_OS_VALUE; a_java_value :SE_JAVA_VALUE; a_build_value: SE_BUILD_VALUE ) + do + set_os_value (an_os_value) + set_java_value (a_java_value) + set_build_value (a_build_value) + end + + make_empty + do + + end +feature -- Access + os_value: detachable SE_OS_VALUE + + java_value : detachable SE_JAVA_VALUE + + build_value : detachable SE_BUILD_VALUE + +feature -- Change Element + set_os_value (an_os_value : SE_OS_VALUE) + -- Set os_value with `an_os_value' + do + os_value := an_os_value + end + + set_build_value (a_build_value : SE_BUILD_VALUE) + -- Set build_value with `a_build_value' + do + build_value := a_build_value + end + + set_java_value (a_java_value : SE_JAVA_VALUE) + -- Set java_value with `a_java_value' + do + + java_value := a_java_value + end + + +end diff --git a/library/test/selenium/src/se_capabilities.e b/library/test/selenium/src/se_capabilities.e new file mode 100644 index 00000000..e551b1b4 --- /dev/null +++ b/library/test/selenium/src/se_capabilities.e @@ -0,0 +1,149 @@ +note + description: "Object that describe available features a client can submit in a WebDriver session. Not all server implementations will support every WebDriver feature." + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=Capabilities", "protocl=http", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#Desired_Capabilities" +class + SE_CAPABILITIES + +create + make +feature -- Initialization + make + -- defaults initializations + do + end + +feature -- Access + browser_name : detachable STRING_32 + --The name of the browser being used; should be one of {chrome|firefox|htmlunit|internet explorer|iphone} + + version : detachable STRING_32 + -- The browser version, or the empty string if unknown. + + platform : detachable STRING_32 + -- A key specifying which platform the browser is running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX}. + -- When requesting a new session, the client may specify ANY to indicate any available platform may be used. + + is_javascript_enabled : BOOLEAN + --Whether the session supports executing user supplied JavaScript in the context of the current page. + + takes_screenshot : BOOLEAN + --Whether the session supports taking screenshots of the current page. + + handles_alerts : BOOLEAN + --Whether the session can interact with modal popups, such as window.alert and window.confirm. + + is_database_enabled : BOOLEAN + --Whether the session can interact database storage. + + is_location_context_enabled : BOOLEAN + --Whether the session can set and query the browser's location context. + + is_application_cache_enabled : BOOLEAN + --Whether the session can interact with the application cache. + + is_browser_connection_enabled : BOOLEAN + --Whether the session can query for the browser's connectivity and disable it if desired. + + is_css_selectors_enabled : BOOLEAN + --Whether the session supports CSS selectors when searching for elements. + + is_web_storage_enabled : BOOLEAN + --Whether the session supports interactions with storage objects. + + is_rotatable : BOOLEAN + --Whether the session can rotate the current page's current layout between portrait and landscape orientations (only applies to mobile platforms). + + accept_ssl_certs : BOOLEAN + --Whether the session should accept all SSL certs by default. + + native_events : BOOLEAN + --Whether the session is capable of generating native events when simulating user input. + + proxy : detachable WEB_DRIVER_PROXY + --Details of any proxy to use. If no proxy is specified, whatever the system's current or default state is used. The format is specified under Proxy JSON Object. + +feature -- Change Elemenet + set_browser_name (a_browser_name : STRING_32) + do + browser_name := a_browser_name + end + + set_version (a_version : STRING_32) + do + version := a_version + end + + set_platform (a_platform : STRING_32) + do + platform := a_platform + end + + set_javascript_enabled ( value : BOOLEAN) + do + is_javascript_enabled := value + end + + set_takes_screenshot (value : BOOLEAN) + do + takes_screenshot := value + end + + set_handles_alerts ( value: BOOLEAN) + do + handles_alerts := value + end + + set_database_enabled (value : BOOLEAN) + do + is_database_enabled := value + end + + set_location_context_enabled (value:BOOLEAN) + do + is_location_context_enabled := value + end + + set_application_cache_enabled (value : BOOLEAN) + do + is_application_cache_enabled := value + end + + set_browser_connection_enabled (value : BOOLEAN) + do + is_browser_connection_enabled := value + end + + set_css_selectors_enabled (value : BOOLEAN) + do + is_css_selectors_enabled := value + end + + set_web_storage_enabled (value : BOOLEAN) + do + is_web_storage_enabled := value + end + + set_rotatable (value : BOOLEAN) + do + is_rotatable := value + end + + set_accept_ssl_certs (value : BOOLEAN) + do + accept_ssl_certs := value + end + + set_native_events ( value : BOOLEAN) + do + native_events := value + end + + set_proxy ( a_proxy : WEB_DRIVER_PROXY) + do + proxy := a_proxy + end + +end diff --git a/library/test/selenium/src/se_error.e b/library/test/selenium/src/se_error.e new file mode 100644 index 00000000..42236c89 --- /dev/null +++ b/library/test/selenium/src/se_error.e @@ -0,0 +1,24 @@ +note + description: "Summary description for {SE_ERROR}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_ERROR + +create + make +feature -- Initialization + make (a_code : INTEGER_32; a_summary : STRING_32; a_detail : STRING_32) + do + code := a_code + summary := a_summary + detail := a_detail + end + +feature -- Access + code : INTEGER_32 + summary : STRING_32 + detail : STRING_32 +end diff --git a/library/test/selenium/src/se_session.e b/library/test/selenium/src/se_session.e new file mode 100644 index 00000000..66ed2fce --- /dev/null +++ b/library/test/selenium/src/se_session.e @@ -0,0 +1,27 @@ +note + description: "Object that represent an active session" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_SESSION + +create + make +feature -- Initializaton + make (a_session_id : STRING_32; a_capabilities: SE_CAPABILITIES) + do + session_id := a_session_id + capabilities := a_capabilities + end + +feature -- Access + + session_id : STRING_32 + -- The session id. + + capabilities : SE_CAPABILITIES + -- An object describing the session's capabilities. + +end diff --git a/library/test/selenium/src/web_driver_cookie.e b/library/test/selenium/src/web_driver_cookie.e new file mode 100644 index 00000000..311a5bdb --- /dev/null +++ b/library/test/selenium/src/web_driver_cookie.e @@ -0,0 +1,69 @@ +note + description: "Object that describe a cookie. When returning Cookie objects, the server should only omit an optional field if it is incapable of providing the information." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_DRIVER_COOKIE + +create + make +feature {NONE}-- Initialization + make (a_name : STRING_32; a_value: STRING_32) + do + set_name (a_name) + set_value (a_value) + end + +feature -- Access + name : STRING_32 + --The name of the cookie. + + value : STRING_32 + -- The cookie value. + + path : detachable STRING_32 + --(Optional) The cookie path + + domain : detachable STRING_32 + --(Optional) The domain the cookie is visible to. + + secure : BOOLEAN + --(Optional) Whether the cookie is a secure cookie + + expiry : NATURAL_32 + -- (Optional) When the cookie expires, specified in seconds since midnight, January 1, 1970 UTC.1 + +feature -- Change Element + set_name (a_name:STRING_32) + do + name := a_name + end + + set_value (a_value:STRING_32) + do + value := a_value + end + + set_path (a_path : STRING_32) + do + path := a_path + end + + set_domain (a_domain : STRING_32) + do + domain := a_domain + end + + set_secure (a_value : BOOLEAN) + do + secure := a_value + end + + set_expiry ( a_value : NATURAL_32) + do + expiry := a_value + end + +end diff --git a/library/test/selenium/src/web_driver_log.e b/library/test/selenium/src/web_driver_log.e new file mode 100644 index 00000000..1c2924c9 --- /dev/null +++ b/library/test/selenium/src/web_driver_log.e @@ -0,0 +1,26 @@ +note + description: "Object describing a log entry" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_DRIVER_LOG +feature + + timestamp : NATURAL_32 + --The timestamp of the entry. + + level : detachable STRING_32 + --The log level of the entry, for example, "INFO" (see log levels). + --ALL All log messages. Used for fetching of logs and configuration of logging. + --DEBUG Messages for debugging. + --INFO Messages with user information. + --WARNING Messages corresponding to non-critical problems. + --SEVERE Messages corresponding to critical errors. + --OFF No log messages. Used for configuration of logging. + + message : detachable STRING_32 + --The log message. + +end diff --git a/library/test/selenium/src/web_driver_proxy.e b/library/test/selenium/src/web_driver_proxy.e new file mode 100644 index 00000000..1aacaca8 --- /dev/null +++ b/library/test/selenium/src/web_driver_proxy.e @@ -0,0 +1,47 @@ +note + description: "A JSON object describing a Proxy configuration." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_DRIVER_PROXY +create + make + +feature -- Initialization + make (a_proxy_type : STRING_32) + do + set_proxy_type(a_proxy_type) + end +feature -- Access + + proxy_type: STRING_32 + --(Required) The type of proxy being used. + --Possible values are: + -- direct - A direct connection - + -- no proxy in use, + -- manual - Manual proxy settings configured, + -- e.g. setting a proxy for HTTP, a proxy for FTP, etc, + -- pac - Proxy autoconfiguration from a URL), + -- autodetect (proxy autodetection, probably with WPAD, + -- system - Use system settings + + proxy_auto_config_url : detachable STRING_32 + --(Required if proxyType == pac, Ignored otherwise) + -- Specifies the URL to be used for proxy autoconfiguration. Expected format example: http://hostname.com:1234/pacfile + + ftp_proxy : detachable STRING_32 + http_proxy: detachable STRING_32 + ssl_Proxy : detachable STRING_32 + --(Optional, Ignored if proxyType != manual) Specifies the proxies to be used for FTP, HTTP and HTTPS requests respectively. + --Behaviour is undefined if a request is made, where the proxy for the particular protocol is undefined, if proxyType is manual. + --Expected format example: hostname.com:1234 + + +feature -- Element Change + set_proxy_type (a_proxy_type : STRING_32) + do + proxy_type := a_proxy_type + end +end diff --git a/library/test/selenium/src/web_element.e b/library/test/selenium/src/web_element.e new file mode 100644 index 00000000..7147d82e --- /dev/null +++ b/library/test/selenium/src/web_element.e @@ -0,0 +1,10 @@ +note + description: "An object in the WebDriver API that represents a DOM element on the page." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_ELEMENT + +end diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e new file mode 100644 index 00000000..a27397ae --- /dev/null +++ b/library/test/selenium/test/application.e @@ -0,0 +1,82 @@ +note + description : "test application root class" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION + +inherit + ARGUMENTS + +create + make + +feature {NONE} -- Initialization + + make + local + web_driver: SE_JSON_WIRE_PROTOCOL + capabilities : SE_CAPABILITIES + do + -- check if the selenium Remote WebDriver is up and running. + create web_driver.make + if attached web_driver.status as l_status then + print (l_status) + + -- retrieve sessions + if attached web_driver.sessions as l_session then + across l_session as item loop + print (item) + end + end + + -- create a new session + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then + print ("%NSessionId:" + l_session.session_id) + end + + + -- retrieve sessions + if attached web_driver.sessions as l_session then + across l_session as item loop + print (item) + end + end + + else + print ("The selenium server is not accesible") + end + + end + + test_session + local + h: LIBCURL_HTTP_CLIENT + session: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + s := "[ + { + "desiredCapabilities" : { + "browserName":"firefox" + } + } + ]" + + + session := h.new_session ("http://localhost:4444/wd/hub/") + create context.make + context.headers.put ("application/json;charset=UTF-8", "Content-Type") + context.headers.put ("application/json;charset=UTF-8", "Accept") + resp := session.post ("session", context,s) + print(resp) + end +end diff --git a/library/test/selenium/test/test-safe.ecf b/library/test/selenium/test/test-safe.ecf new file mode 100644 index 00000000..de82f16f --- /dev/null +++ b/library/test/selenium/test/test-safe.ecf @@ -0,0 +1,20 @@ + + + + + + + + + + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + diff --git a/library/test/selenium/test/test.rc b/library/test/selenium/test/test.rc new file mode 100644 index 00000000..b0ec159c --- /dev/null +++ b/library/test/selenium/test/test.rc @@ -0,0 +1,6 @@ +#include + +STRINGTABLE +BEGIN + 1 "This Program was made using EiffelStudio using Visual Studio C++" +END From 6ead464a6b5c94805f8909945259d08bb10e8de0 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 12 Apr 2013 09:38:04 -0300 Subject: [PATCH 02/36] Fixed configurations paths --- library/server/wsf/tests/server/test.e | 2 +- library/test/selenium/selenium-safe.ecf | 2 +- library/test/selenium/test/test-safe.ecf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/server/wsf/tests/server/test.e b/library/server/wsf/tests/server/test.e index 5cd52363..7a95af2b 100644 --- a/library/server/wsf/tests/server/test.e +++ b/library/server/wsf/tests/server/test.e @@ -15,7 +15,7 @@ feature {NONE} -- Initialization -- Initialize `Current'. do print ("Test Server that could be used for autotest%N") --- base_url := "/test/" + base_url := "/test/" set_service_option ("port", 9091) set_service_option ("verbose", True) diff --git a/library/test/selenium/selenium-safe.ecf b/library/test/selenium/selenium-safe.ecf index b09d84cf..a9335f48 100644 --- a/library/test/selenium/selenium-safe.ecf +++ b/library/test/selenium/selenium-safe.ecf @@ -7,7 +7,7 @@ - + /EIFGENs$ diff --git a/library/test/selenium/test/test-safe.ecf b/library/test/selenium/test/test-safe.ecf index de82f16f..8ca22e1f 100644 --- a/library/test/selenium/test/test-safe.ecf +++ b/library/test/selenium/test/test-safe.ecf @@ -8,7 +8,7 @@ - + /EIFGENs$ From 1daab0598aff4f040a849e8c637c1e1cbff73829 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 15 Apr 2013 09:40:17 -0300 Subject: [PATCH 03/36] Improved error handling, implemented more methods from the REST API from Selenium2 --- .../se_timeout_type_json_converter.e | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 library/test/selenium/src/converter/se_timeout_type_json_converter.e diff --git a/library/test/selenium/src/converter/se_timeout_type_json_converter.e b/library/test/selenium/src/converter/se_timeout_type_json_converter.e new file mode 100644 index 00000000..9551ee01 --- /dev/null +++ b/library/test/selenium/src/converter/se_timeout_type_json_converter.e @@ -0,0 +1,60 @@ +note + description: "Summary description for {SE_TIMEOUT_TYPE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_TIMEOUT_TYPE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object.make_empty + end + +feature -- Access + + object: SE_TIMEOUT_TYPE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result.make_empty + if attached {STRING_32} json_to_object (j.item (type_key), Void) as l_item then + Result.set_type(l_item) + end + if attached {INTEGER_32} json_to_object (j.item (ms_key), Void) as l_item then + Result.set_ms (l_item) + end + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.type),type_key) + Result.put (json.value (o.ms), ms_key) + end + +feature {NONE} -- Implementation + + + type_key: JSON_STRING + once + create Result.make_json ("type") + end + + ms_key: JSON_STRING + once + create Result.make_json ("ms") + end + + +end From c63e30717902e521b1f38e2c7840637b4d0410b7 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 15 Apr 2013 16:16:16 -0300 Subject: [PATCH 04/36] Updated RestAPI commands --- library/test/selenium/src/command_executor.e | 398 +++- .../src/converter/se_status_json_converter.e | 4 +- .../test/selenium/src/helpers/json_helper.e | 3 +- .../src/protocol/se_json_wire_protocol.e | 1612 ++++++++++++++++- .../protocol/se_json_wire_protocol_commands.e | 157 +- .../test/selenium/src/response/se_status.e | 15 +- library/test/selenium/src/se_error.e | 9 + library/test/selenium/src/se_timeout_type.e | 45 + library/test/selenium/src/web_element.e | 16 + library/test/selenium/test/application.e | 17 +- .../test/selenium/test/exception_trace.log | 28 + 11 files changed, 2183 insertions(+), 121 deletions(-) create mode 100644 library/test/selenium/src/se_timeout_type.e create mode 100644 library/test/selenium/test/exception_trace.log diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index 961a60ab..22f0081e 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -7,36 +7,45 @@ note class COMMAND_EXECUTOR + inherit + JSON_HELPER + SE_JSON_WIRE_PROTOCOL_COMMANDS +-- TODO +-- clean and improve the code +-- handle response from the server in a smart way create make feature -- Initialization - make (a_host : STRING_32) + + make (a_host: STRING_32) + local + h: LIBCURL_HTTP_CLIENT do host := a_host + create h.make + http_session := h.new_session (a_host) + -- http_session.set_is_debug (True) + -- http_session.set_proxy ("127.0.0.1", 8888) end feature -- Status Report - is_available : BOOLEAN - -- Is the Seleniun server up and running? - local - resp: HTTP_CLIENT_RESPONSE + + is_available: BOOLEAN + -- Is the Seleniun server up and running? do --- resp := execute_get (cmd_ping) --- if resp.status = 200 then --- Result := True --- end - Result := true + Result := http_session.is_available end + feature -- Commands - status : SE_RESPONSE + status: SE_RESPONSE require - selinum_server_available : is_available + selinum_server_available: is_available local resp: HTTP_CLIENT_RESPONSE do @@ -47,57 +56,358 @@ feature -- Commands end end - new_session (capabilities : STRING_32) : SE_RESPONSE + new_session (capabilities: STRING_32): SE_RESPONSE require - selinum_server_available : is_available + selinum_server_available: is_available local resp: HTTP_CLIENT_RESPONSE do create Result.make_empty resp := execute_post (cmd_new_session, capabilities) - if attached resp.body as l_body then - Result := build_response(l_body) + if attached resp.header ("Location") as l_location then + resp := http_new_session (l_location).get ("", context_executor) + if attached resp.body as l_body then + Result := build_response (l_body) + end end end - sessions : SE_RESPONSE + sessions: SE_RESPONSE require - selinum_server_available : is_available + selinum_server_available: is_available local resp: HTTP_CLIENT_RESPONSE do create Result.make_empty resp := execute_get (cmd_sessions) if attached resp.body as l_body then - Result := build_response(l_body) + Result := build_response (l_body) end end + retrieve_session (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_by_id (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + delete_session (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_delete (cmd_session_by_id (cmd_session_by_id (session_id))) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + set_session_timeouts (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_timeouts (a_session_id), a_data_timeout) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + set_session_timeouts_async_script (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_timeouts_async_script (a_session_id), a_data_timeout) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + end + + set_session_timeouts_implicit_wait (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_timeouts_implicit_wait (a_session_id), a_data_timeout) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + end + + retrieve_window_handle (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_window_handle (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + retrieve_window_handles (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_window_handles (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + retrieve_url (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_url (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + navigate_to_url (a_session_id: STRING_32; a_url: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_url (a_session_id), a_url) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + forward (a_session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_forward (a_session_id), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + back (a_session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_back (a_session_id), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + refresh (a_session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_refresh (a_session_id), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + execute + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + -- TODO + end + + execute_async + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + -- TODO + end + + screenshot (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_screenshot (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + ime_available_engines (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_ime_available (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + ime_active_engine (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_ime_active_engine (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + ime_activated (session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_ime_activated (session_id)) + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + ime_deactivate (a_session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_ime_deactivate (a_session_id), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + end + + ime_activate (a_session_id: STRING_32; an_engine: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_ime_activate (a_session_id), an_engine) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := build_response (l_body) + end + end + + end feature {NONE} -- Implementation - execute_get (command_name:STRING_32) : HTTP_CLIENT_RESPONSE - local - h: LIBCURL_HTTP_CLIENT - http_session : HTTP_CLIENT_SESSION + + execute_get (command_name: STRING_32): HTTP_CLIENT_RESPONSE do - create h.make - http_session := h.new_session (host) Result := http_session.get (command_name, context_executor) end - execute_post (command_name:STRING_32; data: STRING_32) : HTTP_CLIENT_RESPONSE - local - h: LIBCURL_HTTP_CLIENT - http_session : HTTP_CLIENT_SESSION + execute_post (command_name: STRING_32; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE do - create h.make - http_session := h.new_session (host) Result := http_session.post (command_name, context_executor, data) - end + execute_delete (command_name: STRING_32): HTTP_CLIENT_RESPONSE + do + Result := http_session.delete (command_name, context_executor) + end - build_response (a_message : STRING_32) : SE_RESPONSE + build_response (a_message: STRING_32): SE_RESPONSE do create Result.make_empty initialize_converters (json) @@ -107,14 +417,26 @@ feature {NONE} -- Implementation Result.set_json_response (a_message) end - - context_executor : HTTP_CLIENT_REQUEST_CONTEXT - -- request context for each request - once + context_executor: HTTP_CLIENT_REQUEST_CONTEXT + -- request context for each request + do create Result.make Result.headers.put ("application/json;charset=UTF-8", "Content-Type") Result.headers.put ("application/json;charset=UTF-8", "Accept") end - host : STRING_32 + host: STRING_32 + + http_session: HTTP_CLIENT_SESSION + + http_new_session (url: STRING_32): HTTP_CLIENT_SESSION + local + h: LIBCURL_HTTP_CLIENT + do + create h.make + Result := h.new_session (url) + -- Result.set_is_debug (True) + -- Result.set_proxy ("127.0.0.1", 8888) + end + end diff --git a/library/test/selenium/src/converter/se_status_json_converter.e b/library/test/selenium/src/converter/se_status_json_converter.e index ae1c379e..789c9232 100644 --- a/library/test/selenium/src/converter/se_status_json_converter.e +++ b/library/test/selenium/src/converter/se_status_json_converter.e @@ -29,8 +29,8 @@ feature -- Conversion from_json (j: like to_json): detachable like object do create Result - if attached {INTEGER_8} json_to_object (j.item (status_key), Void) as l_ucs then - Result.set_status (l_ucs.out) + if attached {INTEGER_32} json_to_object (j.item (status_key), Void) as l_ucs then + Result.set_status (l_ucs) end if attached {STRING_32} json_to_object (j.item (session_id_key), Void) as l_ucs then Result.set_session_id (l_ucs) diff --git a/library/test/selenium/src/helpers/json_helper.e b/library/test/selenium/src/helpers/json_helper.e index 88b8fb3f..90dd1c4f 100644 --- a/library/test/selenium/src/helpers/json_helper.e +++ b/library/test/selenium/src/helpers/json_helper.e @@ -27,7 +27,7 @@ feature -- Access do initialize_converters (json) create parser.make_parser (str) - if attached parser.parse_object as st and parser.is_parsed then + if attached parser.parse as st and parser.is_parsed then Result := st end end @@ -68,5 +68,6 @@ feature -- Access j.add_converter (create {SE_STATUS_VALUE_JSON_CONVERTER}.make) j.add_converter (create {SE_CAPABILITIES_JSON_CONVERTER}.make) j.add_converter (create {SE_RESPONSE_JSON_CONVERTER}.make) + j.add_converter (create {SE_TIMEOUT_TYPE_JSON_CONVERTER}.make) end end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index dca15c36..3e960b2b 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -39,6 +39,14 @@ feature -- Initialization initialize_executor end +feature -- Access + + has_error: BOOLEAN + -- Did an error occur in the last request? + -- There are two types of errors: invalid requests and failed commands. + + last_error: detachable SE_ERROR + feature -- Commands status: detachable SE_STATUS @@ -50,18 +58,16 @@ feature -- Commands -- All fields are optional; if omitted, the client should assume the value is uknown. -- Furthermore, server implementations may include additional fields not listed here. local - response : SE_RESPONSE + response: SE_RESPONSE do if commnad_executor.is_available then - response := commnad_executor.status - if attached response.json_response as l_response then - Result := json_to_se_status (l_response) - end - else - -- TODO log the error. - -- Handling error - -- the Selenium server is not running or not it is reachable + check_response (response) + if not has_error then + if attached response.json_response as l_response then + Result := json_to_se_status (l_response) + end + end end end @@ -70,69 +76,1514 @@ feature -- Commands -- Create a new session. -- The server should attempt to create a session that most closely matches the desired and required capabilities. -- Required capabilities have higher priority than desired capabilities and must be set for the session to be created. - -- JSON Parameters: + -- JSON Parameters: -- desiredCapabilities - {object} An object describing the session's desired capabilities. -- requiredCapabilities - {object} An object describing the session's required capabilities (Optional). - -- Returns: + -- Returns: -- A 302 See Other redirect to /session/:sessionId, where :sessionId is the ID of the newly created session. - -- Potential Errors: + -- Potential Errors: -- SessionNotCreatedException - If a required capability could not be set. local - response : SE_RESPONSE + response: SE_RESPONSE do - -- TODO, update the status of the server - -- SE_STATUS - -- SE_ERROR - -- create an COMMAND_EXECUTOR + -- TODO, update the status of the server + -- SE_STATUS + -- SE_ERROR + -- create an COMMAND_EXECUTOR if commnad_executor.is_available then - if attached to_json (capabilities) as l_json then - response := commnad_executor.new_session(desired_capabilities (l_json.representation)) - if attached response.json_response as r_value then - Result := build_session (r_value) + response := commnad_executor.new_session (desired_capabilities (l_json.representation)) + check_response (response) + if not has_error then + if attached response.json_response as r_value then + Result := build_session (r_value, "session") + end end end - else end end + sessions: detachable LIST [SE_SESSION] + -- GET /sessions + -- Returns a list of the currently active sessions. Each session will be returned as a list of JSON objects with the following keys: + -- id string The session ID. + -- capabilities object An object describing the session's capabilities. + -- Returns: + -- {Array.} A list of the currently active sessions. - sessions : detachable LIST[SE_SESSION] - -- GET /sessions - -- Returns a list of the currently active sessions. Each session will be returned as a list of JSON objects with the following keys: - -- id string The session ID. - -- capabilities object An object describing the session's capabilities. local - response : SE_RESPONSE - index : INTEGER + response: SE_RESPONSE + index: INTEGER do if commnad_executor.is_available then response := commnad_executor.sessions - if attached response.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then - create {ARRAYED_LIST[SE_SESSION]} Result.make (10) - from - index := 1 - until - index > l_json_array.count - loop - if attached {JSON_OBJECT} l_json_array.i_th (index) as json_obj then - if attached build_session (json_obj.representation) as l_session then - Result.force ( l_session) + check_response (response) + if not has_error then + if attached response.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [SE_SESSION]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_OBJECT} l_json_array.i_th (index) as json_obj then + if attached build_session (json_obj.representation, "sessions") as l_session then + Result.force (l_session) + end end + index := index + 1 end - index := index + 1 end end - else - -- TODO handle error end + end + retrieve_session (a_session_id: STRING_32): detachable SE_SESSION + -- GET /session/:sessionId + -- Retrieve the capabilities of the specified session. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {object} An object describing the session's capabilities. + local + response : SE_RESPONSE + do + if commnad_executor.is_available then + response := commnad_executor.retrieve_session (a_session_id) + check_response (response) + if not has_error then + if attached response.json_response as r_value then + Result := build_session (r_value, "session") + end + end + end + end + + delete_session (a_session_id: STRING) + -- DELETE /session/:sessionId + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.delete_session (a_session_id) + check_response (resp) + end + end + + set_session_timeouts (a_session_id: STRING_32; a_timeout_type: SE_TIMEOUT_TYPE) + -- POST /session/:sessionId/timeouts + -- Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- type - {string} The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout. + -- ms - {number} The amount of time, in milliseconds, that time-limited commands are permitted to run. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + if attached to_json (a_timeout_type) as l_json then + resp := commnad_executor.set_session_timeouts (a_session_id, l_json.representation) + check_response (resp) + end + end + end + + set_session_timeouts_async_script (a_session_id: STRING_32; ms: INTEGER_32) + -- POST /session/:sessionId/timeouts/async_script + -- Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async + -- are permitted to run before they are aborted and a |Timeout| error is returned to the client. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- ms - {number} The amount of time, in milliseconds, that time-limited commands are permitted to run. + local + l_timeout: SE_TIMEOUT_TYPE + resp: SE_RESPONSE + do + create l_timeout.make_empty + l_timeout.set_ms (ms) + if commnad_executor.is_available then + if attached to_json (l_timeout) as l_json then + resp := commnad_executor.set_session_timeouts_async_script (a_session_id, l_json.representation) + check_response (resp) + end + end + end + + set_session_timeouts_implicit_wait (a_session_id: STRING_32; ms: NATURAL_32) + -- POST /session/:sessionId/timeouts/implicit_wait + -- Set the amount of time the driver should wait when searching for elements. When searching for a single element, the driver should poll the page until an element is found or the timeout expires, whichever occurs first. When searching for multiple elements, the driver should poll the page until at least one element is found or the timeout expires, at which point it should return an empty list. + -- If this command is never sent, the driver should default to an implicit wait of 0ms. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- ms - {number} The amount of time to wait, in milliseconds. This value has a lower bound of 0. + local + l_timeout: SE_TIMEOUT_TYPE + resp: SE_RESPONSE + do + create l_timeout.make_empty + l_timeout.set_ms (ms.as_integer_32) + if commnad_executor.is_available then + if attached to_json (l_timeout) as l_json then + resp := commnad_executor.set_session_timeouts_implicit_wait (a_session_id, l_json.representation) + check_response (resp) + end + end + end + + retrieve_window_handle (a_session_id: STRING_32): detachable STRING_32 + -- GET /session/:sessionId/window_handle + -- Retrieve the current window handle. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The current window handle. + --Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.retrieve_window_handle (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end + end + + retrieve_window_handles (a_session_id: STRING_32): detachable LIST [STRING_32] + -- GET /session/:sessionId/window_handles + -- Retrieve the list of all window handles available to the session. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} A list of window handles. + + local + resp: SE_RESPONSE + index: INTEGER_32 + do + if commnad_executor.is_available then + resp := commnad_executor.retrieve_window_handles (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [STRING_32]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_STRING} l_json_array.i_th (index) as json_str then + Result.force (json_str.representation) + end + index := index + 1 + end + end + end + end + end + + retrieve_url (a_session_id: STRING_32): detachable STRING_32 + -- GET /session/:sessionId/url + -- Retrieve the URL of the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The current URL. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.retrieve_url (a_session_id) + check_response (resp) + if has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end + end + + navigate_to_url (a_session_id: STRING_32; an_url: STRING_32) + -- POST /session/:sessionId/url + -- Navigate to a new URL. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- url - {string} The URL to navigate to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + l_json: STRING_32 + resp: SE_RESPONSE + do + l_json := "[ + { "url": $url } + ]" + l_json.replace_substring_all ("$url", an_url) + if commnad_executor.is_available then + resp := commnad_executor.navigate_to_url (a_session_id, l_json) + check_response (resp) + end + end + + forward (a_session_id: STRING_32) + -- POST /session/:sessionId/forward + -- Navigate forwards in the browser history, if possible. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.forward (a_session_id) + check_response (resp) + end + end + + back (a_session_id: STRING_32) + -- POST /session/:sessionId/back + -- Navigate backwards in the browser history, if possible. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.back (a_session_id) + check_response (resp) + end + end + + refresh (a_session_id: STRING_32) + -- POST /session/:sessionId/refresh + -- Refresh the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.refresh (a_session_id) + check_response (resp) + end + end + + execute (a_session_id: STRING_32) + -- POST /session/:sessionId/execute + -- Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. + -- The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client. + -- The script argument defines the script to execute in the form of a function body. The value returned by that function will be returned to the client. + -- The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified. + + -- Arguments may be any JSON-primitive, array, or JSON object. JSON objects that define a + -- WebElement reference will be converted to the corresponding DOM element. + -- Likewise, any WebElements in the script result will be returned to the client as WebElement JSON objects. + + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- script - {string} The script to execute. + -- args - {Array.<*>} The script arguments. + -- Returns: + -- {*} The script result. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If one of the script arguments is a WebElement that is not attached to the page's DOM. + -- JavaScriptError - If the script throws an Error. + do + --TODO + end + + execute_async (a_session_id: STRING_32) + -- POST /session/:sessionId/execute_async + -- Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, which is always provided as the final argument to the function. The value to this callback will be returned to the client. + -- Asynchronous script commands may not span page loads. If an unload event is fired while waiting for a script result, an error should be returned to the client. + -- The script argument defines the script to execute in teh form of a function body. The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified. The final argument will always be a callback function that must be invoked to signal that the script has finished. + -- Arguments may be any JSON-primitive, array, or JSON object. JSON objects that define a WebElement reference will be converted to the corresponding DOM element. Likewise, any WebElements in the script result will be returned to the client as WebElement JSON objects. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- script - {string} The script to execute. + -- args - {Array.<*>} The script arguments. + -- Returns: + -- {*} The script result. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If one of the script arguments is a WebElement that is not attached to the page's DOM. + -- Timeout - If the script callback is not invoked before the timout expires. Timeouts are controlled by the /session/:sessionId/timeout/async_script command. + -- JavaScriptError - If the script throws an Error or if an unload event is fired while waiting for the script to finish. + do + --TODO + end + + screenshot (a_session_id: STRING_32): detachable STRING_32 + -- GET /session/:sessionId/screenshot + -- Take a screenshot of the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The screenshot as a base64 encoded PNG. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.screenshot (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end + end + + ime_available_engines (a_session_id: STRING_32): detachable LIST [STRING_32] + -- GET /session/:sessionId/ime/available_engines + -- List all available engines on the machine. To use an engine, it has to be present in this list. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} A list of available engines + -- Potential Errors: + -- ImeNotAvailableException - If the host does not support IME + local + resp: SE_RESPONSE + index: INTEGER_32 + do + if commnad_executor.is_available then + resp := commnad_executor.ime_available_engines (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [STRING_32]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_STRING} l_json_array.i_th (index) as json_str then + Result.force (json_str.representation) + end + index := index + 1 + end + end + end + end + end + + ime_active_engine (a_session_id: STRING_32): detachable STRING_32 + -- GET /session/:sessionId/ime/active_engine + -- Get the name of the active IME engine. The name string is platform specific. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The name of the active IME engine. + -- Potential Errors: + -- ImeNotAvailableException - If the host does not support IME + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.ime_active_engine (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end + end + + ime_activated (a_session_id: STRING_32): BOOLEAN + -- GET /session/:sessionId/ime/activated + -- Indicates whether IME input is active at the moment (not if it's available. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {boolean} true if IME input is available and currently active, false otherwise + -- Potential Errors: + -- ImeNotAvailableException - If the host does not support IME + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.ime_active_engine (a_session_id) + check_response (resp) + if not has_error then + if attached {BOOLEAN} resp.value as l_value then + Result := l_value + end + end + end + end + + ime_deactivate (a_session_id: STRING_32) + -- POST /session/:sessionId/ime/deactivate + -- De-activates the currently-active IME engine. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- ImeNotAvailableException - If the host does not support IME + local + resp: SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.ime_deactivate (a_session_id) + check_response (resp) + end + end + + ime_activate (a_session_id: STRING_32; an_engine: STRING_32) + -- POST /session/:sessionId/ime/activate + -- Make an engines that is available (appears on the list returned by getAvailableEngines) active. After this call, the engine will be added to the list of engines loaded in the IME daemon and the input sent using sendKeys will be converted by the active engine. Note that this is a platform-independent method of activating IME (the platform-specific way being using keyboard shortcuts + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- engine - {string} Name of the engine to activate. + -- Potential Errors: + -- ImeActivationFailedException - If the engine is not available or if the activation fails for other reasons. + -- ImeNotAvailableException - If the host does not support IME + local + l_json: STRING_32 + resp: SE_RESPONSE + do + l_json := "[ + { "engine": $engine } + ]" + l_json.replace_substring_all ("$engine", an_engine) + if commnad_executor.is_available then + resp := commnad_executor.ime_activate (a_session_id, l_json) + check_response (resp) + end + end + + frame (a_session_id: STRING_32) + -- POST /session/:sessionId/frame + -- Change focus to another frame on the page. If the frame id is null, the server should switch to the page's default content. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- id - {string|number|null|WebElement JSON Object} Identifier for the frame to change focus to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- NoSuchFrame - If the frame specified by id cannot be found. + do + -- TODO + end + + change_focus_window (a_session_id: STRING_32; a_name: STRING_32) + -- POST /session/:sessionId/window + -- Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- name - {string} The window to change focus to. + -- Potential Errors: + -- NoSuchWindow - If the window specified by name cannot be found. + do + -- TODO + end + + close_window (a_session_id: STRING_32) + -- DELETE /session/:sessionId/window + -- Close the current window. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window is already closed + do + --TODO + end + + change_size_window (a_session_id: STRING_32; a_window_handle: STRING_32) + -- POST /session/:sessionId/window/:windowHandle/size + -- Change the size of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be resized. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- width - {number} The new window width. + -- height - {number} The new window height. + do + end + + size_window (a_session_id: STRING_32; a_window_handle: STRING_32) + -- GET /session/:sessionId/window/:windowHandle/size + -- Get the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {width: number, height: number} The size of the window. + -- Potential Errors: + -- NoSuchWindow - If the specified window cannot be found. + do + --TODO + end + + change_window_position (a_session_id: STRING_32; a_window_handle: STRING_32) + -- POST /session/:sessionId/window/:windowHandle/position + -- Change the position of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be moved. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- x - {number} The X coordinate to position the window at, relative to the upper left corner of the screen. + -- y - {number} The Y coordinate to position the window at, relative to the upper left corner of the screen. + -- Potential Errors: + -- NoSuchWindow - If the specified window cannot be found. + do + -- TODO + end + + window_position (a_sesion_id: STRING_32; a_window_handle: STRING_32) + -- GET /session/:sessionId/window/:windowHandle/position + -- Get the position of the specified window. If the :windowHandle URL parameter is "current", the position of the currently active window will be returned. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {x: number, y: number} The X and Y coordinates for the window, relative to the upper left corner of the screen. + -- Potential Errors: + -- NoSuchWindow - If the specified window cannot be found. + do + --TODO + end + + window_maximize (a_session_id: STRING_32; a_window_haNdle: STRING_32) + -- POST /session/:sessionId/window/:windowHandle/maximize + -- Maximize the specified window if not already maximized. If the :windowHandle URL parameter is "current", the currently active window will be maximized. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the specified window cannot be found. + do + end + + retrieve_cookies (a_session_id: STRING_32) + -- GET /session/:sessionId/cookie + -- Retrieve all cookies visible to the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} A list of cookies. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + set_cookie (a_session_id: STRING_32) + -- POST /session/:sessionId/cookie + -- Set a cookie. If the cookie path is not specified, it should be set to "/". Likewise, if the domain is omitted, it should default to the current page's domain. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- cookie - {object} A JSON object defining the cookie to add. + do + -- TODO + end + + delete_cookies (a_session_id: STRING_32) + -- DELETE /session/:sessionId/cookie + -- Delete all cookies visible to the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- InvalidCookieDomain - If the cookie's domain is not visible from the current page. + -- NoSuchWindow - If the currently selected window has been closed. + -- UnableToSetCookie - If attempting to set a cookie on a page that does not support cookies (e.g. pages with mime-type text/plain). + do + -- TODO + end + + delete_cookie_by_name (a_session_id: STRING_32; a_name: STRING_32) + -- DELETE /session/:sessionId/cookie/:name + -- Delete the cookie with the given name. This command should be a no-op if there is no such cookie visible to the current page. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :name - The name of the cookie to delete. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + -- TODO + end + + page_source (a_session_id: STRING_32) + -- GET /session/:sessionId/source + -- Get the current page source. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The current page source. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + page_title (a_session_id: STRING_32) + -- GET /session/:sessionId/title + -- Get the current page title. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The current page title. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + -- TODO + end + + search_element (a_session_id: STRING_32) + -- POST /session/:sessionId/element + -- Search for an element on the page, starting from the document root. The located element will be returned as a + -- WebElement JSON object. The table below lists the locator strategies that each server should support. + -- Each locator must return the first matching element located in the DOM. + -- + -- Strategy Description + -- class name Returns an element whose class name contains the search value; compound class names are not permitted. + -- css selector Returns an element matching a CSS selector. + -- id Returns an element whose ID attribute matches the search value. + -- name Returns an element whose NAME attribute matches the search value. + -- link text Returns an anchor element whose visible text matches the search value. + -- partial link text Returns an anchor element whose visible text partially matches the search value. + -- tag name Returns an element whose tag name matches the search value. + -- xpath Returns an element matching an XPath expression. + -- + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- using - {string} The locator strategy to use. + -- value - {string} The The search target. + -- Returns: + -- {ELEMENT:string} A WebElement JSON object for the located element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- NoSuchElement - If the element cannot be found. + -- XPathLookupError - If using XPath and the input expression is invalid. + do + -- TODO + end + + search_elements (a_session_id: STRING_32) + -- POST /session/:sessionId/elements + -- Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. The table below lists the locator strategies that each server should support. Elements should be returned in the order located in the DOM. + -- + -- Strategy Description + -- class name Returns an element whose class name contains the search value; compound class names are not permitted. + -- css selector Returns an element matching a CSS selector. + -- id Returns an element whose ID attribute matches the search value. + -- name Returns an element whose NAME attribute matches the search value. + -- link text Returns an anchor element whose visible text matches the search value. + -- partial link text Returns an anchor element whose visible text partially matches the search value. + -- tag name Returns an element whose tag name matches the search value. + -- xpath Returns an element matching an XPath expression. + -- + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- using - {string} The locator strategy to use. + -- value - {string} The The search target. + -- Returns: + -- {Array.<{ELEMENT:string}>} A list of WebElement JSON objects for the located elements. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- XPathLookupError - If using XPath and the input expression is invalid. + do + end + + element_active (a_session_id: STRING_32) + -- POST /session/:sessionId/element/active + -- Get the element on the page that currently has focus. The element will be returned as a WebElement JSON object. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {ELEMENT:string} A WebElement JSON object for the active element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + element_id (a_session_id: STRING_32) + -- GET /session/:sessionId/element/:id + -- Describe the identified element. + -- Note: This command is reserved for future use; its return type is currently undefined. + + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + search_element_id (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/element + -- Search for an element on the page, starting from the identified element. + -- The located element will be returned as a WebElement JSON object. + -- The table below lists the locator strategies that each server should support. + -- Each locator must return the first matching element located in the DOM. + -- + -- Strategy Description + -- class name Returns an element whose class name contains the search value; compound class names are not permitted. + -- css selector Returns an element matching a CSS selector. + -- id Returns an element whose ID attribute matches the search value. + -- name Returns an element whose NAME attribute matches the search value. + -- link text Returns an anchor element whose visible text matches the search value. + -- partial link text Returns an anchor element whose visible text partially matches the search value. + -- tag name Returns an element whose tag name matches the search value. + -- xpath Returns an element matching an XPath expression. + -- + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- JSON Parameters: + -- using - {string} The locator strategy to use. + -- value - {string} The The search target. + -- Returns: + -- {ELEMENT:string} A WebElement JSON object for the located element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- NoSuchElement - If the element cannot be found. + -- XPathLookupError - If using XPath and the input expression is invalid. + do + end + + search_elements_id (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/elements + -- Search for multiple elements on the page, starting from the identified element. + -- The located elements will be returned as a WebElement JSON objects. + -- The table below lists the locator strategies that each server should support. + -- Elements should be returned in the order located in the DOM. + -- + -- Strategy Description + -- class name Returns an element whose class name contains the search value; compound class names are not permitted. + -- css selector Returns an element matching a CSS selector. + -- id Returns an element whose ID attribute matches the search value. + -- name Returns an element whose NAME attribute matches the search value. + -- link text Returns an anchor element whose visible text matches the search value. + -- partial link text Returns an anchor element whose visible text partially matches the search value. + -- tag name Returns an element whose tag name matches the search value. + -- xpath Returns an element matching an XPath expression. + -- + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- JSON Parameters: + -- using - {string} The locator strategy to use. + -- value - {string} The The search target. + -- Returns: + -- {Array.<{ELEMENT:string}>} A list of WebElement JSON objects for the located elements. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- XPathLookupError - If using XPath and the input expression is invalid. + do + end + + element_click (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/click + -- Click on an element. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) + do + end + + element_submit (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/submit + -- Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + element_text (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/text + -- Returns the visible text for the element. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + send_event (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/value + -- Send a sequence of key strokes to an element. + -- Any UTF-8 character may be specified, however, if the server does not support native key events, + -- it should simulate key strokes for a standard US keyboard layout. + -- The Unicode Private Use Area code points, 0xE000-0xF8FF, are used to represent pressable, non-text keys (see table below). + -- Key Code Key Code Key Code Key Code Key Code + -- NULL U+E000 Space U+E00D Numpad 0 U+E01A Multiply U+E024 F1 U+E031 + -- Cancel U+E001 Pageup U+E00E Numpad 1 U+E01B Add U+E025 F2 U+E032 + -- Help U+E002 Pagedown U+E00F Numpad 2 U+E01C Separator U+E026 F3 U+E033 + -- Back space U+E003 End U+E010 Numpad 3 U+E01D Subtract U+E027 F4 U+E034 + -- Tab U+E004 Home U+E011 Numpad 4 U+E01E Decimal U+E028 F5 U+E035 + -- Clear U+E005 Left arrow U+E012 Numpad 5 U+E01F Divide U+E029 F6 U+E036 + -- Return1 U+E006 Up arrow U+E013 Numpad 6 U+E020 F7 U+E037 + -- Enter1 U+E007 Right arrow U+E014 Numpad 7 U+E021 F8 U+E038 + -- Shift U+E008 Down arrow U+E015 Numpad 8 U+E022 F9 U+E039 + -- Control U+E009 Insert U+E016 Numpad 9 U+E023 F10 U+E03A + -- Alt U+E00A Delete U+E017 F11 U+E03B + -- Pause U+E00B Semicolon U+E018 F12 U+E03C + -- Escape U+E00C Equals U+E019 Command/Meta U+E03D + -- 1 The return key is not the same as the enter key. + -- The server must process the key sequence as follows: + + -- Each key that appears on the keyboard without requiring modifiers are sent as a keydown followed by a key up. + -- If the server does not support native events and must simulate key strokes with JavaScript, it must generate keydown, keypress, and keyup events, in that order. The keypress event should only be fired when the corresponding key is for a printable character. + -- If a key requires a modifier key (e.g. "!" on a standard US keyboard), the sequence is: modifier down, key down, key up, modifier up, where key is the ideal unmodified key value (using the previous example, a "1"). + -- Modifier keys (Ctrl, Shift, Alt, and Command/Meta) are assumed to be "sticky"; each modifier should be held down (e.g. only a keydown event) until either the modifier is encountered again in the sequence, or the NULL (U+E000) key is encountered. + -- Each key sequence is terminated with an implicit NULL key. Subsequently, all depressed modifier keys must be released (with corresponding keyup events) at the end of the sequence. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- JSON Parameters: + -- value - {Array.} The sequence of keys to type. An array must be provided. The server should flatten the array items to a single string to be typed. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) + do + end + + send_key_strokes (a_session_id: STRING_32) + -- POST /session/:sessionId/keys + -- Send a sequence of key strokes to the active element. This command is similar to the send keys command in every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- value - {Array.} The keys sequence to be sent. The sequence is defined in thesend keys command. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + query_by_tag_name (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/name + -- Query for an element's tag name. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {string} The element's tag name, as a lowercase string. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + clear (a_session_id: STRING_32; an_id: STRING_32) + -- POST /session/:sessionId/element/:id/clear + -- Clear a TEXTAREA or text INPUT element's value. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) + -- InvalidElementState - If the referenced element is disabled. + do + end + + is_selected (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/selected + -- Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {boolean} Whether the element is selected. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + is_enabled (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/enabled + -- Determine if an element is currently enabled. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {boolean} Whether the element is enabled. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + element_value (a_session_id: STRING_32; an_id: STRING_32; a_name: STRING_32) + -- GET /session/:sessionId/element/:id/attribute/:name + -- Get the value of an element's attribute. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {string|null} The value of the attribute, or null if it is not set on the element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + elements_equals (a_session_id: STRING_32; an_id: STRING_32; an_other: STRING_32) + -- GET /session/:sessionId/element/:id/equals/:other + -- Test if two element IDs refer to the same DOM element. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- :other - ID of the element to compare against. + -- Returns: + -- {boolean} Whether the two IDs refer to the same element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If either the element refered to by :id or :other is no longer attached to the page's DOM. + do + end + + is_displayed (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/displayed + -- Determine if an element is currently displayed. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {boolean} Whether the element is displayed. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + element_location (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/location + -- Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. + -- The element's coordinates are returned as a JSON object with x and y properties. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {x:number, y:number} The X and Y coordinates for the element on the page. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + is_location_in_view (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/location_in_view + -- Determine an element's location on the screen once it has been scrolled into view. + -- Note: This is considered an internal command and should only be used to determine an element's + -- location for correctly generating native events. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {x:number, y:number} The X and Y coordinates for the element. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + element_size (a_session_id: STRING_32; an_id: STRING_32) + -- GET /session/:sessionId/element/:id/size + -- Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {width:number, height:number} The width and height of the element, in pixels. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + element_css_value (a_session_id: STRING_32; an_id: STRING_32; a_property_name: STRING_32) + -- GET /session/:sessionId/element/:id/css/:propertyName + -- Query the value of an element's computed CSS property. The CSS property to query should be specified using the CSS property name, not the JavaScript property name (e.g. background-color instead of backgroundColor). + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :id - ID of the element to route the command to. + -- Returns: + -- {string} The value of the specified CSS property. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + do + end + + retrieve_browser_orientation (a_session_id: STRING_32) + -- GET /session/:sessionId/orientation + -- Get the current browser orientation. The server should return a valid orientation value as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The current browser orientation corresponding to a value defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + set_browser_orientation (a_session_id: STRING_32) + -- POST /session/:sessionId/orientation + -- Set the browser orientation. The orientation should be specified as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- orientation - {string} The new browser orientation as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + retrieve_alert_text (a_session_id: STRING_32) + -- GET /session/:sessionId/alert_text + -- Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {string} The text of the currently displayed alert. + -- Potential Errors: + -- NoAlertPresent - If there is no alert displayed. + do + end + + send_alert_text (a_session_id: STRING_32) + -- POST /session/:sessionId/alert_text + -- Sends keystrokes to a JavaScript prompt() dialog. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- text - {string} Keystrokes to send to the prompt() dialog. + -- Potential Errors: + -- NoAlertPresent - If there is no alert displayed. + do + end + + accept_alert (a_session_id: STRING_32) + -- POST /session/:sessionId/accept_alert + -- Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoAlertPresent - If there is no alert displayed. + do + end + + dismiss_alert (a_session_id: STRING_32) + -- POST /session/:sessionId/dismiss_alert + -- Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. For alert() dialogs, this is equivalent to clicking the 'OK' button. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoAlertPresent - If there is no alert displayed. + do + end + + move_to (a_session_id: STRING_32) + -- POST /session/:sessionId/moveto + -- Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse. + -- xoffset - {number} X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + -- yoffset - {number} Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + do + end + + click (a_session_id: STRING_32) + -- POST /session/:sessionId/click + -- Click any mouse button (at the coordinates set by the last moveto command). Note that calling this command after calling buttondown and before calling button up (or any out-of-order interactions sequence) will yield undefined behaviour). + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + do + end + + button_down (a_session_id: STRING_32) + -- POST /session/:sessionId/buttondown + -- Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + do + end + + button_up (a_session_id: STRING_32) + -- POST /session/:sessionId/buttonup + -- Releases the mouse button previously held (where the mouse is currently at). Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + do + end + + double_click (a_session_id: STRING_32) + -- POST /session/:sessionId/doubleclick + -- Double-clicks at the current mouse coordinates (set by moveto). + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + do + end + + touch_click (a_session_id: STRING_32) + -- POST /session/:sessionId/touch/click + -- Single tap on the touch enabled device. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} ID of the element to single tap on. + do + end + + touch_down (a_session_id: STRING_32) + -- POST /session/:sessionId/touch/down + -- Finger down on the screen. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- x - {number} X coordinate on the screen. + -- y - {number} Y coordinate on the screen. + do + end + + touch_up (a_session_id: STRING_32) + -- POST /session/:sessionId/touch/up + -- Finger up on the screen. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- x - {number} X coordinate on the screen. + -- y - {number} Y coordinate on the screen. + do + end + + touch_move (a_session_id: STRING_32) + -- POST session/:sessionId/touch/move + -- Finger move on the screen. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- x - {number} X coordinate on the screen. + -- y - {number} Y coordinate on the screen. + do + end + + start_touch_scroll (a_session_id: STRING_32) + -- POST session/:sessionId/touch/scroll + -- Scroll on the touch screen using finger based motion events. Use this command to start scrolling at a particular screen location. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} ID of the element where the scroll starts. + -- xoffset - {number} The x offset in pixels to scroll by. + -- yoffset - {number} The y offset in pixels to scroll by. + do + end + + touch_scroll (a_session: STRING_32) + -- POST session/:sessionId/touch/scroll + -- Scroll on the touch screen using finger based motion events. Use this command if you don't care where the scroll starts on the screen. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- xoffset - {number} The x offset in pixels to scrollby. + -- yoffset - {number} The y offset in pixels to scrollby. + do + end + + touch_double_click (a_session_id: STRING_32) + -- POST session/:sessionId/touch/doubleclick + -- Double tap on the touch screen using finger motion events. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} ID of the element to double tap on. + do + end + + touch_long_click (a_session_id: STRING_32) + -- POST session/:sessionId/touch/longclick + -- Long press on the touch screen using finger motion events. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} ID of the element to long press on. + do + end + + start_touch_flick (a_session_id: STRING_32) + -- POST session/:sessionId/touch/flick + -- Flick on the touch screen using finger motion events. This flickcommand starts at a particulat screen location. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- element - {string} ID of the element where the flick starts. + -- xoffset - {number} The x offset in pixels to flick by. + -- yoffset - {number} The y offset in pixels to flick by. + -- speed - {number} The speed in pixels per seconds. + do + end + + touch_flick (a_session_id: STRING_32) + -- POST session/:sessionId/touch/flick + -- Flick on the touch screen using finger motion events. Use this flick command if you don't care where the flick starts on the screen. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- xSpeed - {number} The x speed in pixels per second. + -- ySpeed - {number} The y speed in pixels per second. + do + end + + retrieve_geo_location (a_session_id: STRING_32) + -- GET /session/:sessionId/location + -- Get the current geo location. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {latitude: number, longitude: number, altitude: number} The current geo location. + do + end + + set_geo_location (a_session_id: STRING_32) + -- POST /session/:sessionId/location + -- Set the current geo location. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- location - {latitude: number, longitude: number, altitude: number} The new location. + do + end + + retrieve_local_storage (a_session_id: STRING_32) + -- GET /session/:sessionId/local_storage + -- Get all keys of the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} The list of keys. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + set_location_storage (a_session_id: STRING_32) + -- POST /session/:sessionId/local_storage + -- Set the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- key - {string} The key to set. + -- value - {string} The value to set. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + delete_local_storage (a_session_id: STRING_32) + -- DELETE /session/:sessionId/local_storage + -- Clear the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + retrieve_storage_by_key (a_session_id: STRING_32; a_key: STRING_32) + -- GET /session/:sessionId/local_storage/key/:key + -- Get the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :key - The key to get. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + delete_storage_by_key (a_session_id: STRING_32; a_key: STRING_32) + -- DELETE /session/:sessionId/local_storage/key/:key + -- Remove the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :key - The key to remove. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + local_storage_size (a_session_id: STRING_32) + -- GET /session/:sessionId/local_storage/size + -- Get the number of items in the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {number} The number of items in the storage. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + session_storage_keys (a_session_id: STRING_32) + -- GET /session/:sessionId/session_storage + -- Get all keys of the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} The list of keys. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + set_session_storage (a_session_id: STRING_32) + -- POST /session/:sessionId/session_storage + -- Set the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- key - {string} The key to set. + -- value - {string} The value to set. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + delete_session_storage (a_session_id: STRING_32) + -- DELETE /session/:sessionId/session_storage + -- Clear the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + retrive_storage_item_by_key (a_session_id: STRING_32; a_key: STRING_32) + -- GET /session/:sessionId/session_storage/key/:key + -- Get the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :key - The key to get. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + remove_storage_item_by_key (a_session_id: STRING_32; a_key: STRING_32) + -- DELETE /session/:sessionId/session_storage/key/:key + -- Remove the storage item for the given key. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- :key - The key to remove. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + session_storage_size (a_session_id: STRING_32) + -- GET /session/:sessionId/session_storage/size + -- Get the number of items in the storage. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {number} The number of items in the storage. + -- Potential Errors: + -- NoSuchWindow - If the currently selected window has been closed. + do + end + + log (a_session_id: STRING_32) + -- POST /session/:sessionId/log + -- Get the log for a given log type. Log buffer is reset after each request. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- JSON Parameters: + -- type - {string} The log type. This must be provided. + -- Returns: + -- {Array.} The list of log entries. + do + end + + available_log_types (a_session_id: STRING_32) + -- GET /session/:sessionId/log/types + -- Get available log types. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {Array.} The list of available log types. + do + end + + application_cache_status (a_session_id: STRING_32) + -- GET /session/:sessionId/application_cache/status + -- Get the status of the html5 application cache. + -- URL Parameters: + -- :sessionId - ID of the session to route the command to. + -- Returns: + -- {number} Status code for application cache: {UNCACHED = 0, IDLE = 1, CHECKING = 2, DOWNLOADING = 3, UPDATE_READY = 4, OBSOLETE = 5} + do + end + +feature -- Error Handling + + check_response (a_response: SE_RESPONSE) + -- Check the answer given from the selenium server. If the response status shows an error + -- set has_error in True and let the description of the error in last_error + -- in other case set has_error in False and last_error in Void + do + if a_response.status /= 0 then + -- there was an error + has_error := true + last_error := error_handling (a_response.status) + else + has_error := false + last_error := Void + end end feature {NONE} -- Implementation + initialize_executor do - create commnad_executor.make ( host ) + create commnad_executor.make (host) end host: STRING_32 @@ -149,14 +1600,79 @@ feature {NONE} -- Implementation } ]" - commnad_executor : COMMAND_EXECUTOR + commnad_executor: COMMAND_EXECUTOR - build_session (value : STRING_32): detachable SE_SESSION + build_session (value: STRING_32; to: STRING_32): detachable SE_SESSION do - if attached {JSON_OBJECT} string_to_json (value) as l_value then - if attached l_value.item ("sessionId") as ls and then attached l_value.item ("value") as lv and then attached json_to_se_capabilities (lv.representation) as lc then - create Result.make (ls.representation, lc) + if to.is_case_insensitive_equal ("session") then + if attached {JSON_OBJECT} string_to_json (value) as l_value then + if attached l_value.item ("sessionId") as ls and then attached l_value.item ("value") as lv and then attached json_to_se_capabilities (lv.representation) as lc then + create Result.make (ls.representation, lc) + end + end + elseif to.is_case_insensitive_equal ("sessions") then + if attached {JSON_OBJECT} string_to_json (value) as l_value then + if attached l_value.item ("id") as ls and then attached l_value.item ("capabilities") as lv and then attached json_to_se_capabilities (lv.representation) as lc then + create Result.make (ls.representation, lc) + end end end end + + error_handling (a_code: INTEGER_32): SE_ERROR + -- Inspect the code `a_code' and return the error + do + create Result.make (-1, "ErrorNotFound", "A9n unknown API error") + inspect a_code + when 6 then + create Result.make (6, "NoSuchDriver", "A session is either terminated or not started") + when 7 then + create Result.make (7, "NoSuchDriver", "An element could not be located on the page using the given search parameters.") + when 8 then + create Result.make (8, "NoSuchDriver", "A request to switch to a frame could not be satisfied because the frame could not be found.") + when 9 then + create Result.make (9, "UnknownCommand", "The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.") + when 10 then + create Result.make (10, "StaleElementReference", "An element command failed because the referenced element is no longer attached to the DOM.") + when 11 then + create Result.make (11, "ElementNotVisible", "An element command could not be completed because the element is not visible on the page.") + when 12 then + create Result.make (12, "InvalidElementState", "An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).") + when 13 then + create Result.make (13, "UnknownError", "An unknown server-side error occurred while processing the command.") + when 15 then + create Result.make (15, "ElementIsNotSelectable", "An attempt was made to select an element that cannot be selected.") + when 17 then + create Result.make (17, "JavaScriptError", "An error occurred while executing user supplied JavaScript.") + when 19 then + create Result.make (19, "XPathLookupError", "An error occurred while searching for an element by XPath.") + when 21 then + create Result.make (21, "Timeout", "An operation did not complete before its timeout expired.") + when 23 then + create Result.make (23, "NoSuchWindow", "A request to switch to a different window could not be satisfied because the window could not be found.") + when 24 then + create Result.make (24, "InvalidCookieDomain", "An illegal attempt was made to set a cookie under a different domain than the current page.") + when 25 then + create Result.make (25, "UnableToSetCookie", "A request to set a cookie's value could not be satisfied.") + when 26 then + create Result.make (26, "InvalidCookieDomain", "A modal dialog was open, blocking this operation") + when 27 then + create Result.make (27, "UnableToSetCookie", "An attempt was made to operate on a modal dialog when one was not open.") + when 28 then + create Result.make (28, "ScriptTimeout", "A script did not complete before its timeout expired.") + when 29 then + create Result.make (29, "InvalidElementCoordinates", "The coordinates provided to an interactions operation are invalid.") + when 30 then + create Result.make (30, "IMENotAvailable", "IME was not available.") + when 31 then + create Result.make (31, "IMEEngineActivationFailed", "An IME engine could not be started.") + when 32 then + create Result.make (32, "InvalidSelector", "Argument was an invalid selector (e.g. XPath/CSS).") + when 33 then + create Result.make (33, "SessionNotCreatedException", "A new session could not be created.") + when 34 then + create Result.make (34, "MoveTargetOutOfBounds", "Target provided for a move action is out of bounds.") + end + end + end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 243fc733..98f7651d 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -19,25 +19,148 @@ feature --POST /session Create a new session. cmd_sessions : STRING = "sessions" --GET /sessions Returns a list of the currently active sessions. ---GET /session/:sessionId Retrieve the capabilities of the specified session. ---DELETE /session/:sessionId Delete the session. ---POST /session/:sessionId/timeouts Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. ---POST /session/:sessionId/timeouts/async_script Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. ---POST /session/:sessionId/timeouts/implicit_wait Set the amount of time the driver should wait when searching for elements. ---GET /session/:sessionId/window_handle Retrieve the current window handle. ---GET /session/:sessionId/window_handles Retrieve the list of all window handles available to the session. ---GET /session/:sessionId/url Retrieve the URL of the current page. ---POST /session/:sessionId/url Navigate to a new URL. ---POST /session/:sessionId/forward Navigate forwards in the browser history, if possible. ---POST /session/:sessionId/back Navigate backwards in the browser history, if possible. ---POST /session/:sessionId/refresh Refresh the current page. + + cmd_session_by_id_tmpl : STRING ="session/$id" + + cmd_session_by_id (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_by_id_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_timeouts_tmpl : STRING ="session/$id/timeouts" + + cmd_session_timeouts (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_timeouts_async_script_tmpl : STRING ="session/$id/timeouts/async_script" + + cmd_session_timeouts_async_script (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_async_script_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_timeouts_implicit_wait_tmpl : STRING ="/session/$id/timeouts/implicit_wait" + + cmd_session_timeouts_implicit_wait (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_implicit_wait_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_window_handle_tmpl : STRING ="/session/$id/window_handle" + + cmd_session_window_handle (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_handle_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_window_handles_tmpl : STRING ="/session/$id/window_handles" + + cmd_session_window_handles (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_handles_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_url_tmpl : STRING ="/session/$id/url" + + cmd_session_url (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_url_tmpl) + Result.replace_substring_all ("$id", id) + end + + + + cmd_session_forward_tmpl : STRING ="/session/$id/forward" + + cmd_session_forward (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_forward_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_back_tmpl : STRING ="/session/$id/back" + + cmd_session_back (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_back_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_refresh_tmpl : STRING ="/session/$id/refresh" + + cmd_session_refresh (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_refresh_tmpl) + Result.replace_substring_all ("$id", id) + end + + --POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. --POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. ---GET /session/:sessionId/screenshot Take a screenshot of the current page. ---GET /session/:sessionId/ime/available_engines List all available engines on the machine. ---GET /session/:sessionId/ime/active_engine Get the name of the active IME engine. ---GET /session/:sessionId/ime/activated Indicates whether IME input is active at the moment (not if it's available. ---POST /session/:sessionId/ime/deactivate De-activates the currently-active IME engine. + + + cmd_session_screenshot_tmpl : STRING ="/session/$id/screenshot" + + cmd_session_screenshot (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_screenshot_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_ime_available_engines_tmpl : STRING ="/session/$id/ime/available_engines" + + cmd_session_ime_available (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_available_engines_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_active_engine_tmpl : STRING ="/session/$id/ime/active_engine" + + cmd_session_ime_active_engine (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_active_engine_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_activated_tmpl : STRING ="/session/$id/ime/activated" + + cmd_session_ime_activated (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_activated_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_deactivate_tmpl : STRING ="/session/$id/ime/deactivate" + + cmd_session_ime_deactivate (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_deactivate_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_activate_tmpl : STRING ="/session/$id/ime/activate" + + cmd_session_ime_activate (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_activate_tmpl) + Result.replace_substring_all ("$id", id) + end + + + --POST /session/:sessionId/ime/activate Make an engines that is available (appears on the listreturned by getAvailableEngines) active. --POST /session/:sessionId/frame Change focus to another frame on the page. --POST /session/:sessionId/window Change focus to another window. diff --git a/library/test/selenium/src/response/se_status.e b/library/test/selenium/src/response/se_status.e index ecc8b060..bbc002bf 100644 --- a/library/test/selenium/src/response/se_status.e +++ b/library/test/selenium/src/response/se_status.e @@ -14,7 +14,7 @@ inherit end feature -- Access - status: detachable STRING_32 + status: INTEGER_32 session_id: detachable STRING_32 state: detachable STRING_32 class_name: detachable STRING_32 @@ -22,7 +22,7 @@ feature -- Access hash_code: detachable STRING_32 feature -- Change Element - set_status (a_status : STRING_32) + set_status (a_status : INTEGER_32) do status := a_status end @@ -55,12 +55,11 @@ feature -- Change Element out : STRING do create Result.make_from_string ("Response : ") - if attached status as l_satus then - Result.append ("[Status:") - Result.append (l_satus.out) - Result.append ("]") - Result.append (" ") - end + Result.append ("[Status:") + Result.append (status.out) + Result.append ("]") + Result.append (" ") + if attached session_id as l_session_id then Result.append ("[SessionId:") Result.append (l_session_id.out) diff --git a/library/test/selenium/src/se_error.e b/library/test/selenium/src/se_error.e index 42236c89..dbae5da5 100644 --- a/library/test/selenium/src/se_error.e +++ b/library/test/selenium/src/se_error.e @@ -21,4 +21,13 @@ feature -- Access code : INTEGER_32 summary : STRING_32 detail : STRING_32 + +feature -- Report + full_message : STRING_32 + -- Full error description + do + create Result.make_empty + Result.append ("code : " + code.out + " - summary:" + summary + " - detail:" + detail) + end + end diff --git a/library/test/selenium/src/se_timeout_type.e b/library/test/selenium/src/se_timeout_type.e new file mode 100644 index 00000000..e5f8b089 --- /dev/null +++ b/library/test/selenium/src/se_timeout_type.e @@ -0,0 +1,45 @@ +note + description: "Summary description for {SE_TIMEOUT_TYPE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_TIMEOUT_TYPE + +create + make, + make_empty + +feature -- Initialization + make (a_type : STRING_32; a_ms : INTEGER_32) + do + set_type (a_type) + set_ms (a_ms) + end + + make_empty + do + + end + +feature -- Access + type : detachable STRING_32 + -- The type of operation to set the timeout for. + -- Valid values are: "script" for script timeouts, + -- "implicit" for modifying the implicit wait timeout and + -- "page load" for setting a page load timeout. + ms : INTEGER_32 + -- The amount of time, in milliseconds, that time-limited commands are permitted to run. + +feature -- Change Element + set_type (a_type : STRING_32) + do + type := a_type + end + + set_ms (a_ms : INTEGER_32) + do + ms := a_ms + end +end diff --git a/library/test/selenium/src/web_element.e b/library/test/selenium/src/web_element.e index 7147d82e..91abe6c8 100644 --- a/library/test/selenium/src/web_element.e +++ b/library/test/selenium/src/web_element.e @@ -6,5 +6,21 @@ note class WEB_ELEMENT +create + make +feature + make + do + end +feature -- Access + element : detachable STRING_32 + --The opaque ID assigned to the element by the server. + --This ID should be used in all subsequent commands issued against the element. + +feature -- Change Element + set_element (an_element : STRING) + do + element := an_element + end end diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e index a27397ae..0ca08638 100644 --- a/library/test/selenium/test/application.e +++ b/library/test/selenium/test/application.e @@ -24,13 +24,16 @@ feature {NONE} -- Initialization if attached web_driver.status as l_status then print (l_status) - -- retrieve sessions - if attached web_driver.sessions as l_session then - across l_session as item loop - print (item) - end + + + -- create a new session + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then + print ("%NSessionId:" + l_session.session_id) end + -- create a new session create capabilities.make capabilities.set_browser_name ("chrome") @@ -41,8 +44,8 @@ feature {NONE} -- Initialization -- retrieve sessions if attached web_driver.sessions as l_session then - across l_session as item loop - print (item) + across l_session as l_item loop + print (l_item) end end diff --git a/library/test/selenium/test/exception_trace.log b/library/test/selenium/test/exception_trace.log new file mode 100644 index 00000000..c12662e1 --- /dev/null +++ b/library/test/selenium/test/exception_trace.log @@ -0,0 +1,28 @@ + +test: system execution failed. +Following is the set of recorded exceptions: + +------------------------------------------------------------------------------- +Class / Object Routine Nature of exception Effect +------------------------------------------------------------------------------- +JSON_PARSER make_parser @1 json_not_empty: +<00000000029AAD48> Precondition violated. Fail +------------------------------------------------------------------------------- +SE_JSON_WIRE_PROTOCOL + string_to_json @2 +<00000000029705E8> (From JSON_HELPER) Routine failure. Fail +------------------------------------------------------------------------------- +SE_JSON_WIRE_PROTOCOL + build_session @1 +<00000000029705E8> Routine failure. Fail +------------------------------------------------------------------------------- +SE_JSON_WIRE_PROTOCOL + create_session_with_desired_capabilities @5 +<00000000029705E8> Routine failure. Fail +------------------------------------------------------------------------------- +APPLICATION make @6 +<00000000029705A8> Routine failure. Fail +------------------------------------------------------------------------------- +APPLICATION root's creation +<00000000029705A8> Routine failure. Exit +------------------------------------------------------------------------------- From ce2ca051f6ab4de2c93698be55569eac8d18871f Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 16 Apr 2013 17:31:33 -0300 Subject: [PATCH 05/36] Fixed feature typo, improved commands, added AutoTest --- library/test/selenium/selenium-safe.ecf | 1 + library/test/selenium/src/command_executor.e | 59 +++++---- .../converter/se_response_json_converter.e | 2 +- .../test/selenium/src/helpers/json_helper.e | 13 ++ .../src/protocol/se_json_wire_protocol.e | 18 ++- .../protocol/se_json_wire_protocol_commands.e | 10 +- library/test/selenium/test/application.e | 3 + library/test/selenium/test/test-safe.ecf | 1 + .../selenium/test/test_json_wire_protocol.e | 125 ++++++++++++++++++ 9 files changed, 194 insertions(+), 38 deletions(-) create mode 100644 library/test/selenium/test/test_json_wire_protocol.e diff --git a/library/test/selenium/selenium-safe.ecf b/library/test/selenium/selenium-safe.ecf index a9335f48..19b00f12 100644 --- a/library/test/selenium/selenium-safe.ecf +++ b/library/test/selenium/selenium-safe.ecf @@ -6,6 +6,7 @@ + diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index 22f0081e..7d8e606b 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -52,7 +52,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_status) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -64,10 +64,16 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_new_session, capabilities) - if attached resp.header ("Location") as l_location then - resp := http_new_session (l_location).get ("", context_executor) + if not (resp.status >= 400) then + if attached resp.header ("Location") as l_location then + resp := http_new_session (l_location).get ("", context_executor) + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -81,7 +87,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_sessions) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -94,7 +100,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_by_id (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -105,13 +111,13 @@ feature -- Commands resp: HTTP_CLIENT_RESPONSE do create Result.make_empty - resp := execute_delete (cmd_session_by_id (cmd_session_by_id (session_id))) + resp := execute_delete (cmd_session_by_id ( session_id )) if resp.status = 204 then Result.set_status (0) Result.set_session_id (session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -129,7 +135,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -147,7 +153,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -166,7 +172,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -181,7 +187,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_window_handle (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -194,7 +200,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_window_handles (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -207,7 +213,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_url (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -224,7 +230,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -242,7 +248,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -260,7 +266,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -278,7 +284,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -310,7 +316,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_screenshot (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -323,7 +329,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_ime_available (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -336,7 +342,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_ime_active_engine (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -349,7 +355,7 @@ feature -- Commands create Result.make_empty resp := execute_get (cmd_session_ime_activated (session_id)) if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -366,7 +372,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end end @@ -384,7 +390,7 @@ feature -- Commands Result.set_session_id (a_session_id) else if attached resp.body as l_body then - Result := build_response (l_body) + Result := new_response (l_body) end end @@ -407,11 +413,10 @@ feature {NONE} -- Implementation Result := http_session.delete (command_name, context_executor) end - build_response (a_message: STRING_32): SE_RESPONSE + new_response (a_message: STRING_32): SE_RESPONSE do create Result.make_empty - initialize_converters (json) - if attached {SE_RESPONSE} json.object_from_json (a_message, "SE_RESPONSE") as l_response then + if attached json_to_se_response(a_message) as l_response then Result := l_response end Result.set_json_response (a_message) diff --git a/library/test/selenium/src/converter/se_response_json_converter.e b/library/test/selenium/src/converter/se_response_json_converter.e index 4e28414f..17784320 100644 --- a/library/test/selenium/src/converter/se_response_json_converter.e +++ b/library/test/selenium/src/converter/se_response_json_converter.e @@ -31,7 +31,7 @@ feature -- Conversion if attached {STRING_32} json_to_object (j.item (session_key), Void) as l_item then Result.set_session_id(l_item) end - if attached {INTEGER_32} json_to_object (j.item (status_key), Void) as l_item then + if attached {INTEGER_8} json_to_object (j.item (status_key), Void) as l_item then Result.set_status(l_item) end if attached {JSON_VALUE} j.item (value_key) as l_item then diff --git a/library/test/selenium/src/helpers/json_helper.e b/library/test/selenium/src/helpers/json_helper.e index 90dd1c4f..5d5cdd59 100644 --- a/library/test/selenium/src/helpers/json_helper.e +++ b/library/test/selenium/src/helpers/json_helper.e @@ -58,6 +58,19 @@ feature -- Access end end + json_to_se_response (post: STRING_32): detachable SE_RESPONSE + local + parser: JSON_PARSER + do + initialize_converters (json) + create parser.make_parser (post) + if attached parser.parse_object as st and parser.is_parsed then + if attached {SE_RESPONSE} json.object (st, "SE_RESPONSE") as l_response then + Result := l_response + end + end + end + initialize_converters (j: like json) -- Initialize json converters do diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index 3e960b2b..b4aee5d7 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -96,7 +96,7 @@ feature -- Commands check_response (response) if not has_error then if attached response.json_response as r_value then - Result := build_session (r_value, "session") + Result := new_session (r_value, "session") end end end @@ -127,7 +127,7 @@ feature -- Commands index > l_json_array.count loop if attached {JSON_OBJECT} l_json_array.i_th (index) as json_obj then - if attached build_session (json_obj.representation, "sessions") as l_session then + if attached new_session (json_obj.representation, "sessions") as l_session then Result.force (l_session) end end @@ -153,7 +153,7 @@ feature -- Commands check_response (response) if not has_error then if attached response.json_response as r_value then - Result := build_session (r_value, "session") + Result := new_session (r_value, "session") end end end @@ -1602,18 +1602,24 @@ feature {NONE} -- Implementation commnad_executor: COMMAND_EXECUTOR - build_session (value: STRING_32; to: STRING_32): detachable SE_SESSION + new_session (value: STRING_32; to: STRING_32): detachable SE_SESSION + local + l_rep : STRING_32 do if to.is_case_insensitive_equal ("session") then if attached {JSON_OBJECT} string_to_json (value) as l_value then if attached l_value.item ("sessionId") as ls and then attached l_value.item ("value") as lv and then attached json_to_se_capabilities (lv.representation) as lc then - create Result.make (ls.representation, lc) + l_rep := ls.representation + l_rep.replace_substring_all ("%"", "") + create Result.make (l_rep, lc) end end elseif to.is_case_insensitive_equal ("sessions") then if attached {JSON_OBJECT} string_to_json (value) as l_value then if attached l_value.item ("id") as ls and then attached l_value.item ("capabilities") as lv and then attached json_to_se_capabilities (lv.representation) as lc then - create Result.make (ls.representation, lc) + l_rep := ls.representation + l_rep.replace_substring_all ("%"", "") + create Result.make (l_rep, lc) end end end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 98f7651d..0b5c92f7 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -7,8 +7,8 @@ note class SE_JSON_WIRE_PROTOCOL_COMMANDS - feature + cmd_ping : STRING = "" --GET / expected a 200 ok @@ -29,12 +29,14 @@ feature end - cmd_session_timeouts_tmpl : STRING ="session/$id/timeouts" + cmd_session_timeouts_tmpl : STRING_32 ="[ + session/$id/timeouts + ]" - cmd_session_timeouts (id: STRING_32): STRING_32 + cmd_session_timeouts (id: STRING_32):STRING_32 do create Result.make_from_string (cmd_session_timeouts_tmpl) - Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$id",id) end cmd_session_timeouts_async_script_tmpl : STRING ="session/$id/timeouts/async_script" diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e index 0ca08638..d9ad3933 100644 --- a/library/test/selenium/test/application.e +++ b/library/test/selenium/test/application.e @@ -18,6 +18,7 @@ feature {NONE} -- Initialization local web_driver: SE_JSON_WIRE_PROTOCOL capabilities : SE_CAPABILITIES + timeout : SE_TIMEOUT_TYPE do -- check if the selenium Remote WebDriver is up and running. create web_driver.make @@ -39,6 +40,8 @@ feature {NONE} -- Initialization capabilities.set_browser_name ("chrome") if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then print ("%NSessionId:" + l_session.session_id) + create timeout.make_empty + web_driver.set_session_timeouts (l_session.session_id, timeout) end diff --git a/library/test/selenium/test/test-safe.ecf b/library/test/selenium/test/test-safe.ecf index 8ca22e1f..22cd2c01 100644 --- a/library/test/selenium/test/test-safe.ecf +++ b/library/test/selenium/test/test-safe.ecf @@ -9,6 +9,7 @@ + /EIFGENs$ diff --git a/library/test/selenium/test/test_json_wire_protocol.e b/library/test/selenium/test/test_json_wire_protocol.e new file mode 100644 index 00000000..da92ce0a --- /dev/null +++ b/library/test/selenium/test/test_json_wire_protocol.e @@ -0,0 +1,125 @@ +note + description: "[ + Eiffel tests that can be executed by testing tool. + ]" + author: "EiffelStudio test wizard" + date: "$Date$" + revision: "$Revision$" + testing: "type/manual" + +class + TEST_JSON_WIRE_PROTOCOL + +inherit + + EQA_TEST_SET + redefine + on_prepare, + on_clean + end + +feature {NONE} -- Events + + on_prepare + local + capabilities: SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + session_id := l_session.session_id + end + end + + on_clean + -- + do + if attached session_id as l_session_id then + wire_protocol.delete_session (session_id) + end + end + +feature -- Test routines + + test_status + -- + do + if attached {SE_STATUS} wire_protocol.status as l_status then + assert ("No error", not wire_protocol.has_error) + assert ("Expected status 0", l_status.status = 0) + assert ("Expected sessionId", l_status.session_id = Void) + end + end + + test_seleniun_server_host_not_available + -- + local + l_wire_protocol: SE_JSON_WIRE_PROTOCOL + do + create l_wire_protocol.make_with_host ("http://127.0.0.1:4443/wd/hub/status") + assert ("expected void", l_wire_protocol.status = Void) + end + + test_create_valid_new_session + local + capabilities: SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + end + end + + test_create_invalid_new_session + local + capabilities: SE_CAPABILITIES + session: detachable SE_SESSION + do + create capabilities.make + capabilities.set_browser_name ("invalid") + session := wire_protocol.create_session_with_desired_capabilities (capabilities) + assert ("Expected error", wire_protocol.has_error) + assert ("Expected void", session = Void) + end + + test_retrieve_sessions + local + sessions: detachable LIST [SE_SESSION] + do + sessions := wire_protocol.sessions + assert ("Not void", sessions /= Void) + assert ("One or more items:", sessions.count >= 1) + end + + + test_delete_session + local + capabilities: SE_CAPABILITIES + session : detachable SE_SESSION + pre_session, post_session : INTEGER + do +-- if attached wire_protocol.sessions as l_sessions then +-- pre_session := l_sessions.count +-- end + +-- if attached session_id as l_session_id then +-- wire_protocol.delete_session (session_id) +-- end + +-- if attached wire_protocol.sessions as l_sessions then +-- post_session := l_sessions.count +-- end + +-- assert ("After delete Pre sesssion - 1 is equal to post_session", (pre_session - 1) = post_session) + end + +feature {NONE}-- Implementation + wire_protocol: SE_JSON_WIRE_PROTOCOL + once + create Result.make + end + + session_id: detachable STRING_32 + +end From c344ecceecc78ddd1e565e1ca02e9f2452677f16 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 17 Apr 2013 10:06:34 -0300 Subject: [PATCH 06/36] Fixed errors in navigate_to_url command, Fixed url templates in json_wire_protocol_command. Added test cases to AutoTest --- .../src/protocol/se_json_wire_protocol.e | 2 +- .../protocol/se_json_wire_protocol_commands.e | 26 +-- library/test/selenium/src/se_timeout_type.e | 3 +- library/test/selenium/test/application.e | 133 ++++++++++----- .../selenium/test/test_json_wire_protocol.e | 160 ++++++++++++++++++ 5 files changed, 265 insertions(+), 59 deletions(-) diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index b4aee5d7..a72fa163 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -328,7 +328,7 @@ feature -- Commands resp: SE_RESPONSE do l_json := "[ - { "url": $url } + { "url": "$url" } ]" l_json.replace_substring_all ("$url", an_url) if commnad_executor.is_available then diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 0b5c92f7..c8b25e8d 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -47,7 +47,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_timeouts_implicit_wait_tmpl : STRING ="/session/$id/timeouts/implicit_wait" + cmd_session_timeouts_implicit_wait_tmpl : STRING ="session/$id/timeouts/implicit_wait" cmd_session_timeouts_implicit_wait (id: STRING_32): STRING_32 do @@ -56,7 +56,7 @@ feature end - cmd_session_window_handle_tmpl : STRING ="/session/$id/window_handle" + cmd_session_window_handle_tmpl : STRING ="session/$id/window_handle" cmd_session_window_handle (id: STRING_32): STRING_32 do @@ -64,7 +64,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_window_handles_tmpl : STRING ="/session/$id/window_handles" + cmd_session_window_handles_tmpl : STRING ="session/$id/window_handles" cmd_session_window_handles (id: STRING_32): STRING_32 do @@ -72,7 +72,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_url_tmpl : STRING ="/session/$id/url" + cmd_session_url_tmpl : STRING ="session/$id/url" cmd_session_url (id: STRING_32): STRING_32 do @@ -82,7 +82,7 @@ feature - cmd_session_forward_tmpl : STRING ="/session/$id/forward" + cmd_session_forward_tmpl : STRING ="session/$id/forward" cmd_session_forward (id: STRING_32): STRING_32 do @@ -90,7 +90,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_back_tmpl : STRING ="/session/$id/back" + cmd_session_back_tmpl : STRING ="session/$id/back" cmd_session_back (id: STRING_32): STRING_32 do @@ -99,7 +99,7 @@ feature end - cmd_session_refresh_tmpl : STRING ="/session/$id/refresh" + cmd_session_refresh_tmpl : STRING ="session/$id/refresh" cmd_session_refresh (id: STRING_32): STRING_32 do @@ -112,7 +112,7 @@ feature --POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. - cmd_session_screenshot_tmpl : STRING ="/session/$id/screenshot" + cmd_session_screenshot_tmpl : STRING ="session/$id/screenshot" cmd_session_screenshot (id: STRING_32): STRING_32 do @@ -121,7 +121,7 @@ feature end - cmd_session_ime_available_engines_tmpl : STRING ="/session/$id/ime/available_engines" + cmd_session_ime_available_engines_tmpl : STRING ="session/$id/ime/available_engines" cmd_session_ime_available (id: STRING_32): STRING_32 do @@ -129,7 +129,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_ime_active_engine_tmpl : STRING ="/session/$id/ime/active_engine" + cmd_session_ime_active_engine_tmpl : STRING ="session/$id/ime/active_engine" cmd_session_ime_active_engine (id: STRING_32): STRING_32 do @@ -137,7 +137,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_ime_activated_tmpl : STRING ="/session/$id/ime/activated" + cmd_session_ime_activated_tmpl : STRING ="session/$id/ime/activated" cmd_session_ime_activated (id: STRING_32): STRING_32 do @@ -145,7 +145,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_ime_deactivate_tmpl : STRING ="/session/$id/ime/deactivate" + cmd_session_ime_deactivate_tmpl : STRING ="session/$id/ime/deactivate" cmd_session_ime_deactivate (id: STRING_32): STRING_32 do @@ -153,7 +153,7 @@ feature Result.replace_substring_all ("$id", id) end - cmd_session_ime_activate_tmpl : STRING ="/session/$id/ime/activate" + cmd_session_ime_activate_tmpl : STRING ="session/$id/ime/activate" cmd_session_ime_activate (id: STRING_32): STRING_32 do diff --git a/library/test/selenium/src/se_timeout_type.e b/library/test/selenium/src/se_timeout_type.e index e5f8b089..82deb5d0 100644 --- a/library/test/selenium/src/se_timeout_type.e +++ b/library/test/selenium/src/se_timeout_type.e @@ -7,6 +7,7 @@ note class SE_TIMEOUT_TYPE +-- TODO add contracts to validate the timeout types. create make, make_empty @@ -22,7 +23,7 @@ feature -- Initialization do end - + feature -- Access type : detachable STRING_32 -- The type of operation to set the timeout for. diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e index d9ad3933..c822c072 100644 --- a/library/test/selenium/test/application.e +++ b/library/test/selenium/test/application.e @@ -1,14 +1,17 @@ note - description : "test application root class" - date : "$Date$" - revision : "$Revision$" + description: "test application root class" + date: "$Date$" + revision: "$Revision$" class APPLICATION inherit + ARGUMENTS + +-- TODO start and stop selenium server from Eiffel. create make @@ -17,72 +20,114 @@ feature {NONE} -- Initialization make local web_driver: SE_JSON_WIRE_PROTOCOL - capabilities : SE_CAPABILITIES - timeout : SE_TIMEOUT_TYPE + capabilities: SE_CAPABILITIES + timeout: SE_TIMEOUT_TYPE do - -- check if the selenium Remote WebDriver is up and running. + -- check if the selenium Remote WebDriver is up and running. create web_driver.make - if attached web_driver.status as l_status then + if attached web_driver.status as l_status then print (l_status) - -- create a new session + -- create a new session create capabilities.make capabilities.set_browser_name ("chrome") if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then print ("%NSessionId:" + l_session.session_id) + web_driver.navigate_to_url (l_session.session_id, "http://www.google.com/") + check + Has_no_error: not web_driver.has_error + end + web_driver.navigate_to_url (l_session.session_id, "http://www.infoq.com/") + check + Has_no_error: not web_driver.has_error + end + web_driver.navigate_to_url (l_session.session_id, "http://www.yahoo.com/") + check + Has_no_error: not web_driver.has_error + end + + --back + web_driver.back (l_session.session_id) + check + Has_no_error: not web_driver.has_error + end + if attached web_driver.retrieve_url (l_session.session_id) as l_back_url then + check + Has_no_error: not web_driver.has_error + end + check + expected_infoq: "http://www.infoq.com/" ~ l_back_url.out + end + end + + -- forward + web_driver.forward (l_session.session_id) + check + Has_no_error: not web_driver.has_error + end + if attached web_driver.retrieve_url (l_session.session_id) as l_forward_url then + check + Has_no_error: not web_driver.has_error + end + check + expected_yahoo: "http://www.yahoo.com/" ~ l_forward_url.out + end + end + + -- refresh + web_driver.refresh (l_session.session_id) + check + Has_no_error: not web_driver.has_error + end end - - -- create a new session create capabilities.make capabilities.set_browser_name ("chrome") if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then print ("%NSessionId:" + l_session.session_id) - create timeout.make_empty + create timeout.make ("script", 1) web_driver.set_session_timeouts (l_session.session_id, timeout) end - - -- retrieve sessions - if attached web_driver.sessions as l_session then - across l_session as l_item loop - print (l_item) - end - end - +-- -- retrieve sessions +-- if attached web_driver.sessions as l_session then +-- across +-- l_session as l_item +-- loop +-- print (l_item) +-- end +-- end else print ("The selenium server is not accesible") end - end test_session local - h: LIBCURL_HTTP_CLIENT - session: HTTP_CLIENT_SESSION - resp : detachable HTTP_CLIENT_RESPONSE - l_location : detachable READABLE_STRING_8 - body : STRING - context : HTTP_CLIENT_REQUEST_CONTEXT - s: READABLE_STRING_8 - do - create h.make - s := "[ - { - "desiredCapabilities" : { - "browserName":"firefox" - } - } - ]" - - - session := h.new_session ("http://localhost:4444/wd/hub/") - create context.make - context.headers.put ("application/json;charset=UTF-8", "Content-Type") - context.headers.put ("application/json;charset=UTF-8", "Accept") - resp := session.post ("session", context,s) - print(resp) + h: LIBCURL_HTTP_CLIENT + session: HTTP_CLIENT_SESSION + resp: detachable HTTP_CLIENT_RESPONSE + l_location: detachable READABLE_STRING_8 + body: STRING + context: HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + s := "[ + { + "desiredCapabilities" : { + "browserName":"firefox" + } + } + ]" + session := h.new_session ("http://localhost:4444/wd/hub/") + create context.make + context.headers.put ("application/json;charset=UTF-8", "Content-Type") + context.headers.put ("application/json;charset=UTF-8", "Accept") + resp := session.post ("session", context, s) + print (resp) end + end diff --git a/library/test/selenium/test/test_json_wire_protocol.e b/library/test/selenium/test/test_json_wire_protocol.e index da92ce0a..8c1dbb1c 100644 --- a/library/test/selenium/test/test_json_wire_protocol.e +++ b/library/test/selenium/test/test_json_wire_protocol.e @@ -114,6 +114,166 @@ feature -- Test routines -- assert ("After delete Pre sesssion - 1 is equal to post_session", (pre_session - 1) = post_session) end + test_valid_session_timeouts + local + l_timeout :SE_TIMEOUT_TYPE + capabilities : SE_CAPABILITIES + do + create l_timeout.make ("script", 1) + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.set_session_timeouts (l_session.session_id, l_timeout) + assert ("Has no error", not wire_protocol.has_error) + end + end + + test_invalid_session_timeouts + local + l_timeout :SE_TIMEOUT_TYPE + capabilities : SE_CAPABILITIES + do + create l_timeout.make ("tes", 1) + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.set_session_timeouts (l_session.session_id, l_timeout) + assert ("Has error", wire_protocol.has_error) + end + + end + + test_valid_session_async_script_timeouts + local + capabilities : SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.set_session_timeouts_async_script (l_session.session_id, 1) + assert ("Has no error", not wire_protocol.has_error) + end + end + + + test_valid_session_implicit_wait_timeouts + local + capabilities : SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.set_session_timeouts_implicit_wait (l_session.session_id, 1) + assert ("Has no error", not wire_protocol.has_error) + end + end + + + test_retrieve_window_handle + local + capabilities : SE_CAPABILITIES + window_handle : detachable STRING_32 + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + window_handle := wire_protocol.retrieve_window_handle (l_session.session_id) + assert ("Has no error", not wire_protocol.has_error) + assert ("Windows handle not void", attached window_handle = True) + end + end + + + test_retrieve_window_handles + local + capabilities : SE_CAPABILITIES + window_handles : detachable LIST[STRING_32] + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + window_handles := wire_protocol.retrieve_window_handles (l_session.session_id) + assert ("Has no error", not wire_protocol.has_error) + assert ("Windows handleS not void", attached window_handles = True) + end + end + + test_retrieve_url + local + capabilities : SE_CAPABILITIES + url : detachable STRING_32 + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + url := wire_protocol.retrieve_url (session_id) + assert ("Has no error", not wire_protocol.has_error) + assert ("url not void", attached url = True) + end + end + + test_navigate_to_url + local + capabilities : SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.navigate_to_url (session_id,"http://www.google.com/") + assert ("Has no error", not wire_protocol.has_error) + if attached wire_protocol.retrieve_url (session_id) as l_url then + assert("Expected url", "http://www.google.com/" ~ l_url.out) + end + end + end + + + test_back_and_forward + local + capabilities : SE_CAPABILITIES + do + create capabilities.make + capabilities.set_browser_name ("chrome") + capabilities.set_takes_screenshot (True) + if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then + assert ("No error", not wire_protocol.has_error) + wire_protocol.navigate_to_url (l_session.session_id,"http://www.google.com/") + assert ("Has no error", not wire_protocol.has_error) + wire_protocol.navigate_to_url (l_session.session_id,"http://www.infoq.com/") + assert ("Has no error", not wire_protocol.has_error) + wire_protocol.navigate_to_url (l_session.session_id,"http://www.yahoo.com/") + assert ("Has no error", not wire_protocol.has_error) + + --back + wire_protocol.back (l_session.session_id) + assert ("Has no error", not wire_protocol.has_error) + + if attached wire_protocol.retrieve_url (l_session.session_id) as l_back_url then + assert ("Has no error", not wire_protocol.has_error) + assert ("Expected infoq", "http://www.infoq.com/" ~ l_back_url.out) + end + + -- forward + wire_protocol.forward (l_session.session_id) + assert ("Has no error", not wire_protocol.has_error) + + if attached wire_protocol.retrieve_url (l_session.session_id) as l_forward_url then + assert ("Has no error", not wire_protocol.has_error) + assert ("Expected yahoo", "http://www.yahoo.com/" ~ l_forward_url.out) + end + + end + end + + feature {NONE}-- Implementation wire_protocol: SE_JSON_WIRE_PROTOCOL once From 3c41ca08640f606c14d0d4249aa948e04a04fc2f Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 22 Apr 2013 09:15:50 -0300 Subject: [PATCH 07/36] Added new classes, implemented more methods from JSONWireProtol API. Added test cases --- library/test/selenium/src/command_executor.e | 336 ++++++++++++++++++ .../src/converter/se_cookie_json_converter.e | 100 ++++++ .../test/selenium/src/helpers/json_helper.e | 15 + .../src/protocol/se_json_wire_protocol.e | 304 +++++++++++++--- .../protocol/se_json_wire_protocol_commands.e | 147 +++++++- library/test/selenium/src/se_by.e | 155 ++++++++ library/test/selenium/src/se_cookie.e | 96 +++++ .../src/se_locator_strategy_constants.e | 28 ++ library/test/selenium/src/se_window.e | 48 +++ library/test/selenium/src/web_driver_cookie.e | 69 ---- library/test/selenium/src/web_element.e | 8 +- library/test/selenium/test/application.e | 130 +++++-- .../selenium/test/test_json_wire_protocol.e | 17 + library/test/selenium/test/test_se_by.e | 69 ++++ 14 files changed, 1364 insertions(+), 158 deletions(-) create mode 100644 library/test/selenium/src/converter/se_cookie_json_converter.e create mode 100644 library/test/selenium/src/se_by.e create mode 100644 library/test/selenium/src/se_cookie.e create mode 100644 library/test/selenium/src/se_locator_strategy_constants.e create mode 100644 library/test/selenium/src/se_window.e delete mode 100644 library/test/selenium/src/web_driver_cookie.e create mode 100644 library/test/selenium/test/test_se_by.e diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index 7d8e606b..8cdd36dc 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -396,6 +396,342 @@ feature -- Commands end + change_focus_window (a_session_id: STRING_32; a_data: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_window (a_session_id), a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + close_window (a_session_id: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_delete (cmd_session_window (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + + end + + change_size_window (a_session_id: STRING_32; a_window_handle : STRING_32;a_data: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_window_size (a_session_id,a_window_handle), a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + size_window (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + change_window_position (a_session_id: STRING_32; a_window_handle : STRING_32;a_data: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_window_position (a_session_id,a_window_handle), a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + window_position (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + window_maximize (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_window_maximize (a_session_id,a_window_handle), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + retrieve_cookies (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_cookie (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + set_cookie (a_session_id: STRING_32; a_data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_cookie (a_session_id),a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + delete_cookies (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_delete (cmd_session_cookie (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + delete_cookie_by_name (a_session_id: STRING_32; a_name : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_delete (cmd_session_cookie_delete (a_session_id,a_name)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + page_source (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_source (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + page_title (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_title (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + search_element (a_session_id: STRING_32; a_data :STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element (a_session_id),a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + search_element_id_element (a_session_id: STRING_32; id : STRING_32; a_data :STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_id_element (a_session_id,id),a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + search_elements (a_session_id: STRING_32; a_data :STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_elements (a_session_id),a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + + element_active (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_active (a_session_id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + search_element_id_elements (a_session_id: STRING_32; id : STRING_32; a_data :STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_id_elements (a_session_id,id),a_data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + feature {NONE} -- Implementation execute_get (command_name: STRING_32): HTTP_CLIENT_RESPONSE diff --git a/library/test/selenium/src/converter/se_cookie_json_converter.e b/library/test/selenium/src/converter/se_cookie_json_converter.e new file mode 100644 index 00000000..7c9898d5 --- /dev/null +++ b/library/test/selenium/src/converter/se_cookie_json_converter.e @@ -0,0 +1,100 @@ +note + description: "Summary description for {SE_COOKIE_JSON_CONVERTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_COOKIE_JSON_CONVERTER +inherit + SE_JSON_CONVERTER + +create + make + +feature {NONE} -- Initialization + + make + do + create object + end + +feature -- Access + + object: SE_COOKIE + +feature -- Conversion + + from_json (j: like to_json): detachable like object + do + create Result + if attached {STRING_32} json_to_object (j.item (name_key), Void) as l_item then + Result.set_name(l_item) + end + if attached {STRING_32} json_to_object (j.item (value_key), Void) as l_item then + Result.set_value(l_item) + end + if attached {STRING_32} json_to_object (j.item (path_key), Void) as l_item then + Result.set_path(l_item) + end + if attached {STRING_32} json_to_object (j.item (domain_key), Void) as l_item then + Result.set_domain(l_item) + end + if attached {BOOLEAN} json_to_object (j.item (secure_key), Void) as l_item then + if l_item then + Result.secure + end + end + if attached {INTEGER_32} json_to_object (j.item (expiry_key), Void) as l_item then + Result.set_expiry (l_item.as_natural_32) + end + + end + + to_json (o: like object): JSON_OBJECT + do + create Result.make + Result.put (json.value (o.name), name_key) + Result.put (json.value (o.value), value_key) + Result.put (json.value (o.path), path_key) + Result.put (json.value (o.domain), domain_key) + Result.put (json.value (o.is_secure), secure_key) + Result.put (json.value (o.expiry), expiry_key) + end + +feature {NONE} -- Implementation + + + + name_key: JSON_STRING + once + create Result.make_json ("name") + end + + value_key: JSON_STRING + once + create Result.make_json ("value") + end + + path_key: JSON_STRING + once + create Result.make_json ("path") + end + + domain_key: JSON_STRING + once + create Result.make_json ("domain") + end + + secure_key : JSON_STRING + once + create Result.make_json ("secure") + end + + expiry_key : JSON_STRING + once + create Result.make_json ("expiry") + end + + +end diff --git a/library/test/selenium/src/helpers/json_helper.e b/library/test/selenium/src/helpers/json_helper.e index 5d5cdd59..6439ed9f 100644 --- a/library/test/selenium/src/helpers/json_helper.e +++ b/library/test/selenium/src/helpers/json_helper.e @@ -71,6 +71,20 @@ feature -- Access end end + + json_to_se_cookie (post: STRING_32): detachable SE_COOKIE + local + parser: JSON_PARSER + do + initialize_converters (json) + create parser.make_parser (post) + if attached parser.parse_object as st and parser.is_parsed then + if attached {SE_COOKIE} json.object (st, "SE_COOKIE") as l_cookie then + Result := l_cookie + end + end + end + initialize_converters (j: like json) -- Initialize json converters do @@ -82,5 +96,6 @@ feature -- Access j.add_converter (create {SE_CAPABILITIES_JSON_CONVERTER}.make) j.add_converter (create {SE_RESPONSE_JSON_CONVERTER}.make) j.add_converter (create {SE_TIMEOUT_TYPE_JSON_CONVERTER}.make) + j.add_converter (create {SE_COOKIE_JSON_CONVERTER}.make) end end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index a72fa163..53e0644d 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -3,7 +3,7 @@ note author: "" date: "$Date$" revision: "$Revision$" - EIS: "name=SELINIUM", "protocol=http", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol" + EIS: "name=SELINIUM", "protocol=selenium", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol" class SE_JSON_WIRE_PROTOCOL @@ -67,7 +67,7 @@ feature -- Commands if attached response.json_response as l_response then Result := json_to_se_status (l_response) end - end + end end end @@ -146,7 +146,7 @@ feature -- Commands -- Returns: -- {object} An object describing the session's capabilities. local - response : SE_RESPONSE + response: SE_RESPONSE do if commnad_executor.is_available then response := commnad_executor.retrieve_session (a_session_id) @@ -587,7 +587,6 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- NoSuchFrame - If the frame specified by id cannot be found. do - -- TODO end change_focus_window (a_session_id: STRING_32; a_name: STRING_32) @@ -599,8 +598,18 @@ feature -- Commands -- name - {string} The window to change focus to. -- Potential Errors: -- NoSuchWindow - If the window specified by name cannot be found. + local + l_json: STRING_32 + resp: SE_RESPONSE do - -- TODO + l_json := "[ + { "name": "$name" } + ]" + l_json.replace_substring_all ("$name", a_name) + if commnad_executor.is_available then + resp := commnad_executor.change_focus_window (a_session_id, l_json) + check_response (resp) + end end close_window (a_session_id: STRING_32) @@ -610,11 +619,16 @@ feature -- Commands -- :sessionId - ID of the session to route the command to. -- Potential Errors: -- NoSuchWindow - If the currently selected window is already closed + local + resp: SE_RESPONSE do - --TODO + if commnad_executor.is_available then + resp := commnad_executor.close_window (a_session_id) + check_response (resp) + end end - change_size_window (a_session_id: STRING_32; a_window_handle: STRING_32) + change_size_window (a_session_id: STRING_32; a_window_handle: STRING_32; a_width: NATURAL_32; a_height: NATURAL_32) -- POST /session/:sessionId/window/:windowHandle/size -- Change the size of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be resized. -- URL Parameters: @@ -622,10 +636,24 @@ feature -- Commands -- JSON Parameters: -- width - {number} The new window width. -- height - {number} The new window height. + local + l_json: STRING_32 + resp: SE_RESPONSE do + l_json := "[ + { "width": $width, + "height": $height + } + ]" + l_json.replace_substring_all ("$width", a_width.out) + l_json.replace_substring_all ("$height", a_height.out) + if commnad_executor.is_available then + resp := commnad_executor.change_size_window (a_session_id, a_window_handle, l_json) + check_response (resp) + end end - size_window (a_session_id: STRING_32; a_window_handle: STRING_32) + size_window (a_session_id: STRING_32; a_window_handle: STRING_32): SE_WINDOW -- GET /session/:sessionId/window/:windowHandle/size -- Get the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned. -- URL Parameters: @@ -634,11 +662,27 @@ feature -- Commands -- {width: number, height: number} The size of the window. -- Potential Errors: -- NoSuchWindow - If the specified window cannot be found. + local + resp: SE_RESPONSE do - --TODO + create Result + if commnad_executor.is_available then + resp := commnad_executor.size_window (a_session_id, a_window_handle) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as l_json_object then + if attached l_json_object.item ("width") as l_width then + Result.set_width (l_width.representation.to_natural_32) + end + if attached l_json_object.item ("height") as l_height then + Result.set_width (l_height.representation.to_natural_32) + end + end + end + end end - change_window_position (a_session_id: STRING_32; a_window_handle: STRING_32) + change_window_position (a_session_id: STRING_32; a_window_handle: STRING_32; an_x: INTEGER_32; an_y: INTEGER_32) -- POST /session/:sessionId/window/:windowHandle/position -- Change the position of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be moved. -- URL Parameters: @@ -648,11 +692,24 @@ feature -- Commands -- y - {number} The Y coordinate to position the window at, relative to the upper left corner of the screen. -- Potential Errors: -- NoSuchWindow - If the specified window cannot be found. + local + l_json: STRING_32 + resp: SE_RESPONSE do - -- TODO + l_json := "[ + { "x": $x, + "y": $y + } + ]" + l_json.replace_substring_all ("$x", an_x.out) + l_json.replace_substring_all ("$y", an_y.out) + if commnad_executor.is_available then + resp := commnad_executor.change_window_position (a_session_id, a_window_handle, l_json) + check_response (resp) + end end - window_position (a_sesion_id: STRING_32; a_window_handle: STRING_32) + window_position (a_session_id: STRING_32; a_window_handle: STRING_32): SE_WINDOW -- GET /session/:sessionId/window/:windowHandle/position -- Get the position of the specified window. If the :windowHandle URL parameter is "current", the position of the currently active window will be returned. -- URL Parameters: @@ -661,21 +718,43 @@ feature -- Commands -- {x: number, y: number} The X and Y coordinates for the window, relative to the upper left corner of the screen. -- Potential Errors: -- NoSuchWindow - If the specified window cannot be found. + local + resp: SE_RESPONSE do - --TODO + create Result + if commnad_executor.is_available then + resp := commnad_executor.window_position (a_session_id, a_window_handle) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as l_json_object then + if attached l_json_object.item ("x") as l_x then + Result.set_x (l_x.representation.to_integer_32) + end + if attached l_json_object.item ("y") as l_y then + Result.set_y (l_y.representation.to_integer_32) + end + end + end + end end - window_maximize (a_session_id: STRING_32; a_window_haNdle: STRING_32) + window_maximize (a_session_id: STRING_32; a_window_handle: STRING_32) -- POST /session/:sessionId/window/:windowHandle/maximize -- Maximize the specified window if not already maximized. If the :windowHandle URL parameter is "current", the currently active window will be maximized. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- Potential Errors: -- NoSuchWindow - If the specified window cannot be found. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.window_maximize (a_session_id, a_window_handle) + check_response (resp) + end end - retrieve_cookies (a_session_id: STRING_32) + retrieve_cookies (a_session_id: STRING_32): detachable LIST [SE_COOKIE] -- GET /session/:sessionId/cookie -- Retrieve all cookies visible to the current page. -- URL Parameters: @@ -684,18 +763,55 @@ feature -- Commands -- {Array.} A list of cookies. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE + index: INTEGER do + -- Check the format of internal json object + if commnad_executor.is_available then + resp := commnad_executor.retrieve_cookies (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [SE_COOKIE]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_VALUE} l_json_array.i_th (index) as json_str then + if attached json_to_se_cookie (json_str.representation) as l_item then + Result.force (l_item) + end + end + index := index + 1 + end + end + end + end end - set_cookie (a_session_id: STRING_32) + set_cookie (a_session_id: STRING_32; a_cookie: SE_COOKIE) -- POST /session/:sessionId/cookie -- Set a cookie. If the cookie path is not specified, it should be set to "/". Likewise, if the domain is omitted, it should default to the current page's domain. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: -- cookie - {object} A JSON object defining the cookie to add. + local + l_data: STRING_32 + response: SE_RESPONSE do - -- TODO + l_data := "[ + { "cookie": $cookie} + ]" + if commnad_executor.is_available then + if attached to_json (a_cookie) as l_json then + l_data.replace_substring_all ("$cookie", l_json.representation) + response := commnad_executor.set_cookie (a_session_id, l_data) + check_response (response) + end + end end delete_cookies (a_session_id: STRING_32) @@ -707,8 +823,13 @@ feature -- Commands -- InvalidCookieDomain - If the cookie's domain is not visible from the current page. -- NoSuchWindow - If the currently selected window has been closed. -- UnableToSetCookie - If attempting to set a cookie on a page that does not support cookies (e.g. pages with mime-type text/plain). + local + response: SE_RESPONSE do - -- TODO + if commnad_executor.is_available then + response := commnad_executor.delete_cookies (a_session_id) + check_response (response) + end end delete_cookie_by_name (a_session_id: STRING_32; a_name: STRING_32) @@ -719,11 +840,16 @@ feature -- Commands -- :name - The name of the cookie to delete. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + response: SE_RESPONSE do - -- TODO + if commnad_executor.is_available then + response := commnad_executor.delete_cookie_by_name (a_session_id, a_name) + check_response (response) + end end - page_source (a_session_id: STRING_32) + page_source (a_session_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/source -- Get the current page source. -- URL Parameters: @@ -732,10 +858,21 @@ feature -- Commands -- {string} The current page source. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.page_source (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - page_title (a_session_id: STRING_32) + page_title (a_session_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/title -- Get the current page title. -- URL Parameters: @@ -744,11 +881,21 @@ feature -- Commands -- {string} The current page title. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE do - -- TODO + if commnad_executor.is_available then + resp := commnad_executor.page_title (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - search_element (a_session_id: STRING_32) + search_element (a_session_id: STRING_32; strategy: STRING_32): detachable WEB_ELEMENT -- POST /session/:sessionId/element -- Search for an element on the page, starting from the document root. The located element will be returned as a -- WebElement JSON object. The table below lists the locator strategies that each server should support. @@ -775,11 +922,23 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- NoSuchElement - If the element cannot be found. -- XPathLookupError - If using XPath and the input expression is invalid. + require + has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + local + resp: SE_RESPONSE do - -- TODO + if commnad_executor.is_available then + resp := commnad_executor.search_element (a_session_id, strategy) + check_response (resp) + if not has_error then + if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then + create Result.make (l_elem.representation) + end + end + end end - search_elements (a_session_id: STRING_32) + search_elements (a_session_id: STRING_32; strategy: STRING_32): detachable LIST [WEB_ELEMENT] -- POST /session/:sessionId/elements -- Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. The table below lists the locator strategies that each server should support. Elements should be returned in the order located in the DOM. -- @@ -803,10 +962,34 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- XPathLookupError - If using XPath and the input expression is invalid. + require + has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + local + resp: SE_RESPONSE + index: INTEGER do + if commnad_executor.is_available then + resp := commnad_executor.search_elements (a_session_id, strategy) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [WEB_ELEMENT]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_OBJECT} l_json_array.i_th (index) as json_str and then attached json_str.item ("ELEMENT") as l_elem then + Result.force (create {WEB_ELEMENT}.make (l_elem.representation)) + end + index := index + 1 + end + end + end + end end - element_active (a_session_id: STRING_32) + element_active (a_session_id: STRING_32): detachable WEB_ELEMENT -- POST /session/:sessionId/element/active -- Get the element on the page that currently has focus. The element will be returned as a WebElement JSON object. -- URL Parameters: @@ -815,24 +998,35 @@ feature -- Commands -- {ELEMENT:string} A WebElement JSON object for the active element. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_active (a_session_id) + check_response (resp) + if not has_error then + if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then + create Result.make (l_elem.representation) + end + end + end end - element_id (a_session_id: STRING_32) - -- GET /session/:sessionId/element/:id - -- Describe the identified element. - -- Note: This command is reserved for future use; its return type is currently undefined. +-- element_id (a_session_id: STRING_32; ) +-- -- GET /session/:sessionId/element/:id +-- -- Describe the identified element. +-- -- Note: This command is reserved for future use; its return type is currently undefined. - -- URL Parameters: - -- :sessionId - ID of the session to route the command to. - -- :id - ID of the element to route the command to. - -- Potential Errors: - -- NoSuchWindow - If the currently selected window has been closed. - -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. - do - end +-- -- URL Parameters: +-- -- :sessionId - ID of the session to route the command to. +-- -- :id - ID of the element to route the command to. +-- -- Potential Errors: +-- -- NoSuchWindow - If the currently selected window has been closed. +-- -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. +-- do +-- end - search_element_id (a_session_id: STRING_32; an_id: STRING_32) + search_element_id_element (a_session_id: STRING_32; an_id: STRING_32; strategy : STRING_32) : detachable WEB_ELEMENT -- POST /session/:sessionId/element/:id/element -- Search for an element on the page, starting from the identified element. -- The located element will be returned as a WebElement JSON object. @@ -862,10 +1056,24 @@ feature -- Commands -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- NoSuchElement - If the element cannot be found. -- XPathLookupError - If using XPath and the input expression is invalid. + require + has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.search_element_id_element (a_session_id,an_id,strategy) + check_response (resp) + if not has_error then + if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then + create Result.make (l_elem.representation) + end + end + end end - search_elements_id (a_session_id: STRING_32; an_id: STRING_32) + + search_elements_id (a_session_id: STRING_32; an_id: STRING_32; strategy : STRING_32) : detachable LIST[WEB_ELEMENT] -- POST /session/:sessionId/element/:id/elements -- Search for multiple elements on the page, starting from the identified element. -- The located elements will be returned as a WebElement JSON objects. @@ -894,7 +1102,21 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- XPathLookupError - If using XPath and the input expression is invalid. + require + has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.search_element_id_elements (a_session_id,an_id,strategy) + check_response (resp) + if not has_error then +-- if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then +-- create Result.make (l_elem.representation) +-- end + end + end + end element_click (a_session_id: STRING_32; an_id: STRING_32) @@ -1604,7 +1826,7 @@ feature {NONE} -- Implementation new_session (value: STRING_32; to: STRING_32): detachable SE_SESSION local - l_rep : STRING_32 + l_rep: STRING_32 do if to.is_case_insensitive_equal ("session") then if attached {JSON_OBJECT} string_to_json (value) as l_value then diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index c8b25e8d..68af3b22 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -163,26 +163,137 @@ feature ---POST /session/:sessionId/ime/activate Make an engines that is available (appears on the listreturned by getAvailableEngines) active. --POST /session/:sessionId/frame Change focus to another frame on the page. ---POST /session/:sessionId/window Change focus to another window. ---DELETE /session/:sessionId/window Close the current window. ---POST /session/:sessionId/window/:windowHandle/size Change the size of the specified window. ---GET /session/:sessionId/window/:windowHandle/size Get the size of the specified window. ---POST /session/:sessionId/window/:windowHandle/position Change the position of the specified window. ---GET /session/:sessionId/window/:windowHandle/position Get the position of the specified window. ---POST /session/:sessionId/window/:windowHandle/maximize Maximize the specified window if not already maximized. ---GET /session/:sessionId/cookie Retrieve all cookies visible to the current page. ---POST /session/:sessionId/cookie Set a cookie. ---DELETE /session/:sessionId/cookie Delete all cookies visible to the current page. ---DELETE /session/:sessionId/cookie/:name Delete the cookie with the given name. ---GET /session/:sessionId/source Get the current page source. ---GET /session/:sessionId/title Get the current page title. ---POST /session/:sessionId/element Search for an element on the page, starting from the document root. ---POST /session/:sessionId/elements Search for multiple elements on the page, starting from the document root. ---POST /session/:sessionId/element/active Get the element on the page that currently has focus. + + cmd_session_window_tmpl : STRING ="session/$id/window" + + cmd_session_window (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_window_size_tmpl : STRING ="session/$id/window/$windowHandle/size" + + cmd_session_window_size (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_size_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end + + cmd_session_window_position_tmpl : STRING ="session/$id/window/$windowHandle/position" + + cmd_session_window_position (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_position_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end + + cmd_session_window_maximize_tmpl : STRING ="session/$id/window/$windowHandle/maximize" + + cmd_session_window_maximize (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_maximize_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end + + + + cmd_session_cookie_tmpl : STRING ="session/$id/cookie" + + cmd_session_cookie (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_cookie_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_cookie_delte_tmpl : STRING ="session/$id/cookie/$name" + + cmd_session_cookie_delete (id: STRING_32;name : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_cookie_delte_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$name", name) + end + + cmd_session_source_tmpl : STRING ="session/$id/source" + + cmd_session_source (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_source_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_title_tmpl : STRING ="session/$id/title" + + cmd_session_title (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_source_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_tmpl : STRING ="session/$id/element" + + cmd_session_element (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_elements_tmpl : STRING ="session/$id/elements" + + cmd_session_elements (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_elements_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_active_tmpl : STRING ="session/$id/element/active" + + cmd_session_element_active (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_active_tmpl) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_id_tmpl : STRING ="session/$sessionId/element/$id" + + cmd_session_element_id (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + --GET /session/:sessionId/element/:id Describe the identified element. ---POST /session/:sessionId/element/:id/element Search for an element on the page, starting from the identified element. + + cmd_session_element_id_element_tmpl : STRING ="session/$sessionId/element/$id/element" + + cmd_session_element_id_element (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_element_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_id_elements_tmpl : STRING ="session/$sessionId/element/$id/elements" + + cmd_session_element_id_elements (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_elements_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + --POST /session/:sessionId/element/:id/elements Search for multiple elements on the page, starting from the identified element. --POST /session/:sessionId/element/:id/click Click on an element. --POST /session/:sessionId/element/:id/submit Submit a FORM element. diff --git a/library/test/selenium/src/se_by.e b/library/test/selenium/src/se_by.e new file mode 100644 index 00000000..ea4f37ec --- /dev/null +++ b/library/test/selenium/src/se_by.e @@ -0,0 +1,155 @@ +note + description: "Objects used to locate elements within a document" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_BY +inherit + JSON_HELPER + SE_LOCATOR_STRATEGY_CONSTANTS + +create default_create + +feature -- Access + id (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `id' and value `value' + -- { "using" : "id", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_id) + Result.replace_substring_all ("$value", value) + ensure + has_id_strategy : has_correct_stategy (Result, se_id) + end + + name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `name' and value `value' + -- { "using" : "name", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_name) + Result.replace_substring_all ("$value", value) + ensure + has_name_strategy : has_correct_stategy (Result, se_name) + end + + class_name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `class name' and value `value' + -- { "using" : "class name", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_class_name) + Result.replace_substring_all ("$value", value) + ensure + has_class_name_strategy : has_correct_stategy (Result, se_class_name) + end + + + css_selector (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `css selector' and value `value' + -- { "using" : "css selector", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_css_selector) + Result.replace_substring_all ("$value", value) + ensure + has_css_selector_strategy : has_correct_stategy (Result, se_css_selector) + end + + link_text (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `link text' and value `value' + -- { "using" : "link text", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_link_text) + Result.replace_substring_all ("$value", value) + ensure + has_link_text_strategy : has_correct_stategy (Result, se_link_text) + end + + + partial_link_text (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `partial link text' and value `value' + -- { "using" : "partial link text", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_partial_link_text) + Result.replace_substring_all ("$value", value) + ensure + has_partial_link_text_strategy : has_correct_stategy (Result, se_partial_link_text) + end + + tag_name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `tag name' and value `value' + -- { "using" : "tag name", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_tag_name) + Result.replace_substring_all ("$value", value) + ensure + has_tag_name_strategy : has_correct_stategy (Result, se_tag_name) + end + + + xpath (an_id : STRING_32; value : STRING_32 ) : STRING_32 + -- return a STRING representing a JSON + -- with strategy by `xpath' and value `value' + -- { "using" : "xpath", "value":value } + do + create Result.make_from_string (json_template) + Result.replace_substring_all ("$using", se_xpath) + Result.replace_substring_all ("$value", value) + ensure + has_xpath_strategy : has_correct_stategy (Result, se_xpath) + end + + +feature -- Query + has_correct_stategy (data: STRING_32; strategy : STRING_32) : BOOLEAN + do + if attached {JSON_OBJECT} string_to_json(data) as l_json then + if attached l_json.item ("using") as l_using then + Result := (l_using.representation).is_case_insensitive_equal_general ("%""+strategy+"%"") + end + end + end + + + is_valid_strategy (data : STRING_32) : BOOLEAN + -- if data is using on of the following strategies + -- class name + -- css selector + -- id + -- name + -- link text + -- partial link text + -- tag name + -- xpath + -- return True in othercase False + do + Result := has_correct_stategy (data, se_class_name) or else + has_correct_stategy (data, se_css_selector) or else + has_correct_stategy (data, se_id) or else + has_correct_stategy (data, se_link_text) or else + has_correct_stategy (data, se_name) or else + has_correct_stategy (data, se_partial_link_text) or else + has_correct_stategy (data, se_tag_name) or else + has_correct_stategy (data, se_xpath) + end + + +feature {NONE} -- Implementation + json_template : String = "[ + {"using" :"$using", + "value" : "$value"} + ]" +end diff --git a/library/test/selenium/src/se_cookie.e b/library/test/selenium/src/se_cookie.e new file mode 100644 index 00000000..6731afdb --- /dev/null +++ b/library/test/selenium/src/se_cookie.e @@ -0,0 +1,96 @@ +note + description: "bject that describe a cookie. When returning Cookie objects, the server should only omit an optional field if it is incapable of providing the information." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_COOKIE + +create + default_create, make_with_values + +feature -- Initialization + + make_with_values (a_name: STRING_32; a_value: STRING_32; a_path: STRING_32; a_domain: STRING_32) + do + set_name (a_name) + set_path (a_path) + set_value (a_value) + set_domain (a_domain) + end + +feature -- Access + + name: detachable STRING_32 + --The name of the cookie. + + value: detachable STRING_32 + -- The cookie value. + + path: detachable STRING_32 + --(Optional) The cookie path + + domain: detachable STRING_32 + --(Optional) The domain the cookie is visible to. + + is_secure: BOOLEAN + --(Optional) Whether the cookie is a secure cookie + + expiry: NATURAL_32 + -- (Optional) When the cookie expires, specified in seconds since midnight, January 1, 1970 UTC.1 + +feature -- Change Element + + set_name (a_name: STRING_32) + do + name := a_name + ensure + assigned_name: name ~ a_name + end + + set_value (a_value: STRING_32) + do + value := a_value + ensure + assigned_value: value ~ a_value + end + + set_path (a_path: STRING_32) + do + path := a_path + ensure + assigned_path: path ~ a_path + end + + set_domain (a_domain: STRING_32) + do + domain := a_domain + ensure + assigned_domain: domain ~ a_domain + end + + secure + -- set the cookie as secure + do + is_secure := True + ensure + is_secure: is_secure + end + + insecure + -- set the cookie as insecure + do + is_secure := False + ensure + is_not_secure: not is_secure + end + + set_expiry (an_expiry: NATURAL) + do + expiry := an_expiry + ensure + assigned_expiry: expiry ~ an_expiry + end + +end diff --git a/library/test/selenium/src/se_locator_strategy_constants.e b/library/test/selenium/src/se_locator_strategy_constants.e new file mode 100644 index 00000000..86465de4 --- /dev/null +++ b/library/test/selenium/src/se_locator_strategy_constants.e @@ -0,0 +1,28 @@ +note + description: "Summary description for {SE_LOCATOR_STRATEGY_CONSTANTS}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + SE_LOCATOR_STRATEGY_CONSTANTS + +feature -- Constants + se_class_name : STRING_32 = "class name" + + se_css_selector : STRING_32 = "css selector" + + se_id : STRING_32 = "id" + + se_name : STRING_32 = "name" + + se_link_text : STRING_32 = "link text" + + se_partial_link_text : STRING_32 = "partial link text" + + se_tag_name : STRING_32 = "tag name" + + se_xpath : STRING_32 = "xpath" + + +end diff --git a/library/test/selenium/src/se_window.e b/library/test/selenium/src/se_window.e new file mode 100644 index 00000000..91c75151 --- /dev/null +++ b/library/test/selenium/src/se_window.e @@ -0,0 +1,48 @@ +note + description: "Summary description for {SE_WINDOW}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_WINDOW +create + default_create, + make_with_values + +feature -- Initialization + + make_with_values (a_width : NATURAL_32; a_height : NATURAL_32) + do + set_width (a_width) + set_height (a_height) + end + +feature -- Access + --width: number, height: number} The size of the window. + width : NATURAL_32 + height : NATURAL_32 + x,y : INTEGER_32 + +feature -- Change Element + set_width (a_width : NATURAL_32) + do + width := a_width + end + + set_height (a_height : NATURAL_32) + do + height := a_height + end + + set_x (an_x : INTEGER_32) + do + x := an_x + end + + set_y (an_y : INTEGER_32) + do + y := an_y + end + +end diff --git a/library/test/selenium/src/web_driver_cookie.e b/library/test/selenium/src/web_driver_cookie.e deleted file mode 100644 index 311a5bdb..00000000 --- a/library/test/selenium/src/web_driver_cookie.e +++ /dev/null @@ -1,69 +0,0 @@ -note - description: "Object that describe a cookie. When returning Cookie objects, the server should only omit an optional field if it is incapable of providing the information." - author: "" - date: "$Date$" - revision: "$Revision$" - -class - WEB_DRIVER_COOKIE - -create - make -feature {NONE}-- Initialization - make (a_name : STRING_32; a_value: STRING_32) - do - set_name (a_name) - set_value (a_value) - end - -feature -- Access - name : STRING_32 - --The name of the cookie. - - value : STRING_32 - -- The cookie value. - - path : detachable STRING_32 - --(Optional) The cookie path - - domain : detachable STRING_32 - --(Optional) The domain the cookie is visible to. - - secure : BOOLEAN - --(Optional) Whether the cookie is a secure cookie - - expiry : NATURAL_32 - -- (Optional) When the cookie expires, specified in seconds since midnight, January 1, 1970 UTC.1 - -feature -- Change Element - set_name (a_name:STRING_32) - do - name := a_name - end - - set_value (a_value:STRING_32) - do - value := a_value - end - - set_path (a_path : STRING_32) - do - path := a_path - end - - set_domain (a_domain : STRING_32) - do - domain := a_domain - end - - set_secure (a_value : BOOLEAN) - do - secure := a_value - end - - set_expiry ( a_value : NATURAL_32) - do - expiry := a_value - end - -end diff --git a/library/test/selenium/src/web_element.e b/library/test/selenium/src/web_element.e index 91abe6c8..d0fd67f0 100644 --- a/library/test/selenium/src/web_element.e +++ b/library/test/selenium/src/web_element.e @@ -9,17 +9,17 @@ class create make feature - make + make ( an_element : STRING_32) do - + set_element (an_element) end feature -- Access - element : detachable STRING_32 + element : STRING_32 --The opaque ID assigned to the element by the server. --This ID should be used in all subsequent commands issued against the element. feature -- Change Element - set_element (an_element : STRING) + set_element (an_element : STRING_32) do element := an_element end diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e index c822c072..3787b649 100644 --- a/library/test/selenium/test/application.e +++ b/library/test/selenium/test/application.e @@ -18,19 +18,111 @@ create feature {NONE} -- Initialization make + do +-- test_back_forward_refesh +-- test_status_sessions_timeout + test_ime_actions + end + + + test_ime_actions + local + web_driver: SE_JSON_WIRE_PROTOCOL + capabilities: SE_CAPABILITIES + timeout: SE_TIMEOUT_TYPE + + do + -- check if the selenium Remote WebDriver is up and running. + create web_driver.make + if attached web_driver.status as l_status then + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then + print ("%NSessionId:" + l_session.session_id) + -- available engines + if attached web_driver.ime_available_engines (l_session.session_id) as l_available then + check + has_no_error : not web_driver.has_error + end + else + check has_error : web_driver.has_error end + -- ime_active_engine + check + no_active_engine : web_driver.ime_active_engine (l_session.session_id) = Void + has_error : web_driver.has_error + end + -- ime_activated + check + no_active: not web_driver.ime_activated (l_session.session_id) + has_error : web_driver.has_error + end + -- ime_deactivate + web_driver.ime_deactivate (l_session.session_id) + check + has_error : web_driver.has_error + end + + -- ime_activate + web_driver.ime_activate (l_session.session_id,"UNKown") + check + has_error : web_driver.has_error + end + end + end + + create capabilities.make + capabilities.set_browser_name ("firefox") + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then + print ("%NSessionId:" + l_session.session_id) + check + no_error_firefox: not web_driver.has_error + end + end + end + end + test_status_sessions_timeout local web_driver: SE_JSON_WIRE_PROTOCOL capabilities: SE_CAPABILITIES timeout: SE_TIMEOUT_TYPE do - -- check if the selenium Remote WebDriver is up and running. + -- check if the selenium Remote WebDriver is up and running. create web_driver.make if attached web_driver.status as l_status then print (l_status) + -- create a new session + create capabilities.make + capabilities.set_browser_name ("chrome") + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session2 then + print ("%NSessionId:" + l_session2.session_id) + end + -- retrieve sessions + if attached web_driver.sessions as l_session then + across + l_session as l_item + loop + print (l_item) + end + end + if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session2 then + print ("%NSessionId:" + l_session2.session_id) + create timeout.make ("script", 1) + web_driver.set_session_timeouts (l_session2.session_id, timeout) + end - - -- create a new session + else + print ("The selenium server is not accesible") + end + end + test_back_forward_refesh + local + web_driver: SE_JSON_WIRE_PROTOCOL + capabilities: SE_CAPABILITIES + file : RAW_FILE + do + create web_driver.make + -- create a new session create capabilities.make capabilities.set_browser_name ("chrome") if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then @@ -81,36 +173,22 @@ feature {NONE} -- Initialization check Has_no_error: not web_driver.has_error end + if attached web_driver.screenshot (l_session.session_id) as l_screenshot then + check + Has_no_error: not web_driver.has_error + end + create file.make_with_name ("screenshot_"+l_session.session_id+".png") + file.open_write + file.putstring (l_screenshot) + file.close + end end - -- create a new session - create capabilities.make - capabilities.set_browser_name ("chrome") - if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then - print ("%NSessionId:" + l_session.session_id) - create timeout.make ("script", 1) - web_driver.set_session_timeouts (l_session.session_id, timeout) - end - --- -- retrieve sessions --- if attached web_driver.sessions as l_session then --- across --- l_session as l_item --- loop --- print (l_item) --- end --- end - else - print ("The selenium server is not accesible") - end end - test_session local h: LIBCURL_HTTP_CLIENT session: HTTP_CLIENT_SESSION resp: detachable HTTP_CLIENT_RESPONSE - l_location: detachable READABLE_STRING_8 - body: STRING context: HTTP_CLIENT_REQUEST_CONTEXT s: READABLE_STRING_8 do diff --git a/library/test/selenium/test/test_json_wire_protocol.e b/library/test/selenium/test/test_json_wire_protocol.e index 8c1dbb1c..2484cf4a 100644 --- a/library/test/selenium/test/test_json_wire_protocol.e +++ b/library/test/selenium/test/test_json_wire_protocol.e @@ -273,6 +273,23 @@ feature -- Test routines end end + test_ime_available_engines + local + capabilities : SE_CAPABILITIES + do + if attached wire_protocol.ime_available_engines (session_id) as l_ime_available_engines then + assert ("Has no error", not wire_protocol.has_error) + across l_ime_available_engines as item loop + print (item) + end + else + assert ("Has error :", wire_protocol.has_error) + if attached wire_protocol.last_error as l_error then + assert ("Status 13", l_error.code = 13) + end + end + end + feature {NONE}-- Implementation wire_protocol: SE_JSON_WIRE_PROTOCOL diff --git a/library/test/selenium/test/test_se_by.e b/library/test/selenium/test/test_se_by.e new file mode 100644 index 00000000..0b47c052 --- /dev/null +++ b/library/test/selenium/test/test_se_by.e @@ -0,0 +1,69 @@ +note + description: "[ + Eiffel tests that can be executed by testing tool. + ]" + author: "EiffelStudio test wizard" + date: "$Date$" + revision: "$Revision$" + testing: "type/manual" + +class + TEST_SE_BY + +inherit + EQA_TEST_SET + redefine + on_prepare, + on_clean + end + +feature {NONE} -- Events + + on_prepare + -- + do +-- assert ("not_implemented", False) + end + + on_clean + -- + do +-- assert ("not_implemented", False) + end + +feature -- Test routines + + test_valid_strategy_id + local + l_data : STRING_32 + do + l_data := "[ + {"using":"id", "value":"test"} + ]" + assert ("Expected true", (create {SE_BY}).is_valid_strategy (l_data)) + end + + test_valid_strategy_name + local + l_data : STRING_32 + do + l_data := "[ + {"using":"name", "value":"test"} + ]" + assert ("Expected true", (create {SE_BY}).is_valid_strategy (l_data)) + end + + test_wrong_strategy + local + l_data : STRING_32 + do + l_data := "[ + {"using":"wrong", "value":"test"} + ]" + assert ("Expected False", not (create {SE_BY}).is_valid_strategy (l_data)) + end + + +end + + From 9e8548d65a9217ea97dba59c0b70b4a06c509054 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 23 Apr 2013 08:26:02 -0300 Subject: [PATCH 08/36] Added more commands from the JSONWireProtocol. --- library/test/selenium/src/command_executor.e | 127 ++++++++++++++++++ .../src/protocol/se_json_wire_protocol.e | 113 +++++++++++++--- .../protocol/se_json_wire_protocol_commands.e | 76 +++++++++-- 3 files changed, 290 insertions(+), 26 deletions(-) diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index 8cdd36dc..c6362e5a 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -730,8 +730,135 @@ feature -- Commands end end + element_click (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_click (a_session_id,id),Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + element_submit (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_submit (a_session_id,id),Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + element_text (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_text (a_session_id,id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + send_events (a_session_id: STRING_32; id : STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_event (a_session_id,id),data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + send_key_strokes (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_keys (a_session_id),data) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + query_by_tag_name (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_name (a_session_id,id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + + clear_element (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_element_clear (a_session_id,id), Void) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end feature {NONE} -- Implementation execute_get (command_name: STRING_32): HTTP_CLIENT_RESPONSE diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index 53e0644d..621c0233 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -1106,14 +1106,25 @@ feature -- Commands has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) local resp : SE_RESPONSE + index : INTEGER do if commnad_executor.is_available then resp := commnad_executor.search_element_id_elements (a_session_id,an_id,strategy) check_response (resp) - if not has_error then --- if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then --- create Result.make (l_elem.representation) --- end + if not has_error then + if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then + create {ARRAYED_LIST [WEB_ELEMENT]} Result.make (10) + from + index := 1 + until + index > l_json_array.count + loop + if attached {JSON_OBJECT} l_json_array.i_th (index) as json_str and then attached json_str.item ("ELEMENT") as l_elem then + Result.force (create {WEB_ELEMENT}.make (l_elem.representation)) + end + index := index + 1 + end + end end end @@ -1129,7 +1140,13 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_click (a_session_id,an_id) + check_response (resp) + end end element_submit (a_session_id: STRING_32; an_id: STRING_32) @@ -1141,10 +1158,16 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_submit (a_session_id,an_id) + check_response (resp) + end end - element_text (a_session_id: STRING_32; an_id: STRING_32) + element_text (a_session_id: STRING_32; an_id: STRING_32) : detachable STRING_32 -- GET /session/:sessionId/element/:id/text -- Returns the visible text for the element. -- URL Parameters: @@ -1153,10 +1176,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_text (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - send_event (a_session_id: STRING_32; an_id: STRING_32) + send_event (a_session_id: STRING_32; an_id: STRING_32; events : ARRAY[STRING_32]) -- POST /session/:sessionId/element/:id/value -- Send a sequence of key strokes to an element. -- Any UTF-8 character may be specified, however, if the server does not support native key events, @@ -1193,22 +1227,48 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) - do - end + local + resp: SE_RESPONSE + l_json : STRING_32 + do + l_json := "[ + {"value":$array} + ]" + if commnad_executor.is_available then + if attached json.value (create {ARRAYED_LIST[STRING_32]}.make_from_array(events)) as l_array then + l_json.replace_substring_all ("$array", l_array.representation) + resp := commnad_executor.send_events (a_session_id, an_id, l_json) + check_response (resp) + end + end + end - send_key_strokes (a_session_id: STRING_32) + send_key_strokes (a_session_id: STRING_32 ; keys : ARRAY[STRING_32]) -- POST /session/:sessionId/keys -- Send a sequence of key strokes to the active element. This command is similar to the send keys command in every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: - -- value - {Array.} The keys sequence to be sent. The sequence is defined in thesend keys command. + -- value - {Array.} The keys sequence to be sent. The sequence is defined in the send keys command. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. - do - end + local + resp: SE_RESPONSE + l_json : STRING_32 + do + l_json := "[ + {"value":$array} + ]" + if commnad_executor.is_available then + if attached json.value (create {ARRAYED_LIST[STRING_32]}.make_from_array(keys)) as l_array then + l_json.replace_substring_all ("$array", l_array.representation) + resp := commnad_executor.send_key_strokes (a_session_id, l_json) + check_response (resp) + end + end + end - query_by_tag_name (a_session_id: STRING_32; an_id: STRING_32) + query_by_tag_name (a_session_id: STRING_32; an_id: STRING_32) : detachable STRING_32 -- GET /session/:sessionId/element/:id/name -- Query for an element's tag name. -- URL Parameters: @@ -1219,10 +1279,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.query_by_tag_name (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - clear (a_session_id: STRING_32; an_id: STRING_32) + clear_element (a_session_id: STRING_32; an_id: STRING_32) -- POST /session/:sessionId/element/:id/clear -- Clear a TEXTAREA or text INPUT element's value. -- URL Parameters: @@ -1233,10 +1304,16 @@ feature -- Commands -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) -- InvalidElementState - If the referenced element is disabled. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.clear_element (a_session_id, an_id) + check_response (resp) + end end - is_selected (a_session_id: STRING_32; an_id: STRING_32) + is_selected (a_session_id: STRING_32; an_id: STRING_32) : BOOLEAN -- GET /session/:sessionId/element/:id/selected -- Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. -- URL Parameters: @@ -1250,7 +1327,7 @@ feature -- Commands do end - is_enabled (a_session_id: STRING_32; an_id: STRING_32) + is_enabled (a_session_id: STRING_32; an_id: STRING_32) : BOOLEAN -- GET /session/:sessionId/element/:id/enabled -- Determine if an element is currently enabled. -- URL Parameters: @@ -1264,7 +1341,7 @@ feature -- Commands do end - element_value (a_session_id: STRING_32; an_id: STRING_32; a_name: STRING_32) + element_value (a_session_id: STRING_32; an_id: STRING_32; a_name: STRING_32) : detachable STRING_32 -- GET /session/:sessionId/element/:id/attribute/:name -- Get the value of an element's attribute. -- URL Parameters: @@ -1278,7 +1355,7 @@ feature -- Commands do end - elements_equals (a_session_id: STRING_32; an_id: STRING_32; an_other: STRING_32) + elements_equals (a_session_id: STRING_32; an_id: STRING_32; an_other: STRING_32) : BOOLEAN -- GET /session/:sessionId/element/:id/equals/:other -- Test if two element IDs refer to the same DOM element. -- URL Parameters: diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 68af3b22..ae20ffc6 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -293,15 +293,75 @@ feature end + cmd_session_element_click_tmpl : STRING ="session/$sessionId/element/$id/click" + + cmd_session_element_click (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_submit_tmpl : STRING ="session/$sessionId/element/$id/submit" + + cmd_session_element_submit (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_submit_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + + cmd_session_element_text_tmpl : STRING ="session/$sessionId/element/$id/text" + + cmd_session_element_text (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_text_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_event_tmpl : STRING ="session/$sessionId/element/$id/value" + + cmd_session_element_event (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_event_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_keys_tmpl : STRING ="session/$sessionId/keys" + + cmd_session_keys (sessionId: STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_keys_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_element_name_tmpl : STRING ="session/$sessionId/element/$id/name" + + cmd_session_element_name (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_clear_tmpl : STRING ="session/$sessionId/element/$id/clear" + + cmd_session_element_clear (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + ---POST /session/:sessionId/element/:id/elements Search for multiple elements on the page, starting from the identified element. ---POST /session/:sessionId/element/:id/click Click on an element. ---POST /session/:sessionId/element/:id/submit Submit a FORM element. ---GET /session/:sessionId/element/:id/text Returns the visible text for the element. ---POST /session/:sessionId/element/:id/value Send a sequence of key strokes to an element. ---POST /session/:sessionId/keys Send a sequence of key strokes to the active element. ---GET /session/:sessionId/element/:id/name Query for an element's tag name. ---POST /session/:sessionId/element/:id/clear Clear a TEXTAREA or text INPUT element's value. --GET /session/:sessionId/element/:id/selected Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. --GET /session/:sessionId/element/:id/enabled Determine if an element is currently enabled. --GET /session/:sessionId/element/:id/attribute/:name Get the value of an element's attribute. From c7e6fe38fbaebbfad6ab8bf7313eea18a43e94de Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 23 Apr 2013 09:09:57 -0300 Subject: [PATCH 09/36] Added more command from JSONWireProtol. --- library/test/selenium/src/command_executor.e | 92 +++++++++ .../src/protocol/se_json_wire_protocol.e | 187 +++++++++++------- .../protocol/se_json_wire_protocol_commands.e | 52 ++++- library/test/selenium/src/se_window.e | 8 +- 4 files changed, 267 insertions(+), 72 deletions(-) diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index c6362e5a..c27cc65b 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -859,6 +859,98 @@ feature -- Commands end end end + + is_enabled (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_enabled (a_session_id,id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + is_selected (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_selected (a_session_id,id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + element_value (a_session_id: STRING_32; id : STRING_32; name : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_attribute_name (a_session_id,id,name)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + element_equals (a_session_id: STRING_32; id : STRING_32; other : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_equals (a_session_id,id,other)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + is_displayed (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_displayed (a_session_id,id)) + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + Result := new_response (l_body) + end + end + end + + feature {NONE} -- Implementation execute_get (command_name: STRING_32): HTTP_CLIENT_RESPONSE diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index 621c0233..feab05ff 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -923,7 +923,7 @@ feature -- Commands -- NoSuchElement - If the element cannot be found. -- XPathLookupError - If using XPath and the input expression is invalid. require - has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + has_valid_strategy: (create {SE_BY}).is_valid_strategy (strategy) local resp: SE_RESPONSE do @@ -963,7 +963,7 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- XPathLookupError - If using XPath and the input expression is invalid. require - has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + has_valid_strategy: (create {SE_BY}).is_valid_strategy (strategy) local resp: SE_RESPONSE index: INTEGER @@ -999,7 +999,7 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. local - resp : SE_RESPONSE + resp: SE_RESPONSE do if commnad_executor.is_available then resp := commnad_executor.element_active (a_session_id) @@ -1012,21 +1012,21 @@ feature -- Commands end end --- element_id (a_session_id: STRING_32; ) --- -- GET /session/:sessionId/element/:id --- -- Describe the identified element. --- -- Note: This command is reserved for future use; its return type is currently undefined. + -- element_id (a_session_id: STRING_32; ) + -- -- GET /session/:sessionId/element/:id + -- -- Describe the identified element. + -- -- Note: This command is reserved for future use; its return type is currently undefined. --- -- URL Parameters: --- -- :sessionId - ID of the session to route the command to. --- -- :id - ID of the element to route the command to. --- -- Potential Errors: --- -- NoSuchWindow - If the currently selected window has been closed. --- -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. --- do --- end + -- -- URL Parameters: + -- -- :sessionId - ID of the session to route the command to. + -- -- :id - ID of the element to route the command to. + -- -- Potential Errors: + -- -- NoSuchWindow - If the currently selected window has been closed. + -- -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + -- do + -- end - search_element_id_element (a_session_id: STRING_32; an_id: STRING_32; strategy : STRING_32) : detachable WEB_ELEMENT + search_element_id_element (a_session_id: STRING_32; an_id: STRING_32; strategy: STRING_32): detachable WEB_ELEMENT -- POST /session/:sessionId/element/:id/element -- Search for an element on the page, starting from the identified element. -- The located element will be returned as a WebElement JSON object. @@ -1057,12 +1057,12 @@ feature -- Commands -- NoSuchElement - If the element cannot be found. -- XPathLookupError - If using XPath and the input expression is invalid. require - has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + has_valid_strategy: (create {SE_BY}).is_valid_strategy (strategy) local resp: SE_RESPONSE do if commnad_executor.is_available then - resp := commnad_executor.search_element_id_element (a_session_id,an_id,strategy) + resp := commnad_executor.search_element_id_element (a_session_id, an_id, strategy) check_response (resp) if not has_error then if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then @@ -1072,8 +1072,7 @@ feature -- Commands end end - - search_elements_id (a_session_id: STRING_32; an_id: STRING_32; strategy : STRING_32) : detachable LIST[WEB_ELEMENT] + search_elements_id (a_session_id: STRING_32; an_id: STRING_32; strategy: STRING_32): detachable LIST [WEB_ELEMENT] -- POST /session/:sessionId/element/:id/elements -- Search for multiple elements on the page, starting from the identified element. -- The located elements will be returned as a WebElement JSON objects. @@ -1103,15 +1102,15 @@ feature -- Commands -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- XPathLookupError - If using XPath and the input expression is invalid. require - has_valid_strategy : (create {SE_BY}).is_valid_strategy (strategy) + has_valid_strategy: (create {SE_BY}).is_valid_strategy (strategy) local - resp : SE_RESPONSE - index : INTEGER + resp: SE_RESPONSE + index: INTEGER do if commnad_executor.is_available then - resp := commnad_executor.search_element_id_elements (a_session_id,an_id,strategy) + resp := commnad_executor.search_element_id_elements (a_session_id, an_id, strategy) check_response (resp) - if not has_error then + if not has_error then if attached resp.value as l_value and then attached {JSON_ARRAY} string_to_json (l_value) as l_json_array then create {ARRAYED_LIST [WEB_ELEMENT]} Result.make (10) from @@ -1127,7 +1126,6 @@ feature -- Commands end end end - end element_click (a_session_id: STRING_32; an_id: STRING_32) @@ -1141,12 +1139,12 @@ feature -- Commands -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) local - resp: SE_RESPONSE + resp: SE_RESPONSE do - if commnad_executor.is_available then - resp := commnad_executor.element_click (a_session_id,an_id) - check_response (resp) - end + if commnad_executor.is_available then + resp := commnad_executor.element_click (a_session_id, an_id) + check_response (resp) + end end element_submit (a_session_id: STRING_32; an_id: STRING_32) @@ -1159,15 +1157,15 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. local - resp : SE_RESPONSE + resp: SE_RESPONSE do if commnad_executor.is_available then - resp := commnad_executor.element_submit (a_session_id,an_id) + resp := commnad_executor.element_submit (a_session_id, an_id) check_response (resp) end end - element_text (a_session_id: STRING_32; an_id: STRING_32) : detachable STRING_32 + element_text (a_session_id: STRING_32; an_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/element/:id/text -- Returns the visible text for the element. -- URL Parameters: @@ -1190,7 +1188,7 @@ feature -- Commands end end - send_event (a_session_id: STRING_32; an_id: STRING_32; events : ARRAY[STRING_32]) + send_event (a_session_id: STRING_32; an_id: STRING_32; events: ARRAY [STRING_32]) -- POST /session/:sessionId/element/:id/value -- Send a sequence of key strokes to an element. -- Any UTF-8 character may be specified, however, if the server does not support native key events, @@ -1227,23 +1225,23 @@ feature -- Commands -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. -- ElementNotVisible - If the referenced element is not visible on the page (either is hidden by CSS, has 0-width, or has 0-height) - local - resp: SE_RESPONSE - l_json : STRING_32 - do - l_json := "[ - {"value":$array} - ]" - if commnad_executor.is_available then - if attached json.value (create {ARRAYED_LIST[STRING_32]}.make_from_array(events)) as l_array then - l_json.replace_substring_all ("$array", l_array.representation) - resp := commnad_executor.send_events (a_session_id, an_id, l_json) - check_response (resp) - end + local + resp: SE_RESPONSE + l_json: STRING_32 + do + l_json := "[ + {"value":$array} + ]" + if commnad_executor.is_available then + if attached json.value (create {ARRAYED_LIST [STRING_32]}.make_from_array (events)) as l_array then + l_json.replace_substring_all ("$array", l_array.representation) + resp := commnad_executor.send_events (a_session_id, an_id, l_json) + check_response (resp) end end + end - send_key_strokes (a_session_id: STRING_32 ; keys : ARRAY[STRING_32]) + send_key_strokes (a_session_id: STRING_32; keys: ARRAY [STRING_32]) -- POST /session/:sessionId/keys -- Send a sequence of key strokes to the active element. This command is similar to the send keys command in every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. -- URL Parameters: @@ -1253,22 +1251,22 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. local - resp: SE_RESPONSE - l_json : STRING_32 - do - l_json := "[ - {"value":$array} - ]" - if commnad_executor.is_available then - if attached json.value (create {ARRAYED_LIST[STRING_32]}.make_from_array(keys)) as l_array then - l_json.replace_substring_all ("$array", l_array.representation) - resp := commnad_executor.send_key_strokes (a_session_id, l_json) - check_response (resp) - end + resp: SE_RESPONSE + l_json: STRING_32 + do + l_json := "[ + {"value":$array} + ]" + if commnad_executor.is_available then + if attached json.value (create {ARRAYED_LIST [STRING_32]}.make_from_array (keys)) as l_array then + l_json.replace_substring_all ("$array", l_array.representation) + resp := commnad_executor.send_key_strokes (a_session_id, l_json) + check_response (resp) end end + end - query_by_tag_name (a_session_id: STRING_32; an_id: STRING_32) : detachable STRING_32 + query_by_tag_name (a_session_id: STRING_32; an_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/element/:id/name -- Query for an element's tag name. -- URL Parameters: @@ -1313,7 +1311,7 @@ feature -- Commands end end - is_selected (a_session_id: STRING_32; an_id: STRING_32) : BOOLEAN + is_selected (a_session_id: STRING_32; an_id: STRING_32): BOOLEAN -- GET /session/:sessionId/element/:id/selected -- Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. -- URL Parameters: @@ -1324,10 +1322,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.is_selected (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached {JSON_BOOLEAN} resp.value as l_value then + Result := (l_value.item) + end + end + end end - is_enabled (a_session_id: STRING_32; an_id: STRING_32) : BOOLEAN + is_enabled (a_session_id: STRING_32; an_id: STRING_32): BOOLEAN -- GET /session/:sessionId/element/:id/enabled -- Determine if an element is currently enabled. -- URL Parameters: @@ -1338,10 +1347,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.is_enabled (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached {JSON_BOOLEAN} resp.value as l_value then + Result := (l_value.item) + end + end + end end - element_value (a_session_id: STRING_32; an_id: STRING_32; a_name: STRING_32) : detachable STRING_32 + element_value (a_session_id: STRING_32; an_id: STRING_32; a_name: STRING_32): detachable STRING_32 -- GET /session/:sessionId/element/:id/attribute/:name -- Get the value of an element's attribute. -- URL Parameters: @@ -1352,10 +1372,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_value (a_session_id, an_id, a_name) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - elements_equals (a_session_id: STRING_32; an_id: STRING_32; an_other: STRING_32) : BOOLEAN + elements_equals (a_session_id: STRING_32; an_id: STRING_32; an_other: STRING_32): BOOLEAN -- GET /session/:sessionId/element/:id/equals/:other -- Test if two element IDs refer to the same DOM element. -- URL Parameters: @@ -1367,10 +1398,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If either the element refered to by :id or :other is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_equals (a_session_id, an_id, an_other) + check_response (resp) + if not has_error then + if attached {JSON_BOOLEAN} resp.value as l_value then + Result := (l_value.item) + end + end + end end - is_displayed (a_session_id: STRING_32; an_id: STRING_32) + is_displayed (a_session_id: STRING_32; an_id: STRING_32): BOOLEAN -- GET /session/:sessionId/element/:id/displayed -- Determine if an element is currently displayed. -- URL Parameters: @@ -1381,7 +1423,18 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.is_displayed (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached {JSON_BOOLEAN} resp.value as l_value then + Result := (l_value.item) + end + end + end end element_location (a_session_id: STRING_32; an_id: STRING_32) diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index ae20ffc6..a9c3fdcd 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -360,12 +360,56 @@ feature end + cmd_session_element_selected_tmpl : STRING ="session/$sessionId/element/$id/selected" + + cmd_session_element_selected (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_selected_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_enabled_tmpl : STRING ="session/$sessionId/element/$id/enabled" + + cmd_session_element_enabled (sessionId: STRING_32; id : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_enabled_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_attribute_name_tmpl : STRING ="session/$sessionId/element/$id/attribute/$name" + + cmd_session_element_attribute_name (sessionId: STRING_32; id : STRING_32; name : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_attribute_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$name", name) + end + + cmd_session_element_equals_tmpl : STRING ="session/$sessionId/element/$id/equals/$other" + + cmd_session_element_equals (sessionId: STRING_32; id : STRING_32; other : STRING_32 ): STRING_32 + do + create Result.make_from_string (cmd_session_element_equals_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$other", other) + end + + cmd_session_element_displayed_tmpl : STRING ="session/$sessionId/element/$id/displayed" + + cmd_session_element_displayed (sessionId: STRING_32; id : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_displayed_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end ---GET /session/:sessionId/element/:id/selected Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. ---GET /session/:sessionId/element/:id/enabled Determine if an element is currently enabled. ---GET /session/:sessionId/element/:id/attribute/:name Get the value of an element's attribute. ---GET /session/:sessionId/element/:id/equals/:other Test if two element IDs refer to the same DOM element. --GET /session/:sessionId/element/:id/displayed Determine if an element is currently displayed. --GET /session/:sessionId/element/:id/location Determine an element's location on the page. --GET /session/:sessionId/element/:id/location_in_view Determine an element's location on the screen once it has been scrolled into view. diff --git a/library/test/selenium/src/se_window.e b/library/test/selenium/src/se_window.e index 91c75151..49ea5477 100644 --- a/library/test/selenium/src/se_window.e +++ b/library/test/selenium/src/se_window.e @@ -19,15 +19,21 @@ feature -- Initialization end feature -- Access - --width: number, height: number} The size of the window. + --{ width: number, height: number} The size of the window. width : NATURAL_32 height : NATURAL_32 + -- The width and height of the element, in pixels. + x,y : INTEGER_32 + -- The X and Y coordinates for the element. feature -- Change Element set_width (a_width : NATURAL_32) + --Set width to `a_width' do width := a_width + ensure + width_set : width = a_width end set_height (a_height : NATURAL_32) From 4f79bf2addd6511490582b6a426e4b2415c22fdd Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 24 Apr 2013 11:33:39 -0300 Subject: [PATCH 10/36] Implemented more commands from REST API JSONWireProtocol Refactor COMMAND_EXECUTOR. --- library/test/selenium/src/command_executor.e | 511 +++++------------- .../test/selenium/src/helpers/http_methods.e | 19 + .../src/protocol/se_json_wire_protocol.e | 114 +++- .../protocol/se_json_wire_protocol_commands.e | 63 ++- library/test/selenium/src/se_key_stroke.e | 129 +++++ .../test/selenium/src/se_screen_orientation.e | 12 + 6 files changed, 468 insertions(+), 380 deletions(-) create mode 100644 library/test/selenium/src/helpers/http_methods.e create mode 100644 library/test/selenium/src/se_key_stroke.e create mode 100644 library/test/selenium/src/se_screen_orientation.e diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index c27cc65b..5eabad9b 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -51,9 +51,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_status) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response ("", resp) end new_session (capabilities: STRING_32): SE_RESPONSE @@ -64,17 +62,14 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_new_session, capabilities) + -- TODO move this scenario to feature new_response if not (resp.status >= 400) then if attached resp.header ("Location") as l_location then resp := http_new_session (l_location).get ("", context_executor) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response ("", resp) end else - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response ("", resp) end end @@ -86,9 +81,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_sessions) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response ("", resp) end retrieve_session (session_id: STRING_32): SE_RESPONSE @@ -99,9 +92,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_by_id (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end delete_session (session_id: STRING_32): SE_RESPONSE @@ -112,14 +103,7 @@ feature -- Commands do create Result.make_empty resp := execute_delete (cmd_session_by_id ( session_id )) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (session_id, resp) end set_session_timeouts (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE @@ -130,14 +114,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_timeouts (a_session_id), a_data_timeout) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end set_session_timeouts_async_script (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE @@ -148,15 +125,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_timeouts_async_script (a_session_id), a_data_timeout) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end - + Result := new_response (a_session_id, resp) end set_session_timeouts_implicit_wait (a_session_id: STRING_32; a_data_timeout: STRING_32): SE_RESPONSE @@ -167,15 +136,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_timeouts_implicit_wait (a_session_id), a_data_timeout) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end - + Result := new_response (a_session_id, resp) end retrieve_window_handle (session_id: STRING_32): SE_RESPONSE @@ -186,9 +147,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_window_handle (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end retrieve_window_handles (session_id: STRING_32): SE_RESPONSE @@ -199,9 +158,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_window_handles (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end retrieve_url (session_id: STRING_32): SE_RESPONSE @@ -212,9 +169,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_url (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end navigate_to_url (a_session_id: STRING_32; a_url: STRING_32): SE_RESPONSE @@ -225,14 +180,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_url (a_session_id), a_url) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end forward (a_session_id: STRING_32): SE_RESPONSE @@ -243,14 +191,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_forward (a_session_id), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end back (a_session_id: STRING_32): SE_RESPONSE @@ -261,14 +202,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_back (a_session_id), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end refresh (a_session_id: STRING_32): SE_RESPONSE @@ -279,14 +213,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_refresh (a_session_id), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end execute @@ -315,9 +242,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_screenshot (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end ime_available_engines (session_id: STRING_32): SE_RESPONSE @@ -328,9 +253,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_ime_available (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end ime_active_engine (session_id: STRING_32): SE_RESPONSE @@ -341,9 +264,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_ime_active_engine (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end ime_activated (session_id: STRING_32): SE_RESPONSE @@ -354,9 +275,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_ime_activated (session_id)) - if attached resp.body as l_body then - Result := new_response (l_body) - end + Result := new_response (session_id, resp) end ime_deactivate (a_session_id: STRING_32): SE_RESPONSE @@ -367,14 +286,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_ime_deactivate (a_session_id), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end ime_activate (a_session_id: STRING_32; an_engine: STRING_32): SE_RESPONSE @@ -385,15 +297,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_ime_activate (a_session_id), an_engine) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end - + Result := new_response (a_session_id, resp) end change_focus_window (a_session_id: STRING_32; a_data: STRING_32): SE_RESPONSE @@ -404,14 +308,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_window (a_session_id), a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -423,15 +320,7 @@ feature -- Commands do create Result.make_empty resp := execute_delete (cmd_session_window (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end - + Result := new_response (a_session_id, resp) end change_size_window (a_session_id: STRING_32; a_window_handle : STRING_32;a_data: STRING_32): SE_RESPONSE @@ -442,14 +331,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_window_size (a_session_id,a_window_handle), a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end size_window (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE @@ -460,14 +342,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end change_window_position (a_session_id: STRING_32; a_window_handle : STRING_32;a_data: STRING_32): SE_RESPONSE @@ -478,14 +353,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_window_position (a_session_id,a_window_handle), a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end window_position (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE @@ -496,14 +364,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end window_maximize (a_session_id: STRING_32; a_window_handle : STRING_32) : SE_RESPONSE @@ -514,14 +375,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_window_maximize (a_session_id,a_window_handle), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -533,14 +387,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_cookie (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end set_cookie (a_session_id: STRING_32; a_data : STRING_32) : SE_RESPONSE @@ -551,14 +398,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_cookie (a_session_id),a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end delete_cookies (a_session_id: STRING_32) : SE_RESPONSE @@ -569,14 +409,7 @@ feature -- Commands do create Result.make_empty resp := execute_delete (cmd_session_cookie (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end delete_cookie_by_name (a_session_id: STRING_32; a_name : STRING_32) : SE_RESPONSE @@ -587,14 +420,7 @@ feature -- Commands do create Result.make_empty resp := execute_delete (cmd_session_cookie_delete (a_session_id,a_name)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end page_source (a_session_id: STRING_32) : SE_RESPONSE @@ -605,14 +431,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_source (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -624,14 +443,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_title (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -643,14 +455,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element (a_session_id),a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -662,14 +467,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_id_element (a_session_id,id),a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -681,14 +479,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_elements (a_session_id),a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -701,14 +492,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_active (a_session_id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -720,14 +504,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_id_elements (a_session_id,id),a_data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end element_click (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE @@ -738,14 +515,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_click (a_session_id,id),Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -757,14 +527,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_submit (a_session_id,id),Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -776,14 +539,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_text (a_session_id,id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end send_events (a_session_id: STRING_32; id : STRING_32; data : STRING_32) : SE_RESPONSE @@ -794,14 +550,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_event (a_session_id,id),data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -813,14 +562,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_keys (a_session_id),data) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end query_by_tag_name (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE @@ -831,14 +573,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_name (a_session_id,id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end @@ -850,14 +585,7 @@ feature -- Commands do create Result.make_empty resp := execute_post (cmd_session_element_clear (a_session_id,id), Void) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end is_enabled (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE @@ -868,14 +596,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_enabled (a_session_id,id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end is_selected (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE @@ -886,14 +607,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_selected (a_session_id,id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end element_value (a_session_id: STRING_32; id : STRING_32; name : STRING_32) : SE_RESPONSE @@ -904,14 +618,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_attribute_name (a_session_id,id,name)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end element_equals (a_session_id: STRING_32; id : STRING_32; other : STRING_32) : SE_RESPONSE @@ -922,14 +629,7 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_equals (a_session_id,id,other)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end is_displayed (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE @@ -940,16 +640,90 @@ feature -- Commands do create Result.make_empty resp := execute_get (cmd_session_element_displayed (a_session_id,id)) - if resp.status = 204 then - Result.set_status (0) - Result.set_session_id (a_session_id) - else - if attached resp.body as l_body then - Result := new_response (l_body) - end - end + Result := new_response (a_session_id, resp) end + element_location (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_location (a_session_id,id)) + Result := new_response (a_session_id, resp) + end + + location_in_view (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_location_in_view (a_session_id,id)) + Result := new_response (a_session_id, resp) + end + + + element_size (a_session_id: STRING_32; id : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_size (a_session_id,id)) + Result := new_response (a_session_id, resp) + end + + element_css_value (a_session_id: STRING_32; id : STRING_32; property_name : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_element_css_value (a_session_id,id, property_name)) + Result := new_response (a_session_id, resp) + end + + + retrieve_browser_orientation (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_browser_orientation (a_session_id)) + Result := new_response (a_session_id, resp) + end + + + set_browser_orientation (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_post (cmd_session_browser_orientation (a_session_id), data) + Result := new_response (a_session_id, resp) + end + + retrieve_alert_text (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + create Result.make_empty + resp := execute_get (cmd_session_alert_text (a_session_id)) + Result := new_response (a_session_id, resp) + end + + feature {NONE} -- Implementation @@ -968,13 +742,22 @@ feature {NONE} -- Implementation Result := http_session.delete (command_name, context_executor) end - new_response (a_message: STRING_32): SE_RESPONSE + new_response (a_session_id : STRING_32; resp: HTTP_CLIENT_RESPONSE): SE_RESPONSE + -- Create a new Selenium Response based on `resp' HTTP_RESPONSE + -- todo improve it!!! do create Result.make_empty - if attached json_to_se_response(a_message) as l_response then - Result := l_response + if resp.status = 204 then + Result.set_status (0) + Result.set_session_id (a_session_id) + else + if attached resp.body as l_body then + if attached json_to_se_response(l_body) as l_response then + Result := l_response + end + Result.set_json_response (l_body) + end end - Result.set_json_response (a_message) end context_executor: HTTP_CLIENT_REQUEST_CONTEXT diff --git a/library/test/selenium/src/helpers/http_methods.e b/library/test/selenium/src/helpers/http_methods.e new file mode 100644 index 00000000..b0491940 --- /dev/null +++ b/library/test/selenium/src/helpers/http_methods.e @@ -0,0 +1,19 @@ +note + description: "Summary description for {HTTP_METHODS}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + HTTP_METHODS + +feature -- Method Names + OPTIONS : STRING_32 = "OPTIONS" + GET : STRING_32 = "GET" + HEAD : STRING_32 = "HEAD" + POST : STRING_32 = "POST" + PUT : STRING_32 = "PUT" + DELETE : STRING_32 = "DELETE" + TRACE : STRING_32 = "TRACE" + CONNECT : STRING_32 = "CONNECT" +end diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index feab05ff..4c92864c 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -1437,7 +1437,7 @@ feature -- Commands end end - element_location (a_session_id: STRING_32; an_id: STRING_32) + element_location (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW -- GET /session/:sessionId/element/:id/location -- Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. -- The element's coordinates are returned as a JSON object with x and y properties. @@ -1449,10 +1449,27 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + create Result + if commnad_executor.is_available then + resp := commnad_executor.element_location (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as l_json_object then + if attached l_json_object.item ("x") as l_x then + Result.set_x (l_x.representation.to_integer_32) + end + if attached l_json_object.item ("y") as l_y then + Result.set_y (l_y.representation.to_integer_32) + end + end + end + end end - is_location_in_view (a_session_id: STRING_32; an_id: STRING_32) + location_in_view (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW -- GET /session/:sessionId/element/:id/location_in_view -- Determine an element's location on the screen once it has been scrolled into view. -- Note: This is considered an internal command and should only be used to determine an element's @@ -1465,10 +1482,27 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + create Result + if commnad_executor.is_available then + resp := commnad_executor.location_in_view (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as l_json_object then + if attached l_json_object.item ("x") as l_x then + Result.set_x (l_x.representation.to_integer_32) + end + if attached l_json_object.item ("y") as l_y then + Result.set_y (l_y.representation.to_integer_32) + end + end + end + end end - element_size (a_session_id: STRING_32; an_id: STRING_32) + element_size (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW -- GET /session/:sessionId/element/:id/size -- Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. -- URL Parameters: @@ -1479,10 +1513,27 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + create Result + if commnad_executor.is_available then + resp := commnad_executor.element_size (a_session_id, an_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as l_json_object then + if attached l_json_object.item ("width") as l_width then + Result.set_width (l_width.representation.to_natural) + end + if attached l_json_object.item ("height") as l_height then + Result.set_height (l_height.representation.to_natural) + end + end + end + end end - element_css_value (a_session_id: STRING_32; an_id: STRING_32; a_property_name: STRING_32) + element_css_value (a_session_id: STRING_32; an_id: STRING_32; a_property_name: STRING_32): detachable STRING_32 -- GET /session/:sessionId/element/:id/css/:propertyName -- Query the value of an element's computed CSS property. The CSS property to query should be specified using the CSS property name, not the JavaScript property name (e.g. background-color instead of backgroundColor). -- URL Parameters: @@ -1493,10 +1544,21 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- StaleElementReference - If the element referenced by :id is no longer attached to the page's DOM. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.element_css_value (a_session_id, an_id, a_property_name) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end - retrieve_browser_orientation (a_session_id: STRING_32) + retrieve_browser_orientation (a_session_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/orientation -- Get the current browser orientation. The server should return a valid orientation value as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. -- URL Parameters: @@ -1505,10 +1567,24 @@ feature -- Commands -- {string} The current browser orientation corresponding to a value defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.retrieve_browser_orientation (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end + --ensure + -- if not has_error, has_valid_orientation (LANDSCAPE|PORTRAIT) + -- not_has_error : not has_error implies has_valid_orientation () end - set_browser_orientation (a_session_id: STRING_32) + set_browser_orientation (a_session_id: STRING_32; orientation: STRING_32) -- POST /session/:sessionId/orientation -- Set the browser orientation. The orientation should be specified as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. -- URL Parameters: @@ -1517,10 +1593,23 @@ feature -- Commands -- orientation - {string} The new browser orientation as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}. -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. + require + valid_orientation: orientation.is_case_insensitive_equal ("LANDSCAPE") or else orientation.is_case_insensitive_equal ("PORTRAIT") + local + resp: SE_RESPONSE + l_json: STRING_32 do + l_json := "[ + {"orientation" : "$orientation"} + ]" + if commnad_executor.is_available then + l_json.replace_substring_all ("$orientation", orientation) + resp := commnad_executor.set_browser_orientation (a_session_id, l_json) + check_response (resp) + end end - retrieve_alert_text (a_session_id: STRING_32) + retrieve_alert_text (a_session_id: STRING_32): detachable STRING_32 -- GET /session/:sessionId/alert_text -- Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. -- URL Parameters: @@ -1529,7 +1618,18 @@ feature -- Commands -- {string} The text of the currently displayed alert. -- Potential Errors: -- NoAlertPresent - If there is no alert displayed. + local + resp: SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.retrieve_alert_text (a_session_id) + check_response (resp) + if not has_error then + if attached resp.value as l_value then + Result := l_value + end + end + end end send_alert_text (a_session_id: STRING_32) diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index a9c3fdcd..82cfa24a 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -409,16 +409,61 @@ feature Result.replace_substring_all ("$id", id) end + cmd_session_element_location_tmpl : STRING ="session/$sessionId/element/$id/location" + + cmd_session_element_location (sessionId: STRING_32; id : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_location_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_location_in_view_tmpl : STRING ="session/$sessionId/element/$id/location_in_view" + + cmd_session_element_location_in_view (sessionId: STRING_32; id : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_location_in_view_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + + cmd_session_element_size_tmpl : STRING ="session/$sessionId/element/$id/size" + + cmd_session_element_size (sessionId: STRING_32; id : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_size_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_css_value_tmpl : STRING ="session/$sessionId/element/$id/css/$propertyName" + + cmd_session_element_css_value (sessionId: STRING_32; id : STRING_32; property_name : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_css_value_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$propertyName", property_name) + end + + cmd_session_browser_orientation_tmpl : STRING ="session/$sessionId/orientation" + + cmd_session_browser_orientation (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_browser_orientation_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_alert_text_tmpl : STRING ="session/$sessionId/alert_text" + + cmd_session_alert_text (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_alert_text_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + ---GET /session/:sessionId/element/:id/displayed Determine if an element is currently displayed. ---GET /session/:sessionId/element/:id/location Determine an element's location on the page. ---GET /session/:sessionId/element/:id/location_in_view Determine an element's location on the screen once it has been scrolled into view. ---GET /session/:sessionId/element/:id/size Determine an element's size in pixels. ---GET /session/:sessionId/element/:id/css/:propertyName Query the value of an element's computed CSS property. ---GET /session/:sessionId/orientation Get the current browser orientation. ---POST /session/:sessionId/orientation Set the browser orientation. ---GET /session/:sessionId/alert_text Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. ---POST /session/:sessionId/alert_text Sends keystrokes to a JavaScript prompt() dialog. --POST /session/:sessionId/accept_alert Accepts the currently displayed alert dialog. --POST /session/:sessionId/dismiss_alert Dismisses the currently displayed alert dialog. --POST /session/:sessionId/moveto Move the mouse by an offset of the specificed element. diff --git a/library/test/selenium/src/se_key_stroke.e b/library/test/selenium/src/se_key_stroke.e new file mode 100644 index 00000000..c8b18370 --- /dev/null +++ b/library/test/selenium/src/se_key_stroke.e @@ -0,0 +1,129 @@ +note + description: "Summary description for {SE_KEY_STROKE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_KEY_STROKE + +feature -- Access + + Null_key: STRING_32 = "\uE000" + + Cancel_key: STRING_32 = "\uE001" + + Help_key: STRING_32 = "\uE002" + + Backspace_key: STRING_32 = "\uE003" + + Tab_key: STRING_32 = "\uE004" + + Clear_key: STRING_32 = "\uE005" + + Return_key: STRING_32 = "\uE006" + + Enter_key: STRING_32 = "\uE007" + + Shift_key: STRING_32 = "\uE008" + + Control_key: STRING_32 = "\uE009" + + Alt_key: STRING_32 = "\uE00A" + + Pause_key: STRING_32 = "\uE00B" + + Escape_key: STRING_32 = "\uE00C" + + Space_key: STRING_32 = "\uE00D" + + PageUp_key: STRING_32 = "\uE00E" + + PageDown_key: STRING_32 = "\uE00F" + + End_key: STRING_32 = "\uE010" + + Home_key: STRING_32 = "\uE011" + + LeftArrow_key: STRING_32 = "\uE012" + + UpArrow_key: STRING_32 = "\uE013" + + RightArrow_key: STRING_32 = "\uE014" + + DownArrow_key: STRING_32 = "\uE015" + + Insert_key: STRING_32 = "\uE016" + + Delete_key: STRING_32 = "\uE017" + + Semicolon_key: STRING_32 = "\uE018" + + Equals_key: STRING_32 = "\uE019" + + Numpad0_key: STRING_32 = "\uE01A" + + Numpad1_key: STRING_32 = "\uE01B" + + Numpad2_key: STRING_32 = "\uE01C" + + Numpad3_key: STRING_32 = "\uE01D" + + Numpad4_key: STRING_32 = "\uE01E" + + Numpad5_key: STRING_32 = "\uE01F" + + Numpad6_key: STRING_32 = "\uE020" + + Numpad7_key: STRING_32 = "\uE021" + + Numpad8_key: STRING_32 = "\uE022" + + Numpad9_key: STRING_32 = "\uE023" + + Multiply_key: STRING_32 = "\uE024" + + Add_key: STRING_32 = "\uE025" + + Separator_key: STRING_32 = "\uE026" + + Subtract_key: STRING_32 = "\uE027" + + Decimal_key: STRING_32 = "\uE028" + + Divide_key: STRING_32 = "\uE029" + + F1_key: STRING_32 = "\uE031" + + F2_key: STRING_32 = "\uE032" + + F3_key: STRING_32 = "\uE033" + + F4_key: STRING_32 = "\uE034" + + F5_key: STRING_32 = "\uE035" + + F6_key: STRING_32 = "\uE036" + + F7_key: STRING_32 = "\uE037" + + F8_key: STRING_32 = "\uE038" + + F9_key: STRING_32 = "\uE039" + + F10_key: STRING_32 = "\uE03A" + + F11_key: STRING_32 = "\uE03B" + + F12_key: STRING_32 = "\uE03C" + + Command_key: STRING_32 = "\uE03D" + + Meta_key: STRING_32 = "\uE03D" + + keys: ARRAY [STRING_32] + once + Result := <> + end + +end diff --git a/library/test/selenium/src/se_screen_orientation.e b/library/test/selenium/src/se_screen_orientation.e new file mode 100644 index 00000000..ce84afdd --- /dev/null +++ b/library/test/selenium/src/se_screen_orientation.e @@ -0,0 +1,12 @@ +note + description: "Summary description for {SE_SCREEN_ORIENTATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_SCREEN_ORIENTATION + + +-- {LANDSCAPE|PORTRAIT} +end From 9180667ac4efb73f71837ac81a57c3f7880c7e0d Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 24 Apr 2013 14:39:08 -0300 Subject: [PATCH 11/36] Completed low level methods, clean code. --- library/test/selenium/src/command_executor.e | 409 +++++++- .../protocol/se_json_wire_protocol_commands.e | 985 ++++++++++-------- 2 files changed, 916 insertions(+), 478 deletions(-) diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/command_executor.e index 5eabad9b..5c41923c 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/command_executor.e @@ -49,7 +49,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_status) Result := new_response ("", resp) end @@ -79,7 +78,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_sessions) Result := new_response ("", resp) end @@ -90,7 +88,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_by_id (session_id)) Result := new_response (session_id, resp) end @@ -101,7 +98,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_delete (cmd_session_by_id ( session_id )) Result := new_response (session_id, resp) end @@ -112,7 +108,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_timeouts (a_session_id), a_data_timeout) Result := new_response (a_session_id, resp) end @@ -123,7 +118,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_timeouts_async_script (a_session_id), a_data_timeout) Result := new_response (a_session_id, resp) end @@ -134,7 +128,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_timeouts_implicit_wait (a_session_id), a_data_timeout) Result := new_response (a_session_id, resp) end @@ -145,7 +138,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_window_handle (session_id)) Result := new_response (session_id, resp) end @@ -156,7 +148,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_window_handles (session_id)) Result := new_response (session_id, resp) end @@ -167,7 +158,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_url (session_id)) Result := new_response (session_id, resp) end @@ -178,7 +168,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_url (a_session_id), a_url) Result := new_response (a_session_id, resp) end @@ -189,7 +178,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_forward (a_session_id), Void) Result := new_response (a_session_id, resp) end @@ -200,7 +188,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_back (a_session_id), Void) Result := new_response (a_session_id, resp) end @@ -211,7 +198,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_refresh (a_session_id), Void) Result := new_response (a_session_id, resp) end @@ -240,7 +226,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_screenshot (session_id)) Result := new_response (session_id, resp) end @@ -251,7 +236,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_ime_available (session_id)) Result := new_response (session_id, resp) end @@ -262,7 +246,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_ime_active_engine (session_id)) Result := new_response (session_id, resp) end @@ -273,7 +256,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_ime_activated (session_id)) Result := new_response (session_id, resp) end @@ -284,7 +266,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_ime_deactivate (a_session_id), Void) Result := new_response (a_session_id, resp) end @@ -295,7 +276,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_ime_activate (a_session_id), an_engine) Result := new_response (a_session_id, resp) end @@ -306,7 +286,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_window (a_session_id), a_data) Result := new_response (a_session_id, resp) end @@ -318,7 +297,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_delete (cmd_session_window (a_session_id)) Result := new_response (a_session_id, resp) end @@ -329,7 +307,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_window_size (a_session_id,a_window_handle), a_data) Result := new_response (a_session_id, resp) end @@ -340,7 +317,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) Result := new_response (a_session_id, resp) end @@ -351,7 +327,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_window_position (a_session_id,a_window_handle), a_data) Result := new_response (a_session_id, resp) end @@ -362,7 +337,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_window_size (a_session_id,a_window_handle)) Result := new_response (a_session_id, resp) end @@ -373,7 +347,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_window_maximize (a_session_id,a_window_handle), Void) Result := new_response (a_session_id, resp) end @@ -385,7 +358,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_cookie (a_session_id)) Result := new_response (a_session_id, resp) end @@ -396,7 +368,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_cookie (a_session_id),a_data) Result := new_response (a_session_id, resp) end @@ -407,7 +378,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_delete (cmd_session_cookie (a_session_id)) Result := new_response (a_session_id, resp) end @@ -418,7 +388,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_delete (cmd_session_cookie_delete (a_session_id,a_name)) Result := new_response (a_session_id, resp) end @@ -429,7 +398,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_source (a_session_id)) Result := new_response (a_session_id, resp) end @@ -441,7 +409,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_title (a_session_id)) Result := new_response (a_session_id, resp) end @@ -453,7 +420,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element (a_session_id),a_data) Result := new_response (a_session_id, resp) end @@ -465,7 +431,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_id_element (a_session_id,id),a_data) Result := new_response (a_session_id, resp) end @@ -477,7 +442,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_elements (a_session_id),a_data) Result := new_response (a_session_id, resp) end @@ -490,7 +454,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_active (a_session_id)) Result := new_response (a_session_id, resp) end @@ -502,7 +465,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_id_elements (a_session_id,id),a_data) Result := new_response (a_session_id, resp) end @@ -513,7 +475,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_click (a_session_id,id),Void) Result := new_response (a_session_id, resp) end @@ -525,7 +486,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_submit (a_session_id,id),Void) Result := new_response (a_session_id, resp) end @@ -537,7 +497,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_text (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -548,7 +507,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_event (a_session_id,id),data) Result := new_response (a_session_id, resp) end @@ -560,7 +518,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_keys (a_session_id),data) Result := new_response (a_session_id, resp) end @@ -571,7 +528,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_name (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -583,7 +539,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_element_clear (a_session_id,id), Void) Result := new_response (a_session_id, resp) end @@ -594,7 +549,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_enabled (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -605,7 +559,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_selected (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -616,7 +569,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_attribute_name (a_session_id,id,name)) Result := new_response (a_session_id, resp) end @@ -627,7 +579,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_equals (a_session_id,id,other)) Result := new_response (a_session_id, resp) end @@ -638,7 +589,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_displayed (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -649,7 +599,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_location (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -660,7 +609,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_location_in_view (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -672,7 +620,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_size (a_session_id,id)) Result := new_response (a_session_id, resp) end @@ -683,7 +630,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_element_css_value (a_session_id,id, property_name)) Result := new_response (a_session_id, resp) end @@ -695,7 +641,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_browser_orientation (a_session_id)) Result := new_response (a_session_id, resp) end @@ -707,7 +652,6 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_post (cmd_session_browser_orientation (a_session_id), data) Result := new_response (a_session_id, resp) end @@ -718,12 +662,363 @@ feature -- Commands local resp: HTTP_CLIENT_RESPONSE do - create Result.make_empty resp := execute_get (cmd_session_alert_text (a_session_id)) Result := new_response (a_session_id, resp) end + send_alert_text (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_alert_text (a_session_id),data) + Result := new_response (a_session_id, resp) + end + accept_alert (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_accept_alert (a_session_id),Void) + Result := new_response (a_session_id, resp) + end + + dismiss_alert (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_dismiss_alert (a_session_id),Void) + Result := new_response (a_session_id, resp) + end + + move_to (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_move_to (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + + click (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_click (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + button_down (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_buttondown (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + button_up (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_buttonup (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + double_click (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_double_click (a_session_id),Void) + Result := new_response (a_session_id, resp) + end + + + touch_click (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_click (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + touch_down (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_down (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + touch_up (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_up (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + touch_move (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_move (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + start_touch_scroll (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_scroll (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + + touch_scroll (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + Result := start_touch_scroll (a_session_id, data) + end + + touch_double_click (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_double_click (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + + touch_long_click (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_long_click (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + start_touch_flick (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_touch_flick (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + + touch_flick (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + Result := start_touch_flick (a_session_id, data) + end + + + retrieve_geo_location (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_geo_location (a_session_id)) + Result := new_response (a_session_id, resp) + end + + set_geo_location (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_geo_location (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + retrieve_local_storage (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_local_storage (a_session_id)) + Result := new_response (a_session_id, resp) + end + + set_location_storage (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_local_storage (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + delete_local_storage (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_delete (cmd_session_local_storage (a_session_id)) + Result := new_response (a_session_id, resp) + end + + retrieve_storage_by_key (a_session_id: STRING_32; key : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_local_storage_key (a_session_id,key)) + Result := new_response (a_session_id, resp) + end + + delete_storage_by_key (a_session_id: STRING_32; key : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_delete (cmd_session_local_storage_key (a_session_id,key)) + Result := new_response (a_session_id, resp) + end + + local_storage_size (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_local_storage_size (a_session_id)) + Result := new_response (a_session_id, resp) + end + + session_storage_keys (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_storage (a_session_id)) + Result := new_response (a_session_id, resp) + end + + set_session_storage (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_storage (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + delete_session_storage (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_delete (cmd_session_storage (a_session_id)) + Result := new_response (a_session_id, resp) + end + + retrive_storage_item_by_key (a_session_id: STRING_32; key : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_storage_key (a_session_id,key)) + Result := new_response (a_session_id, resp) + end + + remove_storage_item_by_key (a_session_id: STRING_32; key : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_delete (cmd_session_storage_key (a_session_id,key)) + Result := new_response (a_session_id, resp) + end + + session_storage_size (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_storage_size (a_session_id)) + Result := new_response (a_session_id, resp) + end + + log (a_session_id: STRING_32; data : STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_log (a_session_id),data) + Result := new_response (a_session_id, resp) + end + + available_log_types (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_log_types (a_session_id)) + Result := new_response (a_session_id, resp) + end + + application_cache_status (a_session_id: STRING_32) : SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_get (cmd_session_application_cache (a_session_id)) + Result := new_response (a_session_id, resp) + end feature {NONE} -- Implementation diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 82cfa24a..4eba93dc 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -9,493 +9,636 @@ class feature - cmd_ping : STRING = "" + cmd_ping: STRING = "" --GET / expected a 200 ok - cmd_status : STRING = "status" + cmd_status: STRING = "status" --GET /status Query the server's current status. - cmd_new_session : STRING = "session" + cmd_new_session: STRING = "session" --POST /session Create a new session. - cmd_sessions : STRING = "sessions" + + cmd_sessions: STRING = "sessions" --GET /sessions Returns a list of the currently active sessions. - cmd_session_by_id_tmpl : STRING ="session/$id" + cmd_session_by_id_tmpl: STRING = "session/$id" - cmd_session_by_id (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_by_id_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_by_id (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_by_id_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_timeouts_tmpl: STRING_32 = "[ + session/$id/timeouts + ]" + cmd_session_timeouts (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_timeouts_tmpl : STRING_32 ="[ - session/$id/timeouts - ]" + cmd_session_timeouts_async_script_tmpl: STRING = "session/$id/timeouts/async_script" - cmd_session_timeouts (id: STRING_32):STRING_32 - do - create Result.make_from_string (cmd_session_timeouts_tmpl) - Result.replace_substring_all ("$id",id) - end + cmd_session_timeouts_async_script (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_async_script_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_timeouts_async_script_tmpl : STRING ="session/$id/timeouts/async_script" + cmd_session_timeouts_implicit_wait_tmpl: STRING = "session/$id/timeouts/implicit_wait" - cmd_session_timeouts_async_script (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_timeouts_async_script_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_timeouts_implicit_wait (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_timeouts_implicit_wait_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_timeouts_implicit_wait_tmpl : STRING ="session/$id/timeouts/implicit_wait" + cmd_session_window_handle_tmpl: STRING = "session/$id/window_handle" - cmd_session_timeouts_implicit_wait (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_timeouts_implicit_wait_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_window_handle (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_handle_tmpl) + Result.replace_substring_all ("$id", id) + end + cmd_session_window_handles_tmpl: STRING = "session/$id/window_handles" - cmd_session_window_handle_tmpl : STRING ="session/$id/window_handle" + cmd_session_window_handles (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_handles_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_window_handle (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_handle_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_url_tmpl: STRING = "session/$id/url" - cmd_session_window_handles_tmpl : STRING ="session/$id/window_handles" + cmd_session_url (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_url_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_window_handles (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_handles_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_forward_tmpl: STRING = "session/$id/forward" + + cmd_session_forward (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_forward_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_url_tmpl : STRING ="session/$id/url" + cmd_session_back_tmpl: STRING = "session/$id/back" + + cmd_session_back (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_back_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_url (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_url_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_refresh_tmpl: STRING = "session/$id/refresh" + + cmd_session_refresh (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_refresh_tmpl) + Result.replace_substring_all ("$id", id) + end + --POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. + --POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. + + cmd_session_screenshot_tmpl: STRING = "session/$id/screenshot" + cmd_session_screenshot (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_screenshot_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_available_engines_tmpl: STRING = "session/$id/ime/available_engines" - cmd_session_forward_tmpl : STRING ="session/$id/forward" + cmd_session_ime_available (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_available_engines_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_active_engine_tmpl: STRING = "session/$id/ime/active_engine" + + cmd_session_ime_active_engine (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_active_engine_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_ime_activated_tmpl: STRING = "session/$id/ime/activated" - cmd_session_forward (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_forward_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_ime_activated (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_activated_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_back_tmpl : STRING ="session/$id/back" + cmd_session_ime_deactivate_tmpl: STRING = "session/$id/ime/deactivate" - cmd_session_back (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_back_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_ime_deactivate (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_deactivate_tmpl) + Result.replace_substring_all ("$id", id) + end + cmd_session_ime_activate_tmpl: STRING = "session/$id/ime/activate" - cmd_session_refresh_tmpl : STRING ="session/$id/refresh" + cmd_session_ime_activate (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_ime_activate_tmpl) + Result.replace_substring_all ("$id", id) + end - cmd_session_refresh (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_refresh_tmpl) - Result.replace_substring_all ("$id", id) - end + --POST /session/:sessionId/frame Change focus to another frame on the page. + + cmd_session_window_tmpl: STRING = "session/$id/window" + + cmd_session_window (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_tmpl) + Result.replace_substring_all ("$id", id) + end + cmd_session_window_size_tmpl: STRING = "session/$id/window/$windowHandle/size" + + cmd_session_window_size (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_size_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end ---POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. ---POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. + cmd_session_window_position_tmpl: STRING = "session/$id/window/$windowHandle/position" + + cmd_session_window_position (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_position_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end + + cmd_session_window_maximize_tmpl: STRING = "session/$id/window/$windowHandle/maximize" + + cmd_session_window_maximize (id: STRING_32; window_handle: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_window_maximize_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$windowHandle", window_handle) + end + + cmd_session_cookie_tmpl: STRING = "session/$id/cookie" + + cmd_session_cookie (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_cookie_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_cookie_delte_tmpl: STRING = "session/$id/cookie/$name" + + cmd_session_cookie_delete (id: STRING_32; name: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_cookie_delte_tmpl) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$name", name) + end + + cmd_session_source_tmpl: STRING = "session/$id/source" + + cmd_session_source (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_source_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_title_tmpl: STRING = "session/$id/title" + + cmd_session_title (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_source_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_tmpl: STRING = "session/$id/element" + + cmd_session_element (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_elements_tmpl: STRING = "session/$id/elements" + + cmd_session_elements (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_elements_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_active_tmpl: STRING = "session/$id/element/active" + + cmd_session_element_active (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_active_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_id_tmpl: STRING = "session/$sessionId/element/$id" + + cmd_session_element_id (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + --GET /session/:sessionId/element/:id Describe the identified element. + + cmd_session_element_id_element_tmpl: STRING = "session/$sessionId/element/$id/element" + + cmd_session_element_id_element (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_element_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_id_elements_tmpl: STRING = "session/$sessionId/element/$id/elements" + + cmd_session_element_id_elements (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_id_elements_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_click_tmpl: STRING = "session/$sessionId/element/$id/click" + + cmd_session_element_click (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_submit_tmpl: STRING = "session/$sessionId/element/$id/submit" + + cmd_session_element_submit (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_submit_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_text_tmpl: STRING = "session/$sessionId/element/$id/text" + + cmd_session_element_text (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_text_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_event_tmpl: STRING = "session/$sessionId/element/$id/value" + + cmd_session_element_event (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_event_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_keys_tmpl: STRING = "session/$sessionId/keys" + + cmd_session_keys (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_keys_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_element_name_tmpl: STRING = "session/$sessionId/element/$id/name" + + cmd_session_element_name (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_clear_tmpl: STRING = "session/$sessionId/element/$id/clear" + + cmd_session_element_clear (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_selected_tmpl: STRING = "session/$sessionId/element/$id/selected" + + cmd_session_element_selected (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_selected_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_enabled_tmpl: STRING = "session/$sessionId/element/$id/enabled" + + cmd_session_element_enabled (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_enabled_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_attribute_name_tmpl: STRING = "session/$sessionId/element/$id/attribute/$name" + + cmd_session_element_attribute_name (sessionId: STRING_32; id: STRING_32; name: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_attribute_name_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$name", name) + end + + cmd_session_element_equals_tmpl: STRING = "session/$sessionId/element/$id/equals/$other" + + cmd_session_element_equals (sessionId: STRING_32; id: STRING_32; other: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_equals_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$other", other) + end + + cmd_session_element_displayed_tmpl: STRING = "session/$sessionId/element/$id/displayed" + + cmd_session_element_displayed (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_displayed_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_location_tmpl: STRING = "session/$sessionId/element/$id/location" + + cmd_session_element_location (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_location_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_location_in_view_tmpl: STRING = "session/$sessionId/element/$id/location_in_view" + + cmd_session_element_location_in_view (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_location_in_view_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_size_tmpl: STRING = "session/$sessionId/element/$id/size" + + cmd_session_element_size (sessionId: STRING_32; id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_size_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + end + + cmd_session_element_css_value_tmpl: STRING = "session/$sessionId/element/$id/css/$propertyName" + + cmd_session_element_css_value (sessionId: STRING_32; id: STRING_32; property_name: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_element_css_value_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$id", id) + Result.replace_substring_all ("$propertyName", property_name) + end + + cmd_session_browser_orientation_tmpl: STRING = "session/$sessionId/orientation" + + cmd_session_browser_orientation (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_browser_orientation_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_alert_text_tmpl: STRING = "session/$sessionId/alert_text" + + cmd_session_alert_text (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_alert_text_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_accept_alert_tmpl: STRING = "session/$sessionId/accept_alert" + + cmd_session_accept_alert (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_accept_alert_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_dismiss_alert_tmpl: STRING = "session/$sessionId/dismiss_alert" + + cmd_session_dismiss_alert (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_dismiss_alert_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_move_to_tmpl: STRING = "session/$sessionId/move_to" + + cmd_session_move_to (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_move_to_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_click_tmpl: STRING = "session/$sessionId/click" + + cmd_session_click (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_buttondown_tmpl: STRING = "session/$sessionId/buttondown" + + cmd_session_buttondown (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_buttondown_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_buttonup_tmpl: STRING = "session/$sessionId/buttonup" + + cmd_session_buttonup (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_buttonup_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_doubleclick_tmpl: STRING = "session/$sessionId/doubleclick" + + cmd_session_double_click (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_doubleclick_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + cmd_session_touch_click_tmpl: STRING = "session/$sessionId/touch/click" + + cmd_session_touch_click (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_screenshot_tmpl : STRING ="session/$id/screenshot" + cmd_session_touch_down_tmpl: STRING = "session/$sessionId/touch/down" + + cmd_session_touch_down (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_down_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_screenshot (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_screenshot_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_up_tmpl: STRING = "session/$sessionId/touch/up" + cmd_session_touch_up (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_up_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_ime_available_engines_tmpl : STRING ="session/$id/ime/available_engines" + cmd_session_touch_move_tmpl: STRING = "session/$sessionId/touch/move" - cmd_session_ime_available (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_ime_available_engines_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_move (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_move_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_ime_active_engine_tmpl : STRING ="session/$id/ime/active_engine" + cmd_session_touch_scroll_tmpl: STRING = "session/$sessionId/touch/scroll" - cmd_session_ime_active_engine (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_ime_active_engine_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_scroll (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_scroll_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_ime_activated_tmpl : STRING ="session/$id/ime/activated" + cmd_session_touch_double_click_tmpl: STRING = "session/$sessionId/touch/doubleclick" - cmd_session_ime_activated (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_ime_activated_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_double_click (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_double_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_ime_deactivate_tmpl : STRING ="session/$id/ime/deactivate" + cmd_session_touch_long_click_tmpl: STRING = "session/$sessionId/touch/longclick" - cmd_session_ime_deactivate (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_ime_deactivate_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_long_click (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_long_click_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_ime_activate_tmpl : STRING ="session/$id/ime/activate" + cmd_session_touch_flick_tmpl: STRING = "session/$sessionId/touch/flick" - cmd_session_ime_activate (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_ime_activate_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_touch_flick (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_touch_flick_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + cmd_session_geo_location_tmpl: STRING = "session/$sessionId/location" + cmd_session_geo_location (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_geo_location_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end ---POST /session/:sessionId/frame Change focus to another frame on the page. + cmd_session_local_storage_tmpl: STRING = "session/$sessionId/local_storage" - cmd_session_window_tmpl : STRING ="session/$id/window" + cmd_session_local_storage (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_local_storage_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_window (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_local_storage_key_tmpl: STRING = "session/$sessionId/local_storage/key/$key" + cmd_session_local_storage_key (sessionId: STRING_32; key : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_local_storage_key_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$key", key) + end - cmd_session_window_size_tmpl : STRING ="session/$id/window/$windowHandle/size" + cmd_session_local_storage_size_tmpl: STRING = "session/$sessionId/local_storage/size" - cmd_session_window_size (id: STRING_32; window_handle: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_size_tmpl) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$windowHandle", window_handle) - end + cmd_session_local_storage_size (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_local_storage_size_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_window_position_tmpl : STRING ="session/$id/window/$windowHandle/position" + cmd_session_storage_tmpl: STRING = "session/$sessionId/session_storage" - cmd_session_window_position (id: STRING_32; window_handle: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_position_tmpl) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$windowHandle", window_handle) - end + cmd_session_storage (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_storage_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_window_maximize_tmpl : STRING ="session/$id/window/$windowHandle/maximize" + cmd_session_storage_key_tmpl: STRING = "session/$sessionId/session_storage/key/$key" - cmd_session_window_maximize (id: STRING_32; window_handle: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_window_maximize_tmpl) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$windowHandle", window_handle) - end + cmd_session_storage_key (sessionId: STRING_32; key : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_storage_key_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + Result.replace_substring_all ("$key", key) + end + cmd_session_storage_size_tmpl: STRING = "session/$sessionId/session_storage/size" + cmd_session_storage_size (sessionId: STRING_32; key : STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_storage_size_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_cookie_tmpl : STRING ="session/$id/cookie" + cmd_session_log_tmpl: STRING = "session/$sessionId/log" - cmd_session_cookie (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_cookie_tmpl) - Result.replace_substring_all ("$id", id) - end + cmd_session_log (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_log_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + cmd_session_log_types_tmpl: STRING = "session/$sessionId/log/types" - cmd_session_cookie_delte_tmpl : STRING ="session/$id/cookie/$name" + cmd_session_log_types (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_log_types_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_cookie_delete (id: STRING_32;name : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_cookie_delte_tmpl) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$name", name) - end + cmd_session_application_cache_tmpl: STRING = "session/$sessionId/application_cache/status" - cmd_session_source_tmpl : STRING ="session/$id/source" + cmd_session_application_cache (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_application_cache_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end - cmd_session_source (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_source_tmpl) - Result.replace_substring_all ("$id", id) - end - - cmd_session_title_tmpl : STRING ="session/$id/title" - - cmd_session_title (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_source_tmpl) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_tmpl : STRING ="session/$id/element" - - cmd_session_element (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_tmpl) - Result.replace_substring_all ("$id", id) - end - - cmd_session_elements_tmpl : STRING ="session/$id/elements" - - cmd_session_elements (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_elements_tmpl) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_active_tmpl : STRING ="session/$id/element/active" - - cmd_session_element_active (id: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_active_tmpl) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_id_tmpl : STRING ="session/$sessionId/element/$id" - - cmd_session_element_id (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_id_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - ---GET /session/:sessionId/element/:id Describe the identified element. - - cmd_session_element_id_element_tmpl : STRING ="session/$sessionId/element/$id/element" - - cmd_session_element_id_element (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_id_element_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_id_elements_tmpl : STRING ="session/$sessionId/element/$id/elements" - - cmd_session_element_id_elements (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_id_elements_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_click_tmpl : STRING ="session/$sessionId/element/$id/click" - - cmd_session_element_click (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_click_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_submit_tmpl : STRING ="session/$sessionId/element/$id/submit" - - cmd_session_element_submit (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_submit_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - - cmd_session_element_text_tmpl : STRING ="session/$sessionId/element/$id/text" - - cmd_session_element_text (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_text_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_event_tmpl : STRING ="session/$sessionId/element/$id/value" - - cmd_session_element_event (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_event_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_keys_tmpl : STRING ="session/$sessionId/keys" - - cmd_session_keys (sessionId: STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_keys_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - end - - cmd_session_element_name_tmpl : STRING ="session/$sessionId/element/$id/name" - - cmd_session_element_name (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_name_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_clear_tmpl : STRING ="session/$sessionId/element/$id/clear" - - cmd_session_element_clear (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_name_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_selected_tmpl : STRING ="session/$sessionId/element/$id/selected" - - cmd_session_element_selected (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_selected_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_enabled_tmpl : STRING ="session/$sessionId/element/$id/enabled" - - cmd_session_element_enabled (sessionId: STRING_32; id : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_enabled_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_attribute_name_tmpl : STRING ="session/$sessionId/element/$id/attribute/$name" - - cmd_session_element_attribute_name (sessionId: STRING_32; id : STRING_32; name : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_attribute_name_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$name", name) - end - - cmd_session_element_equals_tmpl : STRING ="session/$sessionId/element/$id/equals/$other" - - cmd_session_element_equals (sessionId: STRING_32; id : STRING_32; other : STRING_32 ): STRING_32 - do - create Result.make_from_string (cmd_session_element_equals_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$other", other) - end - - cmd_session_element_displayed_tmpl : STRING ="session/$sessionId/element/$id/displayed" - - cmd_session_element_displayed (sessionId: STRING_32; id : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_displayed_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_location_tmpl : STRING ="session/$sessionId/element/$id/location" - - cmd_session_element_location (sessionId: STRING_32; id : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_location_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_location_in_view_tmpl : STRING ="session/$sessionId/element/$id/location_in_view" - - cmd_session_element_location_in_view (sessionId: STRING_32; id : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_location_in_view_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - - cmd_session_element_size_tmpl : STRING ="session/$sessionId/element/$id/size" - - cmd_session_element_size (sessionId: STRING_32; id : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_size_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - end - - cmd_session_element_css_value_tmpl : STRING ="session/$sessionId/element/$id/css/$propertyName" - - cmd_session_element_css_value (sessionId: STRING_32; id : STRING_32; property_name : STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_element_css_value_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - Result.replace_substring_all ("$id", id) - Result.replace_substring_all ("$propertyName", property_name) - end - - cmd_session_browser_orientation_tmpl : STRING ="session/$sessionId/orientation" - - cmd_session_browser_orientation (sessionId: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_browser_orientation_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - end - - cmd_session_alert_text_tmpl : STRING ="session/$sessionId/alert_text" - - cmd_session_alert_text (sessionId: STRING_32): STRING_32 - do - create Result.make_from_string (cmd_session_alert_text_tmpl) - Result.replace_substring_all ("$sessionId", sessionId) - end - - ---POST /session/:sessionId/accept_alert Accepts the currently displayed alert dialog. ---POST /session/:sessionId/dismiss_alert Dismisses the currently displayed alert dialog. ---POST /session/:sessionId/moveto Move the mouse by an offset of the specificed element. ---POST /session/:sessionId/click Click any mouse button (at the coordinates set by the last moveto command). ---POST /session/:sessionId/buttondown Click and hold the left mouse button (at the coordinates set by the last moveto command). ---POST /session/:sessionId/buttonup Releases the mouse button previously held (where the mouse is currently at). ---POST /session/:sessionId/doubleclick Double-clicks at the current mouse coordinates (set by moveto). ---POST /session/:sessionId/touch/click Single tap on the touch enabled device. ---POST /session/:sessionId/touch/down Finger down on the screen. ---POST /session/:sessionId/touch/up Finger up on the screen. ---POST /session/:sessionId/touch/move Finger move on the screen. ---POST /session/:sessionId/touch/scroll Scroll on the touch screen using finger based motion events. ---POST /session/:sessionId/touch/scroll Scroll on the touch screen using finger based motion events. ---POST /session/:sessionId/touch/doubleclick Double tap on the touch screen using finger motion events. ---POST /session/:sessionId/touch/longclick Long press on the touch screen using finger motion events. ---POST /session/:sessionId/touch/flick Flick on the touch screen using finger motion events. ---POST /session/:sessionId/touch/flick Flick on the touch screen using finger motion events. ---GET /session/:sessionId/location Get the current geo location. ---POST /session/:sessionId/location Set the current geo location. ---GET /session/:sessionId/local_storage Get all keys of the storage. ---POST /session/:sessionId/local_storage Set the storage item for the given key. ---DELETE /session/:sessionId/local_storage Clear the storage. ---GET /session/:sessionId/local_storage/key/:key Get the storage item for the given key. ---DELETE /session/:sessionId/local_storage/key/:key Remove the storage item for the given key. ---GET /session/:sessionId/local_storage/size Get the number of items in the storage. ---GET /session/:sessionId/session_storage Get all keys of the storage. ---POST /session/:sessionId/session_storage Set the storage item for the given key. ---DELETE /session/:sessionId/session_storage Clear the storage. ---GET /session/:sessionId/session_storage/key/:key Get the storage item for the given key. ---DELETE /session/:sessionId/session_storage/key/:key Remove the storage item for the given key. ---GET /session/:sessionId/session_storage/size Get the number of items in the storage. ---POST /session/:sessionId/log Get the log for a given log type. ---GET /session/:sessionId/log/types Get available log types. ---GET /session/:sessionId/application_cache/status Get the status of the html5 application cache. end From 31c2be768feb9a1e8aa6dd0ebb89ffce4d3f0fce Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 29 Apr 2013 18:02:33 -0300 Subject: [PATCH 12/36] Created new classes to represent a web driver. Added Examples, clean code --- library/test/selenium/examples/application.e | 27 ++ library/test/selenium/examples/example_1.e | 58 +++ library/test/selenium/examples/examples.ecf | 19 + library/test/selenium/src/enum.e | 37 ++ .../executor}/command_executor.e | 21 +- .../src/protocol/se_json_wire_protocol.e | 144 +++++- .../protocol/se_json_wire_protocol_commands.e | 30 +- library/test/selenium/src/se_button.e | 95 ++++ library/test/selenium/src/se_by.e | 16 +- library/test/selenium/src/se_cookie.e | 2 +- .../src/{se_window.e => se_dimension.e} | 14 +- library/test/selenium/src/se_point.e | 41 ++ library/test/selenium/src/web_driver.e | 444 ++++++++++++++++++ library/test/selenium/src/web_element.e | 109 ++++- library/test/selenium/test/application.e | 3 + 15 files changed, 1012 insertions(+), 48 deletions(-) create mode 100644 library/test/selenium/examples/application.e create mode 100644 library/test/selenium/examples/example_1.e create mode 100644 library/test/selenium/examples/examples.ecf create mode 100644 library/test/selenium/src/enum.e rename library/test/selenium/src/{ => protocol/executor}/command_executor.e (97%) create mode 100644 library/test/selenium/src/se_button.e rename library/test/selenium/src/{se_window.e => se_dimension.e} (74%) create mode 100644 library/test/selenium/src/se_point.e create mode 100644 library/test/selenium/src/web_driver.e diff --git a/library/test/selenium/examples/application.e b/library/test/selenium/examples/application.e new file mode 100644 index 00000000..d86e9d89 --- /dev/null +++ b/library/test/selenium/examples/application.e @@ -0,0 +1,27 @@ +note + description : "project application root class" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION + +inherit + ARGUMENTS + +create + make + +feature {NONE} -- Initialization + + make + -- Run application. + do + execute_example1 + end + + execute_example1 + do + (create {EXAMPLE_1}).test + end +end diff --git a/library/test/selenium/examples/example_1.e b/library/test/selenium/examples/example_1.e new file mode 100644 index 00000000..d905bfd7 --- /dev/null +++ b/library/test/selenium/examples/example_1.e @@ -0,0 +1,58 @@ +note + description: "Summary description for {EXAMPLE_1}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + EXAMPLE_1 + +feature -- Access + test + local + web_driver: SE_JSON_WIRE_PROTOCOL + capabilities: SE_CAPABILITIES + l_session : SE_SESSION + do + create web_driver.make + if attached web_driver.status as l_status then + create capabilities.make + capabilities.set_browser_name ("chrome") + l_session:= web_driver.create_session_with_desired_capabilities (capabilities) + if attached l_session as l_s then + + -- navigate to www.google.com + web_driver.navigate_to_url (l_s.session_id, "http://www.google.com/") + + -- Find the text input element by its name + if attached {WEB_ELEMENT} web_driver.search_element (l_s.session_id, (create {SE_BY}).name ("q")) as l_element then + -- search something + web_driver.send_event(l_s.session_id, l_element.element,<<"Eiffel Room">>) + + -- Submit Form + web_driver.element_submit (l_s.session_id, l_element.element) + + if attached web_driver.page_title (l_s.session_id) as l_page then + print ("Page Name" + l_page) + end + end + end + + end + end + +-- // And now use this to visit Google +-- driver.get("http://www.google.com"); + +-- // Find the text input element by its name +-- WebElement element = driver.findElement(By.name("q")); + +-- // Enter something to search for +-- element.sendKeys("Cheese!"); + +-- // Now submit the form. WebDriver will find the form for us from the element +-- element.submit(); + +-- // Check the title of the page +-- System.out.println("Page title is: " + driver.getTitle()); +end diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf new file mode 100644 index 00000000..15c5511b --- /dev/null +++ b/library/test/selenium/examples/examples.ecf @@ -0,0 +1,19 @@ + + + + + + + + + + + /EIFGENs$ + /.svn$ + /CVS$ + + + + diff --git a/library/test/selenium/src/enum.e b/library/test/selenium/src/enum.e new file mode 100644 index 00000000..21f7fc76 --- /dev/null +++ b/library/test/selenium/src/enum.e @@ -0,0 +1,37 @@ +note + description: "Summary description for {ENUM}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + ENUM + +feature -- Access + + is_valid_state: BOOLEAN + -- Is the value of the enumeration valid? + do + Result := is_valid_value (value) + end + + value: INTEGER + -- The current value of the enumeration. + + set_value (a_value: INTEGER) + require + is_valid_value (a_value) + do + value := a_value + end + + is_valid_value (a_value: INTEGER): BOOLEAN + -- Can `a_value' be used in a `set_value' feature call? + deferred + end + +invariant + is_valid_state + +end -- class ENUM + diff --git a/library/test/selenium/src/command_executor.e b/library/test/selenium/src/protocol/executor/command_executor.e similarity index 97% rename from library/test/selenium/src/command_executor.e rename to library/test/selenium/src/protocol/executor/command_executor.e index 5c41923c..f21575af 100644 --- a/library/test/selenium/src/command_executor.e +++ b/library/test/selenium/src/protocol/executor/command_executor.e @@ -202,22 +202,24 @@ feature -- Commands Result := new_response (a_session_id, resp) end - execute + execute (a_session_id : STRING_32; data : STRING_32) : SE_RESPONSE require selinum_server_available: is_available local resp: HTTP_CLIENT_RESPONSE do - -- TODO + resp := execute_post (cmd_session_execute (a_session_id), data) + Result := new_response (a_session_id, resp) end - execute_async + execute_async (a_session_id : STRING_32; data : STRING_32) : SE_RESPONSE require selinum_server_available: is_available local resp: HTTP_CLIENT_RESPONSE do - -- TODO + resp := execute_post (cmd_session_execute_async (a_session_id),data) + Result := new_response (a_session_id, resp) end screenshot (session_id: STRING_32): SE_RESPONSE @@ -280,6 +282,17 @@ feature -- Commands Result := new_response (a_session_id, resp) end + + frame (a_session_id: STRING_32; a_data: STRING_32): SE_RESPONSE + require + selinum_server_available: is_available + local + resp: HTTP_CLIENT_RESPONSE + do + resp := execute_post (cmd_session_frame (a_session_id), a_data) + Result := new_response (a_session_id, resp) + end + change_focus_window (a_session_id: STRING_32; a_data: STRING_32): SE_RESPONSE require selinum_server_available: is_available diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index 4c92864c..2d60960f 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -576,7 +576,7 @@ feature -- Commands end end - frame (a_session_id: STRING_32) + frame (a_session_id: STRING_32; arg : detachable STRING_32) -- POST /session/:sessionId/frame -- Change focus to another frame on the page. If the frame id is null, the server should switch to the page's default content. -- URL Parameters: @@ -586,7 +586,23 @@ feature -- Commands -- Potential Errors: -- NoSuchWindow - If the currently selected window has been closed. -- NoSuchFrame - If the frame specified by id cannot be found. + local + l_json: STRING_32 + resp: SE_RESPONSE do + l_json := "[ + { "id": $id } + ]" + if attached arg as l_arg then + l_json.replace_substring_all ("$id", l_arg) + else + l_json.replace_substring_all ("$id", "null") + end + + if commnad_executor.is_available then + resp := commnad_executor.frame (a_session_id, l_json) + check_response (resp) + end end change_focus_window (a_session_id: STRING_32; a_name: STRING_32) @@ -653,7 +669,7 @@ feature -- Commands end end - size_window (a_session_id: STRING_32; a_window_handle: STRING_32): SE_WINDOW + size_window (a_session_id: STRING_32; a_window_handle: STRING_32): SE_DIMENSION -- GET /session/:sessionId/window/:windowHandle/size -- Get the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned. -- URL Parameters: @@ -709,7 +725,7 @@ feature -- Commands end end - window_position (a_session_id: STRING_32; a_window_handle: STRING_32): SE_WINDOW + window_position (a_session_id: STRING_32; a_window_handle: STRING_32): SE_POINT -- GET /session/:sessionId/window/:windowHandle/position -- Get the position of the specified window. If the :windowHandle URL parameter is "current", the position of the currently active window will be returned. -- URL Parameters: @@ -931,8 +947,8 @@ feature -- Commands resp := commnad_executor.search_element (a_session_id, strategy) check_response (resp) if not has_error then - if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then - create Result.make (l_elem.representation) + if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as ll_value and then attached {JSON_STRING} ll_value.item ("ELEMENT") as l_elem then + create Result.make (l_elem.item) end end end @@ -1437,7 +1453,7 @@ feature -- Commands end end - element_location (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW + element_location (a_session_id: STRING_32; an_id: STRING_32): SE_POINT -- GET /session/:sessionId/element/:id/location -- Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. -- The element's coordinates are returned as a JSON object with x and y properties. @@ -1469,7 +1485,7 @@ feature -- Commands end end - location_in_view (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW + location_in_view (a_session_id: STRING_32; an_id: STRING_32): SE_POINT -- GET /session/:sessionId/element/:id/location_in_view -- Determine an element's location on the screen once it has been scrolled into view. -- Note: This is considered an internal command and should only be used to determine an element's @@ -1502,7 +1518,7 @@ feature -- Commands end end - element_size (a_session_id: STRING_32; an_id: STRING_32): SE_WINDOW + element_size (a_session_id: STRING_32; an_id: STRING_32): SE_DIMENSION -- GET /session/:sessionId/element/:id/size -- Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. -- URL Parameters: @@ -1632,7 +1648,7 @@ feature -- Commands end end - send_alert_text (a_session_id: STRING_32) + send_alert_text (a_session_id: STRING_32; text : STRING_32) -- POST /session/:sessionId/alert_text -- Sends keystrokes to a JavaScript prompt() dialog. -- URL Parameters: @@ -1641,7 +1657,19 @@ feature -- Commands -- text - {string} Keystrokes to send to the prompt() dialog. -- Potential Errors: -- NoAlertPresent - If there is no alert displayed. + local + resp : SE_RESPONSE + l_json : STRING_32 do + l_json := "[ + { "text":"$text" } + ]" + + if commnad_executor.is_available then + l_json.replace_substring_all ("$text", text) + resp := commnad_executor.send_alert_text (a_session_id, l_json) + check_response (resp) + end end accept_alert (a_session_id: STRING_32) @@ -1651,7 +1679,13 @@ feature -- Commands -- :sessionId - ID of the session to route the command to. -- Potential Errors: -- NoAlertPresent - If there is no alert displayed. + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.accept_alert (a_session_id) + check_response (resp) + end end dismiss_alert (a_session_id: STRING_32) @@ -1661,57 +1695,131 @@ feature -- Commands -- :sessionId - ID of the session to route the command to. -- Potential Errors: -- NoAlertPresent - If there is no alert displayed. + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.dismiss_alert (a_session_id) + check_response (resp) + end end - move_to (a_session_id: STRING_32) + move_to (a_session_id: STRING_32; web_element : WEB_ELEMENT; xoffset : NATURAL; yoffset:NATURAL) -- POST /session/:sessionId/moveto - -- Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view. + -- Move the mouse by an offset of the specificed element. + -- If no element is specified, the move is relative to the current mouse cursor. + -- If an element is provided but no offset, the mouse will be moved to the center of the element. + -- If the element is not visible, it will be scrolled into view. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: -- element - {string} Opaque ID assigned to the element to move to, as described in the WebElement JSON Object. If not specified or is null, the offset is relative to current position of the mouse. -- xoffset - {number} X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. -- yoffset - {number} Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + local + resp : SE_RESPONSE + l_json : STRING_32 + do + l_json := "[ + { "element" : "$element", + "yoffset" : $yoffset, + "xoffset" : $xoffset + } + ]" + if commnad_executor.is_available then + l_json.replace_substring_all ("$element", web_element.element) + l_json.replace_substring_all ("$yoffset", yoffset.out) + l_json.replace_substring_all ("$xoffset", xoffset.out) + resp := commnad_executor.move_to (a_session_id, l_json) + check_response (resp) + end end - click (a_session_id: STRING_32) + click (a_session_id: STRING_32; button : SE_BUTTON ) -- POST /session/:sessionId/click -- Click any mouse button (at the coordinates set by the last moveto command). Note that calling this command after calling buttondown and before calling button up (or any out-of-order interactions sequence) will yield undefined behaviour). -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + local + resp : SE_RESPONSE + l_json : STRING_32 do + l_json := "[ + { + "button" : $number + } + ]" + if commnad_executor.is_available then + l_json.replace_substring_all ("$number", button.value.out) + resp := commnad_executor.click (a_session_id, l_json) + check_response (resp) + end end - button_down (a_session_id: STRING_32) + button_down (a_session_id: STRING_32; button : SE_BUTTON) -- POST /session/:sessionId/buttondown - -- Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. + -- Click and hold the left mouse button (at the coordinates set by the last moveto command). + -- Note that the next mouse-related command that should follow is buttonup . + -- Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: - -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. + -- Defaults to the left mouse button if not specified. + local + resp : SE_RESPONSE + l_json : STRING_32 do + l_json := "[ + { + "button" : $number + } + ]" + if commnad_executor.is_available then + l_json.replace_substring_all ("$number", button.value.out) + resp := commnad_executor.button_down (a_session_id, l_json) + check_response (resp) + end end - button_up (a_session_id: STRING_32) + button_up (a_session_id: STRING_32; button : SE_BUTTON) -- POST /session/:sessionId/buttonup -- Releases the mouse button previously held (where the mouse is currently at). Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands. -- URL Parameters: -- :sessionId - ID of the session to route the command to. -- JSON Parameters: - -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified. + -- button - {number} Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. + -- Defaults to the left mouse button if not specified. + local + resp : SE_RESPONSE + l_json : STRING_32 do + l_json := "[ + { + "button" : $number + } + ]" + if commnad_executor.is_available then + l_json.replace_substring_all ("$number", button.value.out) + resp := commnad_executor.button_up (a_session_id, l_json) + check_response (resp) + end end - double_click (a_session_id: STRING_32) -- POST /session/:sessionId/doubleclick -- Double-clicks at the current mouse coordinates (set by moveto). -- URL Parameters: -- :sessionId - ID of the session to route the command to. + local + resp : SE_RESPONSE do + if commnad_executor.is_available then + resp := commnad_executor.double_click (a_session_id) + check_response (resp) + end end touch_click (a_session_id: STRING_32) diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e index 4eba93dc..a1ba2bd7 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol_commands.e @@ -103,8 +103,21 @@ feature Result.replace_substring_all ("$id", id) end - --POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. - --POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. + cmd_session_execute_tmpl: STRING = "session/$id/execute" + + cmd_session_execute (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_execute_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_execute_async_tmpl: STRING = "session/$id/execute_async" + + cmd_session_execute_async (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_execute_async_tmpl) + Result.replace_substring_all ("$id", id) + end cmd_session_screenshot_tmpl: STRING = "session/$id/screenshot" @@ -156,6 +169,15 @@ feature --POST /session/:sessionId/frame Change focus to another frame on the page. + cmd_session_frame_tmpl: STRING = "session/$id/frame" + + cmd_session_frame (id: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_frame_tmpl) + Result.replace_substring_all ("$id", id) + end + + cmd_session_window_tmpl: STRING = "session/$id/window" cmd_session_window (id: STRING_32): STRING_32 @@ -220,7 +242,7 @@ feature cmd_session_title (id: STRING_32): STRING_32 do - create Result.make_from_string (cmd_session_source_tmpl) + create Result.make_from_string (cmd_session_title_tmpl) Result.replace_substring_all ("$id", id) end @@ -611,7 +633,7 @@ feature cmd_session_storage_size_tmpl: STRING = "session/$sessionId/session_storage/size" - cmd_session_storage_size (sessionId: STRING_32; key : STRING_32): STRING_32 + cmd_session_storage_size (sessionId: STRING_32): STRING_32 do create Result.make_from_string (cmd_session_storage_size_tmpl) Result.replace_substring_all ("$sessionId", sessionId) diff --git a/library/test/selenium/src/se_button.e b/library/test/selenium/src/se_button.e new file mode 100644 index 00000000..51bb8d38 --- /dev/null +++ b/library/test/selenium/src/se_button.e @@ -0,0 +1,95 @@ +note + description: "Summary description for {SE_BUTTON}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_BUTTON +inherit {NONE} + ENUM + + +create + make_left, + make_middle, + make_right + + +feature -- Initialization + + make_left + do + set_left + end + + make_middle + do + set_middle + end + + make_right + do + set_right + end + + +feature -- Access + + is_valid_value (a_value: INTEGER): BOOLEAN + -- Can `a_value' be used in a `set_value' feature call? + do + Result := (a_value = left_value) or else + (a_value = middle_value) or else + (a_value = right_value) + end + +feature -- Element Change + + set_left + do + value := left_value + end + + set_middle + do + value := middle_value + end + + set_right + do + value := right_value + end + + +feature -- Query + + is_left : BOOLEAN + -- is the current value left? + do + Result := (value = left_value) + end + + is_middle : BOOLEAN + -- is the current value middle? + do + Result := (value = middle_value) + end + + + is_right : BOOLEAN + -- is the current value right? + do + Result := (value = right_value) + end + + +feature {NONE} -- Implementation +-- {LEFT = 0, MIDDLE = 1 , RIGHT = 2} + left_value :INTEGER = 0 + middle_value : INTEGER = 1 + right_value : INTEGER = 2 +end + + + diff --git a/library/test/selenium/src/se_by.e b/library/test/selenium/src/se_by.e index ea4f37ec..84c6b63d 100644 --- a/library/test/selenium/src/se_by.e +++ b/library/test/selenium/src/se_by.e @@ -13,7 +13,7 @@ inherit create default_create feature -- Access - id (an_id : STRING_32; value : STRING_32 ) : STRING_32 + id ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `id' and value `value' -- { "using" : "id", "value":value } @@ -25,7 +25,7 @@ feature -- Access has_id_strategy : has_correct_stategy (Result, se_id) end - name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + name ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `name' and value `value' -- { "using" : "name", "value":value } @@ -37,7 +37,7 @@ feature -- Access has_name_strategy : has_correct_stategy (Result, se_name) end - class_name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + class_name ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `class name' and value `value' -- { "using" : "class name", "value":value } @@ -50,7 +50,7 @@ feature -- Access end - css_selector (an_id : STRING_32; value : STRING_32 ) : STRING_32 + css_selector ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `css selector' and value `value' -- { "using" : "css selector", "value":value } @@ -62,7 +62,7 @@ feature -- Access has_css_selector_strategy : has_correct_stategy (Result, se_css_selector) end - link_text (an_id : STRING_32; value : STRING_32 ) : STRING_32 + link_text ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `link text' and value `value' -- { "using" : "link text", "value":value } @@ -75,7 +75,7 @@ feature -- Access end - partial_link_text (an_id : STRING_32; value : STRING_32 ) : STRING_32 + partial_link_text ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `partial link text' and value `value' -- { "using" : "partial link text", "value":value } @@ -87,7 +87,7 @@ feature -- Access has_partial_link_text_strategy : has_correct_stategy (Result, se_partial_link_text) end - tag_name (an_id : STRING_32; value : STRING_32 ) : STRING_32 + tag_name ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `tag name' and value `value' -- { "using" : "tag name", "value":value } @@ -100,7 +100,7 @@ feature -- Access end - xpath (an_id : STRING_32; value : STRING_32 ) : STRING_32 + xpath ( value : STRING_32 ) : STRING_32 -- return a STRING representing a JSON -- with strategy by `xpath' and value `value' -- { "using" : "xpath", "value":value } diff --git a/library/test/selenium/src/se_cookie.e b/library/test/selenium/src/se_cookie.e index 6731afdb..f15402f3 100644 --- a/library/test/selenium/src/se_cookie.e +++ b/library/test/selenium/src/se_cookie.e @@ -1,5 +1,5 @@ note - description: "bject that describe a cookie. When returning Cookie objects, the server should only omit an optional field if it is incapable of providing the information." + description: "Objects that describe a cookie. When returning Cookie objects, the server should only omit an optional field if it is incapable of providing the information." author: "" date: "$Date$" revision: "$Revision$" diff --git a/library/test/selenium/src/se_window.e b/library/test/selenium/src/se_dimension.e similarity index 74% rename from library/test/selenium/src/se_window.e rename to library/test/selenium/src/se_dimension.e index 49ea5477..216105af 100644 --- a/library/test/selenium/src/se_window.e +++ b/library/test/selenium/src/se_dimension.e @@ -1,11 +1,11 @@ note - description: "Summary description for {SE_WINDOW}." + description: "Summary description for {SE_DIMENSION}." author: "" date: "$Date$" revision: "$Revision$" class - SE_WINDOW + SE_DIMENSION create default_create, make_with_values @@ -24,8 +24,6 @@ feature -- Access height : NATURAL_32 -- The width and height of the element, in pixels. - x,y : INTEGER_32 - -- The X and Y coordinates for the element. feature -- Change Element set_width (a_width : NATURAL_32) @@ -41,14 +39,6 @@ feature -- Change Element height := a_height end - set_x (an_x : INTEGER_32) - do - x := an_x - end - set_y (an_y : INTEGER_32) - do - y := an_y - end end diff --git a/library/test/selenium/src/se_point.e b/library/test/selenium/src/se_point.e new file mode 100644 index 00000000..fc360760 --- /dev/null +++ b/library/test/selenium/src/se_point.e @@ -0,0 +1,41 @@ +note + description: "Summary description for {SE_POINT}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_POINT + +create + default_create, + make_with_values + +feature -- Initialization + + make_with_values (new_x : INTEGER_32; new_y : INTEGER_32) + do + set_x (new_x) + set_y (new_y) + end + +feature -- Access + + x : INTEGER_32 + y : INTEGER_32 + + -- The X and Y coordinates for the element. + +feature -- Change Element + + set_x (an_x : INTEGER_32) + do + x := an_x + end + + set_y (an_y : INTEGER_32) + do + y := an_y + end + +end diff --git a/library/test/selenium/src/web_driver.e b/library/test/selenium/src/web_driver.e new file mode 100644 index 00000000..5144541f --- /dev/null +++ b/library/test/selenium/src/web_driver.e @@ -0,0 +1,444 @@ +note + description: "Objects that represent a Web Browser" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_DRIVER + +inherit {NONE} + + SE_JSON_WIRE_PROTOCOL + rename + back as se_back, + forward as se_forward, + refresh as se_refresh, + window_position as se_window_position, + window_maximize as se_window_maximize + export + {NONE} all + end + +create {SE_JSON_WIRE_PROTOCOL} + make, make_with_host + +feature -- Initialize Session + + start_session_firefox + local + l_capabilities: SE_CAPABILITIES + do + create l_capabilities.make + l_capabilities.set_browser_name ("firefox") + session := create_session_with_desired_capabilities (l_capabilities) + end + + start_session_firefox_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) + require + browser_name_firefox: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "firefox" + do + session := create_session_with_desired_capabilities (a_desired_capabilities) + end + + start_session_chrome + local + l_capabilities: SE_CAPABILITIES + do + create l_capabilities.make + l_capabilities.set_browser_name ("chrome") + session := create_session_with_desired_capabilities (l_capabilities) + end + + start_session_chrome_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) + require + browser_name_chrome: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "chrome" + do + session := create_session_with_desired_capabilities (a_desired_capabilities) + end + + start_session_ie + local + l_capabilities: SE_CAPABILITIES + do + create l_capabilities.make + l_capabilities.set_browser_name ("internet explorer") + session := create_session_with_desired_capabilities (l_capabilities) + end + + start_session_ie_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) + require + browser_name_chrome: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "internet explorer" + do + session := create_session_with_desired_capabilities (a_desired_capabilities) + end + + --|TODO add create session with desired and required capabilities + --| add other drivers. + --| think about pre and postconditions + +feature -- Query + + is_session_active: BOOLEAN + -- exist a valid session? + do + Result := attached session + end + +feature -- Ime Handler + + activate_engine (engine: STRING_32) + -- Make an engines that is available (appears on the list returned by getAvailableEngines) active. + require + exist_session: is_session_active + do + if attached session as l_session then + ime_activate (l_session.session_id, engine) + end + end + + deactivate + -- De-activates the currently-active IME engine. + require + exist_session: is_session_active + do + if attached session as l_session then + ime_deactivate (l_session.session_id) + end + end + + available_engines: detachable LIST [STRING_32] + -- List all available engines on the machine. To use an engine, it has to be present in this list. + require + exist_session: is_session_active + do + if attached session as l_session then + Result := ime_available_engines (l_session.session_id) + end + end + + is_activated: BOOLEAN + require + exist_session: is_session_active + do + if attached session as l_session then + Result := ime_activated (l_session.session_id) + end + end + +feature -- Navigation + + back + -- Navigate backwards in the browser history, if possible. + require + exist_session: is_session_active + do + if attached session as l_session then + se_back (l_session.session_id) + end + end + + forward + -- Navigate forwards in the browser history, if possible. + require + exist_session: is_session_active + do + if attached session as l_session then + se_forward (l_session.session_id) + end + end + + refresh + -- + require + exist_session: is_session_active + do + if attached session as l_session then + se_refresh (l_session.session_id) + end + end + + to_url (an_url: STRING_32) + -- Navigate to a new URL. + require + exist_session: is_session_active + do + if attached session as l_session then + navigate_to_url (l_session.session_id, an_url) + end + end + +feature -- Options + -- Stuff you would do in a browser menu + + add_cookie (cookie: SE_COOKIE) + -- Set a cookie. If the cookie path is not specified, it should be set to "/". + -- Likewise, if the domain is omitted, it should default to the current page's domain. + require + exist_session: is_session_active + do + if attached session as l_session then + set_cookie (l_session.session_id, cookie) + end + end + + delete_all_cookies + -- Delete all cookies visible to the current page. + require + exist_session: is_session_active + do + if attached session as l_session then + delete_cookies (l_session.session_id) + end + end + + delete_cookie (cookie: SE_COOKIE) + -- Delete the cookie with the given name. + -- This command should be a no-op if there is no such cookie visible to the current page. + require + exist_session: is_session_active + do + if attached session as l_session and then attached cookie.name as l_name then + delete_cookie_by_name (l_session.session_id, l_name) + end + end + + get_cookies: detachable LIST [SE_COOKIE] + -- Retrieve all cookies visible to the current page. + require + exist_session: is_session_active + do + if attached session as l_session then + Result := retrieve_cookies (l_session.session_id) + end + end + + get_cookie (name: STRING_32): detachable SE_COOKIE + -- Get a cookie with a given name + require + exist_session: is_session_active + local + found: BOOLEAN + do + if attached session as l_session then + if attached retrieve_cookies (l_session.session_id) as l_list then + from + l_list.start + until + l_list.after or found + loop + if attached l_list.item.name as l_name and then l_name.is_case_insensitive_equal (name) then + found := true + Result := l_list.item + end + l_list.forth + end + end + end + end + +feature -- Target Locator + + active_element: detachable WEB_ELEMENT + require + exist_session: is_session_active + do + if attached session as l_session then + Result := element_active (l_session.session_id) + end + end + + default_content + -- The server switch to the page's default content. + require + exist_session: is_session_active + do + if attached session as l_session then + frame (l_session.session_id, Void) + end + end + + frame_by_index (index: INTEGER) + -- Select a frame by index `index' + require + exist_session: is_session_active + do + if attached session as l_session then + frame (l_session.session_id, index.out) + end + end + + frame_by_name (name: STRING_32) + -- Select a frame by name `name' + require + exist_session: is_session_active + do + if attached session as l_session then + frame (l_session.session_id, name) + end + end + + frame_by_web_element (element: WEB_ELEMENT) + -- Select a frame by name `name' + require + exist_session: is_session_active + do + if attached session as l_session then + frame (l_session.session_id, element.element) + end + end + + window (name: STRING_32) + -- Change focus to another window. + -- The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. + require + exist_session: is_session_active + do + if attached session as l_session then + change_focus_window (l_session.session_id, name) + end + end + +feature -- Window + + window_position: SE_POINT + -- Get the position of the current window. + require + exist_session: is_session_active + do + create Result + if attached session as l_session then + Result := se_window_position (l_session.session_id, "current") + end + end + + window_size: SE_DIMENSION + --Get the size of the current window. + require + exist_session: is_session_active + do + create Result + if attached session as l_session then + Result := size_window (l_session.session_id, "current") + end + end + + window_maximize + --Maximizes the current window if it is not already maximized + require + exist_session: is_session_active + do + if attached session as l_session then + se_window_maximize (l_session.session_id, "current") + end + end + + set_window_position (target_position: SE_POINT) + -- Set the position of the current window. + require + exist_session: is_session_active + do + if attached session as l_session then + change_window_position (l_session.session_id, "current", target_position.x, target_position.y) + end + end + + set_window_size (target_size: SE_DIMENSION) + --Set the size of the current window. + require + exist_session: is_session_active + do + if attached session as l_session then + change_size_window (l_session.session_id, "current", target_size.width, target_size.height) + end + end + +feature -- Common + + window_close + --Close the current window, quitting the browser if it's the last window currently open. + require + exist_session: is_session_active + do + if attached session as l_session then + close_window (l_session.session_id) + end + end + + find_element (by: SE_BY) : detachable WEB_ELEMENT + -- Find the first WebElement using the given strategy. + require + exist_session : is_session_active + do + if attached session as l_session then + + end + end + + find_elements (by: SE_BY) : detachable LIST[WEB_ELEMENT] + -- Find all elements within the current page using the given mechanism.. + require + exist_session : is_session_active + do + if attached session as l_session then + + end + end + + + get_current_url : detachable STRING_32 + -- Retrieve the URL of the current page. + require + exist_session : is_session_active + do + if attached session as l_session then + Result := retrieve_url (l_session.session_id) + end + end + + get_page_source : detachable STRING_32 + -- Get the current page source. + require + exist_session : is_session_active + do + if attached session as l_session then + Result := page_source (l_session.session_id) + end + end + + get_page_tile : detachable STRING_32 + --Get the current page title + require + exist_session : is_session_active + do + if attached session as l_session then + Result := page_title (l_session.session_id) + end + end + + + + get_window_handle : detachable STRING_32 + require + exist_session : is_session_active + do + if attached session as l_session then + Result := retrieve_window_handle (l_session.session_id) + end + end + + get_window_handles : detachable LIST[STRING_32] + require + exist_session : is_session_active + do + if attached session as l_session then + Result := retrieve_window_handles (l_session.session_id) + end + end + + +feature {NONE} -- Implementation + + session: detachable SE_SESSION + +end diff --git a/library/test/selenium/src/web_element.e b/library/test/selenium/src/web_element.e index d0fd67f0..4ae9c1eb 100644 --- a/library/test/selenium/src/web_element.e +++ b/library/test/selenium/src/web_element.e @@ -7,11 +7,20 @@ note class WEB_ELEMENT create - make + make, + make2 feature + make2 ( an_element : STRING_32 ; an_api : like api; a_session_id : STRING_32) + do + set_element (an_element) + api := an_api + session_id := a_session_id + end make ( an_element : STRING_32) do set_element (an_element) + create api.make + session_id := "" end feature -- Access element : STRING_32 @@ -23,4 +32,102 @@ feature -- Change Element do element := an_element end + +feature -- Web Element API + clear + -- Clear a TEXTAREA or text INPUT element's value. + do + api.clear_element (session_id, element) + end + + click + -- Click on an element. + do + api.element_click (session_id, element) + end + + find_element (by : SE_BY) : detachable WEB_ELEMENT + -- Find the first WebElement using the given method. + do + Result := api.search_element (session_id,"") + end + + find_elementS (by : SE_BY) : detachable LIST[WEB_ELEMENT] + -- Find all elements within the current context using the given mechanism. + do + Result := api.search_elements (session_id,"") + end + + get_attribute (name : STRING_32) : detachable STRING_32 + -- Get the value of an element's attribute. + do + Result := api.element_value (session_id, element, name) + end + + get_css_value (name : STRING_32) : detachable STRING_32 + -- Get the value of an element's attribute. + do + Result := api.element_css_value (session_id, element, name) + end + + get_location : SE_POINT + -- Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. + do + Result := api.element_location (session_id, element) + end + + + get_size : SE_DIMENSION + -- Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. + do + Result := api.element_size (session_id, element) + end + + get_tag_name : detachable STRING_32 + -- The element's tag name, as a lowercase string. + do + Result := api.query_by_tag_name (session_id, element) + end + + + get_text : detachable STRING_32 + -- Returns the visible text for the element. + do + Result := api.element_text (session_id, element) + end + + is_displayed : BOOLEAN + -- Determine if an element is currently displayed. + do + Result := api.is_displayed (session_id, element) + end + + is_enabled : BOOLEAN + -- Determine if an element is currently enabled. + do + Result := api.is_enabled (session_id, element) + end + + is_selected : BOOLEAN + -- Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected. + do + Result := api.is_selected (session_id, element) + end + + send_keys (keys : ARRAY[STRING_32]) + -- Send a sequence of key strokes to an element. + do + api.send_event (session_id, element, keys) + end + + submit + -- Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. + do + api.element_submit (session_id, element) + end + +feature {NONE} -- Implementation + + api : SE_JSON_WIRE_PROTOCOL + session_id : STRING_32 end diff --git a/library/test/selenium/test/application.e b/library/test/selenium/test/application.e index 3787b649..0c15522a 100644 --- a/library/test/selenium/test/application.e +++ b/library/test/selenium/test/application.e @@ -115,6 +115,7 @@ feature {NONE} -- Initialization print ("The selenium server is not accesible") end end + test_back_forward_refesh local web_driver: SE_JSON_WIRE_PROTOCOL @@ -184,6 +185,8 @@ feature {NONE} -- Initialization end end end + + test_session local h: LIBCURL_HTTP_CLIENT From dcdc700bac652f09acf66c4d059b00660f6a3a99 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 30 Apr 2013 10:19:34 -0300 Subject: [PATCH 13/36] Added a simple search example. Updated web_driver, use the API as delegation instead of inheritance. Updated web_element class. --- library/test/selenium/examples/application.e | 7 +- library/test/selenium/examples/example_1.e | 2 +- .../test/selenium/examples/example_search.e | 44 +++++++ library/test/selenium/examples/examples.ecf | 10 +- .../src/protocol/se_json_wire_protocol.e | 10 +- library/test/selenium/src/web_driver.e | 110 +++++++++--------- library/test/selenium/src/web_element.e | 12 +- 7 files changed, 121 insertions(+), 74 deletions(-) create mode 100644 library/test/selenium/examples/example_search.e diff --git a/library/test/selenium/examples/application.e b/library/test/selenium/examples/application.e index d86e9d89..d3177d6f 100644 --- a/library/test/selenium/examples/application.e +++ b/library/test/selenium/examples/application.e @@ -17,11 +17,16 @@ feature {NONE} -- Initialization make -- Run application. do - execute_example1 + execute_search end execute_example1 do (create {EXAMPLE_1}).test end + + execute_search + do + (create {EXAMPLE_SEARCH}).search + end end diff --git a/library/test/selenium/examples/example_1.e b/library/test/selenium/examples/example_1.e index d905bfd7..9efa3bce 100644 --- a/library/test/selenium/examples/example_1.e +++ b/library/test/selenium/examples/example_1.e @@ -12,7 +12,7 @@ feature -- Access local web_driver: SE_JSON_WIRE_PROTOCOL capabilities: SE_CAPABILITIES - l_session : SE_SESSION + l_session : detachable SE_SESSION do create web_driver.make if attached web_driver.status as l_status then diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e new file mode 100644 index 00000000..8ef8643f --- /dev/null +++ b/library/test/selenium/examples/example_search.e @@ -0,0 +1,44 @@ +note + description: "Summary description for {EXAMPLE_SEARCH}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + EXAMPLE_SEARCH + +feature -- Example + search + local + web_driver : WEB_DRIVER + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to Google + web_driver.to_url ("http://www.google.com/") + + -- Find the text input element by its name + if attached web_driver.find_element ((create{SE_BY}).name ("q")) as l_element then + + -- Enter something to search for + l_element.send_keys(<<"Eiffel Room">>) + + -- Now submit the form. WebDriver will find the form for us from the element + l_element.submit + + end + + if attached web_driver.get_page_tile as l_title then + print ("Page title is:" + l_title) + end + + -- close the window + web_driver.window_close + + + end +end diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf index 15c5511b..6f6b52d7 100644 --- a/library/test/selenium/examples/examples.ecf +++ b/library/test/selenium/examples/examples.ecf @@ -1,18 +1,18 @@ - + - - diff --git a/library/test/selenium/src/protocol/se_json_wire_protocol.e b/library/test/selenium/src/protocol/se_json_wire_protocol.e index 2d60960f..5d8d95cd 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -948,7 +948,7 @@ feature -- Commands check_response (resp) if not has_error then if attached resp.value as l_value and then attached {JSON_OBJECT} string_to_json (l_value) as ll_value and then attached {JSON_STRING} ll_value.item ("ELEMENT") as l_elem then - create Result.make (l_elem.item) + create Result.make (l_elem.item, Current, a_session_id) end end end @@ -996,7 +996,7 @@ feature -- Commands index > l_json_array.count loop if attached {JSON_OBJECT} l_json_array.i_th (index) as json_str and then attached json_str.item ("ELEMENT") as l_elem then - Result.force (create {WEB_ELEMENT}.make (l_elem.representation)) + Result.force (create {WEB_ELEMENT}.make (l_elem.representation, Current, a_session_id)) end index := index + 1 end @@ -1022,7 +1022,7 @@ feature -- Commands check_response (resp) if not has_error then if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then - create Result.make (l_elem.representation) + create Result.make (l_elem.representation, Current, a_session_id) end end end @@ -1082,7 +1082,7 @@ feature -- Commands check_response (resp) if not has_error then if attached {JSON_OBJECT} resp.value as l_value and then attached l_value.item ("ELEMENT") as l_elem then - create Result.make (l_elem.representation) + create Result.make (l_elem.representation, Current, a_session_id) end end end @@ -1135,7 +1135,7 @@ feature -- Commands index > l_json_array.count loop if attached {JSON_OBJECT} l_json_array.i_th (index) as json_str and then attached json_str.item ("ELEMENT") as l_elem then - Result.force (create {WEB_ELEMENT}.make (l_elem.representation)) + Result.force (create {WEB_ELEMENT}.make (l_elem.representation,Current, a_session_id)) end index := index + 1 end diff --git a/library/test/selenium/src/web_driver.e b/library/test/selenium/src/web_driver.e index 5144541f..05e97bce 100644 --- a/library/test/selenium/src/web_driver.e +++ b/library/test/selenium/src/web_driver.e @@ -7,21 +7,20 @@ note class WEB_DRIVER -inherit {NONE} - SE_JSON_WIRE_PROTOCOL - rename - back as se_back, - forward as se_forward, - refresh as se_refresh, - window_position as se_window_position, - window_maximize as se_window_maximize - export - {NONE} all +create + make, make_with_host + +feature -- Initialization + make + do + create api.make end -create {SE_JSON_WIRE_PROTOCOL} - make, make_with_host + make_with_host (a_host : STRING) + do + create api.make_with_host (a_host) + end feature -- Initialize Session @@ -31,14 +30,14 @@ feature -- Initialize Session do create l_capabilities.make l_capabilities.set_browser_name ("firefox") - session := create_session_with_desired_capabilities (l_capabilities) + session := api.create_session_with_desired_capabilities (l_capabilities) end start_session_firefox_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) require browser_name_firefox: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "firefox" do - session := create_session_with_desired_capabilities (a_desired_capabilities) + session := api.create_session_with_desired_capabilities (a_desired_capabilities) end start_session_chrome @@ -47,14 +46,16 @@ feature -- Initialize Session do create l_capabilities.make l_capabilities.set_browser_name ("chrome") - session := create_session_with_desired_capabilities (l_capabilities) + if attached api.create_session_with_desired_capabilities (l_capabilities) as l_session then + session := l_session + end end start_session_chrome_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) require browser_name_chrome: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "chrome" do - session := create_session_with_desired_capabilities (a_desired_capabilities) + session := api.create_session_with_desired_capabilities (a_desired_capabilities) end start_session_ie @@ -63,14 +64,14 @@ feature -- Initialize Session do create l_capabilities.make l_capabilities.set_browser_name ("internet explorer") - session := create_session_with_desired_capabilities (l_capabilities) + session := api.create_session_with_desired_capabilities (l_capabilities) end start_session_ie_with_desired_capabilities (a_desired_capabilities: SE_CAPABILITIES) require browser_name_chrome: attached a_desired_capabilities.browser_name as l_browser_name and then l_browser_name ~ "internet explorer" do - session := create_session_with_desired_capabilities (a_desired_capabilities) + session := api.create_session_with_desired_capabilities (a_desired_capabilities) end --|TODO add create session with desired and required capabilities @@ -93,7 +94,7 @@ feature -- Ime Handler exist_session: is_session_active do if attached session as l_session then - ime_activate (l_session.session_id, engine) + api.ime_activate (l_session.session_id, engine) end end @@ -103,7 +104,7 @@ feature -- Ime Handler exist_session: is_session_active do if attached session as l_session then - ime_deactivate (l_session.session_id) + api.ime_deactivate (l_session.session_id) end end @@ -113,7 +114,7 @@ feature -- Ime Handler exist_session: is_session_active do if attached session as l_session then - Result := ime_available_engines (l_session.session_id) + Result := api.ime_available_engines (l_session.session_id) end end @@ -122,7 +123,7 @@ feature -- Ime Handler exist_session: is_session_active do if attached session as l_session then - Result := ime_activated (l_session.session_id) + Result := api.ime_activated (l_session.session_id) end end @@ -134,7 +135,7 @@ feature -- Navigation exist_session: is_session_active do if attached session as l_session then - se_back (l_session.session_id) + api.back (l_session.session_id) end end @@ -144,7 +145,7 @@ feature -- Navigation exist_session: is_session_active do if attached session as l_session then - se_forward (l_session.session_id) + api.forward (l_session.session_id) end end @@ -154,7 +155,7 @@ feature -- Navigation exist_session: is_session_active do if attached session as l_session then - se_refresh (l_session.session_id) + api.refresh (l_session.session_id) end end @@ -164,7 +165,7 @@ feature -- Navigation exist_session: is_session_active do if attached session as l_session then - navigate_to_url (l_session.session_id, an_url) + api.navigate_to_url (l_session.session_id, an_url) end end @@ -178,7 +179,7 @@ feature -- Options exist_session: is_session_active do if attached session as l_session then - set_cookie (l_session.session_id, cookie) + api.set_cookie (l_session.session_id, cookie) end end @@ -188,7 +189,7 @@ feature -- Options exist_session: is_session_active do if attached session as l_session then - delete_cookies (l_session.session_id) + api.delete_cookies (l_session.session_id) end end @@ -199,7 +200,7 @@ feature -- Options exist_session: is_session_active do if attached session as l_session and then attached cookie.name as l_name then - delete_cookie_by_name (l_session.session_id, l_name) + api.delete_cookie_by_name (l_session.session_id, l_name) end end @@ -209,7 +210,7 @@ feature -- Options exist_session: is_session_active do if attached session as l_session then - Result := retrieve_cookies (l_session.session_id) + Result := api.retrieve_cookies (l_session.session_id) end end @@ -221,7 +222,7 @@ feature -- Options found: BOOLEAN do if attached session as l_session then - if attached retrieve_cookies (l_session.session_id) as l_list then + if attached api.retrieve_cookies (l_session.session_id) as l_list then from l_list.start until @@ -244,7 +245,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - Result := element_active (l_session.session_id) + Result := api.element_active (l_session.session_id) end end @@ -254,7 +255,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - frame (l_session.session_id, Void) + api.frame (l_session.session_id, Void) end end @@ -264,7 +265,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - frame (l_session.session_id, index.out) + api.frame (l_session.session_id, index.out) end end @@ -274,7 +275,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - frame (l_session.session_id, name) + api.frame (l_session.session_id, name) end end @@ -284,7 +285,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - frame (l_session.session_id, element.element) + api.frame (l_session.session_id, element.element) end end @@ -295,7 +296,7 @@ feature -- Target Locator exist_session: is_session_active do if attached session as l_session then - change_focus_window (l_session.session_id, name) + api.change_focus_window (l_session.session_id, name) end end @@ -308,7 +309,7 @@ feature -- Window do create Result if attached session as l_session then - Result := se_window_position (l_session.session_id, "current") + Result := api.window_position (l_session.session_id, "current") end end @@ -319,7 +320,7 @@ feature -- Window do create Result if attached session as l_session then - Result := size_window (l_session.session_id, "current") + Result := api.size_window (l_session.session_id, "current") end end @@ -329,7 +330,7 @@ feature -- Window exist_session: is_session_active do if attached session as l_session then - se_window_maximize (l_session.session_id, "current") + api.window_maximize (l_session.session_id, "current") end end @@ -339,7 +340,7 @@ feature -- Window exist_session: is_session_active do if attached session as l_session then - change_window_position (l_session.session_id, "current", target_position.x, target_position.y) + api.change_window_position (l_session.session_id, "current", target_position.x, target_position.y) end end @@ -349,7 +350,7 @@ feature -- Window exist_session: is_session_active do if attached session as l_session then - change_size_window (l_session.session_id, "current", target_size.width, target_size.height) + api.change_size_window (l_session.session_id, "current", target_size.width, target_size.height) end end @@ -361,38 +362,41 @@ feature -- Common exist_session: is_session_active do if attached session as l_session then - close_window (l_session.session_id) + api.close_window (l_session.session_id) end end - find_element (by: SE_BY) : detachable WEB_ELEMENT + find_element (by: STRING_32) : detachable WEB_ELEMENT -- Find the first WebElement using the given strategy. require exist_session : is_session_active + valid_strategy : (create {SE_BY}).is_valid_strategy (by) do if attached session as l_session then - + Result := api.search_element (l_session.session_id, by) end end - find_elements (by: SE_BY) : detachable LIST[WEB_ELEMENT] + find_elements (by: STRING_32) : detachable LIST[WEB_ELEMENT] -- Find all elements within the current page using the given mechanism.. require exist_session : is_session_active + valid_strategy : (create {SE_BY}).is_valid_strategy (by) do if attached session as l_session then - + Result := api.search_elements (l_session.session_id, by) end end + get_current_url : detachable STRING_32 -- Retrieve the URL of the current page. require exist_session : is_session_active do if attached session as l_session then - Result := retrieve_url (l_session.session_id) + Result := api.retrieve_url (l_session.session_id) end end @@ -402,7 +406,7 @@ feature -- Common exist_session : is_session_active do if attached session as l_session then - Result := page_source (l_session.session_id) + Result := api.page_source (l_session.session_id) end end @@ -412,7 +416,7 @@ feature -- Common exist_session : is_session_active do if attached session as l_session then - Result := page_title (l_session.session_id) + Result := api.page_title (l_session.session_id) end end @@ -423,7 +427,7 @@ feature -- Common exist_session : is_session_active do if attached session as l_session then - Result := retrieve_window_handle (l_session.session_id) + Result := api.retrieve_window_handle (l_session.session_id) end end @@ -432,7 +436,7 @@ feature -- Common exist_session : is_session_active do if attached session as l_session then - Result := retrieve_window_handles (l_session.session_id) + Result := api.retrieve_window_handles (l_session.session_id) end end @@ -440,5 +444,5 @@ feature -- Common feature {NONE} -- Implementation session: detachable SE_SESSION - + api : SE_JSON_WIRE_PROTOCOL end diff --git a/library/test/selenium/src/web_element.e b/library/test/selenium/src/web_element.e index 4ae9c1eb..9f31b697 100644 --- a/library/test/selenium/src/web_element.e +++ b/library/test/selenium/src/web_element.e @@ -7,21 +7,15 @@ note class WEB_ELEMENT create - make, - make2 + make feature - make2 ( an_element : STRING_32 ; an_api : like api; a_session_id : STRING_32) + make ( an_element : STRING_32 ; an_api : like api; a_session_id : STRING_32) do set_element (an_element) api := an_api session_id := a_session_id end - make ( an_element : STRING_32) - do - set_element (an_element) - create api.make - session_id := "" - end + feature -- Access element : STRING_32 --The opaque ID assigned to the element by the server. From 8535a8378c4d3adc0d337ce19acda9f1cefc7b05 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 3 May 2013 10:43:48 -0300 Subject: [PATCH 14/36] Improve the example, Added a new class WEB_DRIVER_WAIT, still under development. Update web driver, to define time outs. --- .../test/selenium/examples/example_search.e | 11 +++- library/test/selenium/src/web_driver.e | 8 +++ library/test/selenium/src/web_driver_wait.e | 54 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 library/test/selenium/src/web_driver_wait.e diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index 8ef8643f..27d089e0 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -11,6 +11,7 @@ feature -- Example search local web_driver : WEB_DRIVER + wait : WEB_DRIVER_WAIT do --Create a new instance of a Web driver create web_driver.make @@ -31,9 +32,15 @@ feature -- Example l_element.submit end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + create wait.make (web_driver,0) + wait.wait ("Eiffel Room") - if attached web_driver.get_page_tile as l_title then - print ("Page title is:" + l_title) + + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) end -- close the window diff --git a/library/test/selenium/src/web_driver.e b/library/test/selenium/src/web_driver.e index 05e97bce..2d840e36 100644 --- a/library/test/selenium/src/web_driver.e +++ b/library/test/selenium/src/web_driver.e @@ -441,6 +441,14 @@ feature -- Common end +feature {WEB_DRIVER, WEB_DRIVER_WAIT} + session_wait (duration : INTEGER_64) + do + if attached session as l_session then + api.set_session_timeouts_async_script (l_session.session_id, duration.as_integer_32) + end + end + feature {NONE} -- Implementation session: detachable SE_SESSION diff --git a/library/test/selenium/src/web_driver_wait.e b/library/test/selenium/src/web_driver_wait.e new file mode 100644 index 00000000..c08f2718 --- /dev/null +++ b/library/test/selenium/src/web_driver_wait.e @@ -0,0 +1,54 @@ +note + description: "Summary description for {WEB_DRIVER_WAIT}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WEB_DRIVER_WAIT + +create + make +feature {NONE} -- Initialization + make ( driver : like web_driver; a_duration : INTEGER_64) + do + web_driver := driver + duration := a_duration + initialize + ensure + driver_set : driver = web_driver + duration_set : duration = a_duration + end + +feature -- Access + wait (condition : STRING) + + local + found : BOOLEAN + do + condition.to_lower + from + if attached {STRING_32} web_driver.get_page_tile as l_title then + l_title.to_lower + found := l_title.has_substring (condition) + end + until + found + loop + if attached web_driver.get_page_tile as l_title then + l_title.to_lower + found := l_title.has_substring (condition) + + end + end + end + +feature {NONE}-- Implementation + web_driver : WEB_DRIVER + duration : INTEGER_64 + + initialize + do + web_driver.session_wait (duration) + end +end From b777e81ab10645c9047e8ae969c333e850b9baac Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 8 May 2013 10:10:11 -0300 Subject: [PATCH 15/36] Updated WEB_DRIVER_WAIT class, still need to be improved. Updated Readme and the example --- .../test/selenium/examples/example_search.e | 9 +-- library/test/selenium/readme.md | 65 ++++++++++++++++++- library/test/selenium/selenium-safe.ecf | 1 + .../src/protocol/executor/command_executor.e | 2 +- library/test/selenium/src/web_driver_wait.e | 20 ++++-- 5 files changed, 84 insertions(+), 13 deletions(-) diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index 27d089e0..c88fe4d1 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -35,8 +35,11 @@ feature -- Example if attached web_driver.get_page_tile as l_title then print ("%NPage title is:" + l_title) end - create wait.make (web_driver,0) - wait.wait ("Eiffel Room") + + -- Google's search is rendered dynamically with JavaScript. + -- Wait for the page to load, timeout after 10 seconds + create wait.make (web_driver,10) + wait.until_when ("Eiffel Room") if attached web_driver.get_page_tile as l_title then @@ -45,7 +48,5 @@ feature -- Example -- close the window web_driver.window_close - - end end diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md index 88828519..163cc476 100644 --- a/library/test/selenium/readme.md +++ b/library/test/selenium/readme.md @@ -2,7 +2,7 @@ Eiffel Selenium binding ================================================= ## Overview - +Selenium will help you test your web applications effectively and efficiently against a vast number of browsers and platforms. This client is a binding for the REST API interface defined in the WebDriver protocol http://code.google.com/p/selenium/wiki/JsonWireProtocol. WARNING this API is still under development, and maybe it will change @@ -20,8 +20,67 @@ WARNING this API is still under development, and maybe it will change java -jar selenium-server-standalone-2.32.0.jar -Dwebdriver.chrome.driver=%PATH_TO%\chromedriver.exe -Dwebdriver.ie.driver=%PATH_TO%\IEDriverServer.exe -## Getting Started +## Getting Started Selenium-WebDriver API (Eiffel binding only support (for now) RemoteWebDriver) +The examples and guide are based on http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example -TODO +WebDriver is a tool for automating web application testing, and in particular to verify that they work as expected. + + + class + EXAMPLE_SEARCH + + feature -- Example + search + local + web_driver : WEB_DRIVER + wait : WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to Google + web_driver.to_url ("http://www.google.com/") + + -- Find the text input element by its name + if attached web_driver.find_element ((create{SE_BY}).name ("q")) as l_element then + + -- Enter something to search for + l_element.send_keys(<<"Eiffel Room">>) + + -- Now submit the form. WebDriver will find the form for us from the element + l_element.submit + + end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + + -- Google's search is rendered dynamically with JavaScript. + -- Wait for the page to load, timeout after 10 seconds + create wait.make (web_driver,10) + wait.until_when ("Eiffel Room") + + + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + + -- close the window + web_driver.window_close + end + end + + +### Selenium-WebDriver API Commands and Operations + Fetching a Page + The first thing you’re likely to want to do with WebDriver is navigate to a page. + + web_driver.to_url ("http://www.google.com/") + + +### Locating Elements diff --git a/library/test/selenium/selenium-safe.ecf b/library/test/selenium/selenium-safe.ecf index 19b00f12..830e4039 100644 --- a/library/test/selenium/selenium-safe.ecf +++ b/library/test/selenium/selenium-safe.ecf @@ -9,6 +9,7 @@ + /EIFGENs$ diff --git a/library/test/selenium/src/protocol/executor/command_executor.e b/library/test/selenium/src/protocol/executor/command_executor.e index f21575af..b222f15a 100644 --- a/library/test/selenium/src/protocol/executor/command_executor.e +++ b/library/test/selenium/src/protocol/executor/command_executor.e @@ -3,7 +3,7 @@ note author: "" date: "$Date$" revision: "$Revision$" - EIS: "name=SELINIUM", "protocol=JSONWireProtocol", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#Commands" + EIS: "name=SELINIUM", "protocol=uri", "src=https://code.google.com/p/selenium/wiki/JsonWireProtocol#Commands" class COMMAND_EXECUTOR diff --git a/library/test/selenium/src/web_driver_wait.e b/library/test/selenium/src/web_driver_wait.e index c08f2718..c3a450d8 100644 --- a/library/test/selenium/src/web_driver_wait.e +++ b/library/test/selenium/src/web_driver_wait.e @@ -6,7 +6,8 @@ note class WEB_DRIVER_WAIT - +inherit + SHARED_EXECUTION_ENVIRONMENT create make feature {NONE} -- Initialization @@ -21,25 +22,34 @@ feature {NONE} -- Initialization end feature -- Access - wait (condition : STRING) - + -- create another feature to accept a predicate + until_when (condition : STRING) + --Evaluate the condition until it's true or timing out . local found : BOOLEAN + l_time1, l_time2 : TIME + l_duration : TIME_DURATION do + + create l_time1.make_now + create l_duration.make_by_seconds (duration.as_integer_32) + condition.to_lower from + create l_time2.make_now if attached {STRING_32} web_driver.get_page_tile as l_title then l_title.to_lower found := l_title.has_substring (condition) end until - found + found or + l_time2.relative_duration (l_time1).fine_seconds_count > l_duration.fine_seconds_count loop if attached web_driver.get_page_tile as l_title then l_title.to_lower found := l_title.has_substring (condition) - end + create l_time2.make_now end end From 15782c779568a5db89dedbb86becd04a292e5f19 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 8 May 2013 10:20:48 -0300 Subject: [PATCH 16/36] Update readme.md --- library/test/selenium/readme.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md index 163cc476..cf2ada04 100644 --- a/library/test/selenium/readme.md +++ b/library/test/selenium/readme.md @@ -20,7 +20,8 @@ WARNING this API is still under development, and maybe it will change java -jar selenium-server-standalone-2.32.0.jar -Dwebdriver.chrome.driver=%PATH_TO%\chromedriver.exe -Dwebdriver.ie.driver=%PATH_TO%\IEDriverServer.exe -## Getting Started Selenium-WebDriver API (Eiffel binding only support (for now) RemoteWebDriver) +## Getting Started Selenium-WebDriver API +(Eiffel binding only support (for now) RemoteWebDriver) The examples and guide are based on http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example WebDriver is a tool for automating web application testing, and in particular to verify that they work as expected. @@ -75,12 +76,20 @@ WebDriver is a tool for automating web application testing, and in particular to ### Selenium-WebDriver API Commands and Operations - Fetching a Page - The first thing you’re likely to want to do with WebDriver is navigate to a page. +##### Fetching a Page + The first thing you are likely to want to do with WebDriver is navigate to a page. web_driver.to_url ("http://www.google.com/") - - + +##### Locating UI Elements (WebElements) +###### By ID +Example of how to find an element that looks like this: + + + +Eiffel Code + web_driver.find_element ((create{SE_BY}).id ("head")) + ### Locating Elements From f8f1773d18fc05967529c81f85593457dc27215a Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 8 May 2013 10:21:23 -0300 Subject: [PATCH 17/36] Update readme.md --- library/test/selenium/readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md index cf2ada04..87f79afb 100644 --- a/library/test/selenium/readme.md +++ b/library/test/selenium/readme.md @@ -88,6 +88,7 @@ Example of how to find an element that looks like this: Eiffel Code + web_driver.find_element ((create{SE_BY}).id ("head")) ### Locating Elements From e5765d356fda6e919e9416e53298dbc1ce67faeb Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 8 May 2013 10:38:25 -0300 Subject: [PATCH 18/36] Updated documentation This documentation is based on Selinum http://docs.seleniumhq.org/ and adapted to the Eiffel implementation. --- library/test/selenium/readme.md | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md index 87f79afb..ec0ae389 100644 --- a/library/test/selenium/readme.md +++ b/library/test/selenium/readme.md @@ -91,6 +91,82 @@ Eiffel Code web_driver.find_element ((create{SE_BY}).id ("head")) + +###### By Name + +Example of how to find an element that looks like this: + + + +Eiffel Code + + web_driver.find_element ((create{SE_BY}).name ("cheese")) + +###### By Class Name + +Example of how to find an element that looks like this: + +
Cheddar
Gouda
+ +Eiffel Code + + web_driver.find_element ((create{SE_BY}).class_name ("cheese")) + +###### By CSS Selector + +Example of how to find an element that looks like this: + +
milkcheese
+ +Eiffel Code + + web_driver.find_element ((create{SE_BY}).css_selector ("#food span.dairy.aged")) + +###### By Link Text + +Example of how to find an element that looks like this: + + EWF> + +Eiffel Code + + web_driver.find_element ((create{SE_BY}).link_text ("EWF")) + + +###### By Partial Link Text + +Example of how to find an element that looks like this: + + search for ewf> + +Eiffel Code + + web_driver.find_element ((create{SE_BY}).partial_link_text ("ewf")) + + +###### By Tag Name + +Example of how to find an element that looks like this: + + + +Eiffel Code + + web_driver.find_element ((create{SE_BY}).tag_name ("iframe")) + + +###### By XPath + + +Example of how to find an element that looks like this: + + + +Eiffel Code + + web_driver.find_element ((create{SE_BY}).xpath ("//input")) + + ### Locating Elements From 2d3dadc85e246028fb591eb548e900a58da7142b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 8 May 2013 10:48:03 -0300 Subject: [PATCH 19/36] Update readme.md --- library/test/selenium/readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/library/test/selenium/readme.md b/library/test/selenium/readme.md index ec0ae389..19b30d70 100644 --- a/library/test/selenium/readme.md +++ b/library/test/selenium/readme.md @@ -76,6 +76,7 @@ WebDriver is a tool for automating web application testing, and in particular to ### Selenium-WebDriver API Commands and Operations +To learn more go to [Selenium documentation] (http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example) ##### Fetching a Page The first thing you are likely to want to do with WebDriver is navigate to a page. From 8db7d0daa3427a476dded94c0ecb6442875f0d49 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 10 May 2013 09:48:28 -0300 Subject: [PATCH 20/36] Initial implementation of HTTP RESPONSE EXPECTATIONS. Added a class to test http client with httpbin.org and expectations --- .../http_client_response_body_expectation.e | 48 +++++++ .../src/http_client_response_expectation.e | 27 ++++ ..._client_response_status_code_expectation.e | 42 ++++++ .../tests/test_http_client_with_httpbin.e | 121 ++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 library/network/http_client/src/http_client_response_body_expectation.e create mode 100644 library/network/http_client/src/http_client_response_expectation.e create mode 100644 library/network/http_client/src/http_client_response_status_code_expectation.e create mode 100644 library/network/http_client/tests/test_http_client_with_httpbin.e diff --git a/library/network/http_client/src/http_client_response_body_expectation.e b/library/network/http_client/src/http_client_response_body_expectation.e new file mode 100644 index 00000000..cf2039cf --- /dev/null +++ b/library/network/http_client/src/http_client_response_body_expectation.e @@ -0,0 +1,48 @@ +note + description: "Summary description for {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + HTTP_CLIENT_RESPONSE_BODY_EXPECTATION +inherit + HTTP_CLIENT_RESPONSE_EXPECTATION +create + make + +feature {NONE} -- Initializtion + make (a_body : detachable STRING_32) + -- Create and Initialize a body expectation + do + body := a_body + ensure + body_set : body ~ a_body + end + +feature -- Result expected + expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN + -- is `body expected' equals to resp.body? + do + if body = Void and then resp.body = Void then + Result := True + elseif attached resp.body as l_body and then attached body as c_body then + Result := l_body.is_case_insensitive_equal (c_body) + end + end + +feature -- Access + body : detachable STRING_32 + -- expected body + +;note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end diff --git a/library/network/http_client/src/http_client_response_expectation.e b/library/network/http_client/src/http_client_response_expectation.e new file mode 100644 index 00000000..43741ec6 --- /dev/null +++ b/library/network/http_client/src/http_client_response_expectation.e @@ -0,0 +1,27 @@ +note + description: "Summary description for {HTTP_CLIENT_RESPONSE_EXPECTATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + HTTP_CLIENT_RESPONSE_EXPECTATION + +feature + + expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN + deferred + end + +note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" + +end diff --git a/library/network/http_client/src/http_client_response_status_code_expectation.e b/library/network/http_client/src/http_client_response_status_code_expectation.e new file mode 100644 index 00000000..bf829c90 --- /dev/null +++ b/library/network/http_client/src/http_client_response_status_code_expectation.e @@ -0,0 +1,42 @@ +note + description: "Summary description for {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION +inherit + HTTP_CLIENT_RESPONSE_EXPECTATION + +create make + +feature {NONE} -- Initialization + make (a_status : INTEGER_32) + do + status := a_status + ensure + status_set : status = a_status + end + +feature -- Result Expected + expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN + -- is `status' expected equals to resp.status? + do + Result := status = resp.status + end + +feature -- Access + status : INTEGER_32 + -- status expected +;note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end diff --git a/library/network/http_client/tests/test_http_client_with_httpbin.e b/library/network/http_client/tests/test_http_client_with_httpbin.e new file mode 100644 index 00000000..e27d3570 --- /dev/null +++ b/library/network/http_client/tests/test_http_client_with_httpbin.e @@ -0,0 +1,121 @@ +note + description: "Summary description for {TEST_HTTP_CLIENT_WITH_HTTPBIN}." + author: "" + date: "$Date$" + revision: "$Revision$" + EIS: "name=HTTP TESTING", "protocol=uri", "src=http://httpbin.org/" + +class + TEST_HTTP_CLIENT_WITH_HTTPBIN + +inherit + EQA_TEST_SET + +feature + test_origin_ip + local + h: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + sess := h.new_session ("http://httpbin.org/") + resp := sess.get ("",void) + assert ("Expected Status 200 ok", resp.status = 200) + end + + test_status_code + local + h: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + sess := h.new_session ("http://httpbin.org/") + assert ("Expected Status 200 ok", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200)).expected(sess.get ("",void)) ) + end + + test_body + local + h: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + sess := h.new_session ("http://httpbin.org/") + assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) ) + end + + test_body_status + local + h: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + sess := h.new_session ("http://httpbin.org/") + --assert ("Expected no body", (create {HTTP_CLIENT_RESPONSE_STATUS_CODE_EXPECTATION}.make(200) + create {HTTP_CLIENT_RESPONSE_BODY_EXPECTATION}.make(expected_body_get)).expected(sess.get ("get",void)) ) + end + + + test_after_post_should_continue_working + local + h: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + resp : detachable HTTP_CLIENT_RESPONSE + l_location : detachable READABLE_STRING_8 + body : STRING + context : HTTP_CLIENT_REQUEST_CONTEXT + s: READABLE_STRING_8 + do + create h.make + sess := h.new_session ("http://httpbin.org/") + resp := sess.get ("",void) + assert ("Expected Status 200 ok", resp.status = 200) + + create context.make + context.headers.put ("text/plain;charset=UTF-8", "Content-Type") + resp := sess.post ("post", context, "testing post") + assert ("Expected Status 200 ok", resp.status = 200) + + sess := h.new_session ("http://httpbin.org/") + resp := sess.get ("",void) + assert ("Expected Status 200 ok", resp.status = 200) + + sess := h.new_session ("http://httpbin.org/") + resp := sess.get ("redirect/1",void) + assert ("Expected Status 200 ok", resp.status = 200) + + end + + + +expected_body_get : STRING_32 = "[ +{ + "url": "http://httpbin.org/get", + "args": {}, + "headers": { + "Host": "httpbin.org", + "Connection": "close", + "Accept": "*/*" + }, + "origin": "190.177.106.187" +} +]" +end From e0c3c783faa61d8116737e816329b5c46a812b36 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Mon, 13 May 2013 10:47:46 -0300 Subject: [PATCH 21/36] Updated selenium WEB_DRIVER_WAIT, the feature until_when now use a predicate. Updated the related example. --- .../test/selenium/examples/example_search.e | 10 ++++++++- library/test/selenium/examples/examples.ecf | 22 ++++++++++--------- library/test/selenium/src/web_driver_wait.e | 13 +++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index c88fe4d1..6835d9fe 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -39,7 +39,7 @@ feature -- Example -- Google's search is rendered dynamically with JavaScript. -- Wait for the page to load, timeout after 10 seconds create wait.make (web_driver,10) - wait.until_when ("Eiffel Room") + wait.until_when (agent expected_title (web_driver, "Eiffel Room")) if attached web_driver.get_page_tile as l_title then @@ -49,4 +49,12 @@ feature -- Example -- close the window web_driver.window_close end + + expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN + do + if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then + Result := True + end + end + end diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf index 6f6b52d7..ec7013d0 100644 --- a/library/test/selenium/examples/examples.ecf +++ b/library/test/selenium/examples/examples.ecf @@ -1,19 +1,21 @@ - - - + + + + /.git$ + /EIFGENs$ + /CVS$ + /.svn$ + - - - /EIFGENs$ - /CVS$ - /.svn$ - - + + + + diff --git a/library/test/selenium/src/web_driver_wait.e b/library/test/selenium/src/web_driver_wait.e index c3a450d8..e2bb4771 100644 --- a/library/test/selenium/src/web_driver_wait.e +++ b/library/test/selenium/src/web_driver_wait.e @@ -23,7 +23,7 @@ feature {NONE} -- Initialization feature -- Access -- create another feature to accept a predicate - until_when (condition : STRING) + until_when (condition : PREDICATE[ANY, TUPLE]) --Evaluate the condition until it's true or timing out . local found : BOOLEAN @@ -34,20 +34,17 @@ feature -- Access create l_time1.make_now create l_duration.make_by_seconds (duration.as_integer_32) - condition.to_lower from create l_time2.make_now - if attached {STRING_32} web_driver.get_page_tile as l_title then - l_title.to_lower - found := l_title.has_substring (condition) + if condition.item([]) then + found := True end until found or l_time2.relative_duration (l_time1).fine_seconds_count > l_duration.fine_seconds_count loop - if attached web_driver.get_page_tile as l_title then - l_title.to_lower - found := l_title.has_substring (condition) + if condition.item([]) then + found := True end create l_time2.make_now end From d344df6e7e3021aa1e565dfbf57e302ec0a6381b Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 14 May 2013 09:28:21 -0300 Subject: [PATCH 22/36] Added examples find by id, name and class. --- .../test/selenium/examples/example_search.e | 11 ++- library/test/selenium/examples/examples.ecf | 12 +++ .../selenium/examples/find_element_class.e | 84 +++++++++++++++++++ .../test/selenium/examples/find_element_id.e | 53 ++++++++++++ .../selenium/examples/find_element_name.e | 57 +++++++++++++ 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 library/test/selenium/examples/find_element_class.e create mode 100644 library/test/selenium/examples/find_element_id.e create mode 100644 library/test/selenium/examples/find_element_name.e diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index 6835d9fe..727e10a5 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -6,7 +6,16 @@ note class EXAMPLE_SEARCH - + inherit + ANY + redefine + default_create + end +feature + default_create + do + search + end feature -- Example search local diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf index ec7013d0..ae652ff0 100644 --- a/library/test/selenium/examples/examples.ecf +++ b/library/test/selenium/examples/examples.ecf @@ -18,4 +18,16 @@ + + + + + + + + + + + + diff --git a/library/test/selenium/examples/find_element_class.e b/library/test/selenium/examples/find_element_class.e new file mode 100644 index 00000000..32b59578 --- /dev/null +++ b/library/test/selenium/examples/find_element_class.e @@ -0,0 +1,84 @@ +note + description: "Using the class attribute to find elements. The class attribute is provided to apply CSS to an element." + +class + FIND_ELEMENT_CLASS + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + capabilities : SE_CAPABILITIES + do + -- Create desired capabilities + + create capabilities.make + capabilities.set_css_selectors_enabled (True) + capabilities.set_browser_name ("chrome") + + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome and capabilities + web_driver.start_session_chrome_with_desired_capabilities (capabilities) + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + + -- Find the user name, password element by its id and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + + -- After submit, there is an error message, and we still are in the same page + + -- Wait for the page to load, timeout after 10 seconds + create wait.make (web_driver,10) + wait.until_when (agent expected_title (web_driver, "User account")) + + + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).class_name ("title")) as l_title then + if attached l_title.get_text as l_text then + print ("%NDisplay:" + l_text) + + end + end + -- close the window + web_driver.window_close + end + + + expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN + do + if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then + Result := True + end + end + +end diff --git a/library/test/selenium/examples/find_element_id.e b/library/test/selenium/examples/find_element_id.e new file mode 100644 index 00000000..ebadbe5d --- /dev/null +++ b/library/test/selenium/examples/find_element_id.e @@ -0,0 +1,53 @@ +note + description: "Using the id attribute is the most preferable way to locate elements on a page." + +class + FIND_ELEMENT_ID + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + -- Find the user name, password element by its id and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + -- close the window + web_driver.window_close + end + +end diff --git a/library/test/selenium/examples/find_element_name.e b/library/test/selenium/examples/find_element_name.e new file mode 100644 index 00000000..1d8ed37f --- /dev/null +++ b/library/test/selenium/examples/find_element_name.e @@ -0,0 +1,57 @@ +note + description: "[ + Unlike find_element_id, find by name attribute may not be unique on a page. We might find multiple elements + with similar name attributes,if that happends, the first element on the page + will be selected, which may not be the element we are looking for. + ]" + +class + FIND_ELEMENT_NAME + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/user?destination=front") + + -- Find the user name, password element by its name and submit + if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("op")) as l_form then + l_user.send_keys (<<"test">>) + l_pass.send_keys (<<"pass">>) + l_form.submit + end + if attached web_driver.get_page_tile as l_title then + print ("%NPage title is:" + l_title) + end + -- close the window + web_driver.window_close + end + +end From 767989815919e004e28578418d40e0f51dfb42b9 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 14 May 2013 09:29:50 -0300 Subject: [PATCH 23/36] Move expectation classed under a expectation cluster, added a new expectation class for header. --- .../http_client_header_expectation.e | 51 +++++++++++++++++++ .../http_client_response_body_expectation.e | 0 .../http_client_response_expectation.e | 0 ..._client_response_status_code_expectation.e | 0 4 files changed, 51 insertions(+) create mode 100644 library/network/http_client/src/expectation/http_client_header_expectation.e rename library/network/http_client/src/{ => expectation}/http_client_response_body_expectation.e (100%) rename library/network/http_client/src/{ => expectation}/http_client_response_expectation.e (100%) rename library/network/http_client/src/{ => expectation}/http_client_response_status_code_expectation.e (100%) diff --git a/library/network/http_client/src/expectation/http_client_header_expectation.e b/library/network/http_client/src/expectation/http_client_header_expectation.e new file mode 100644 index 00000000..2d0eb5c0 --- /dev/null +++ b/library/network/http_client/src/expectation/http_client_header_expectation.e @@ -0,0 +1,51 @@ +note + description: "Summary description for {HTTP_CLIENT_HEADER_EXPECTATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + HTTP_CLIENT_HEADER_EXPECTATION +inherit + HTTP_CLIENT_RESPONSE_EXPECTATION +create + make + +feature {NONE} -- Initializtion + make (a_header: STRING_32; a_value : STRING) + -- Create and Initialize a header expectation + do + header := a_header + value := a_value + ensure + header_set : header ~ a_header + value_set : value ~ a_value + end + +feature -- Result expected + expected (resp: HTTP_CLIENT_RESPONSE): BOOLEAN + -- is `header name and value expected' equals to resp.header(name)? + do + if attached {READABLE_STRING_8} resp.header (header) as l_value then + if l_value.same_string (l_value) then + Result := true + end + end + end + +feature -- Access + header : STRING + -- header name + value : STRING + -- header value +;note + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end diff --git a/library/network/http_client/src/http_client_response_body_expectation.e b/library/network/http_client/src/expectation/http_client_response_body_expectation.e similarity index 100% rename from library/network/http_client/src/http_client_response_body_expectation.e rename to library/network/http_client/src/expectation/http_client_response_body_expectation.e diff --git a/library/network/http_client/src/http_client_response_expectation.e b/library/network/http_client/src/expectation/http_client_response_expectation.e similarity index 100% rename from library/network/http_client/src/http_client_response_expectation.e rename to library/network/http_client/src/expectation/http_client_response_expectation.e diff --git a/library/network/http_client/src/http_client_response_status_code_expectation.e b/library/network/http_client/src/expectation/http_client_response_status_code_expectation.e similarity index 100% rename from library/network/http_client/src/http_client_response_status_code_expectation.e rename to library/network/http_client/src/expectation/http_client_response_status_code_expectation.e From ad5b52f4e4f5718c9053ceed8b16aba487be0358 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Sat, 18 May 2013 23:12:37 -0300 Subject: [PATCH 24/36] Added new selenium locator examples. Fixed find_elements in WEB_DRIVER. --- library/test/selenium/examples/examples.ecf | 24 +++++ .../selenium/examples/find_element_child.e | 61 ++++++++++++ .../examples/find_element_css_selector.e | 66 +++++++++++++ .../selenium/examples/find_elements_links.e | 65 ++++++++++++ .../find_elements_links_by_partial_text.e | 71 +++++++++++++ .../examples/find_elements_links_by_text.e | 55 +++++++++++ library/test/selenium/examples/project.rc | 6 ++ .../selenium/examples/selenium_example.rc | 6 ++ .../src/protocol/executor/command_executor.e | 2 +- .../src/protocol/se_json_wire_protocol.e | 4 +- library/test/selenium/src/web_driver.e | 99 ++++++++++++------- library/test/selenium/src/web_driver_wait.e | 2 +- library/test/selenium/src/web_element.e | 10 +- 13 files changed, 428 insertions(+), 43 deletions(-) create mode 100644 library/test/selenium/examples/find_element_child.e create mode 100644 library/test/selenium/examples/find_element_css_selector.e create mode 100644 library/test/selenium/examples/find_elements_links.e create mode 100644 library/test/selenium/examples/find_elements_links_by_partial_text.e create mode 100644 library/test/selenium/examples/find_elements_links_by_text.e create mode 100644 library/test/selenium/examples/project.rc create mode 100644 library/test/selenium/examples/selenium_example.rc diff --git a/library/test/selenium/examples/examples.ecf b/library/test/selenium/examples/examples.ecf index ae652ff0..c01074d6 100644 --- a/library/test/selenium/examples/examples.ecf +++ b/library/test/selenium/examples/examples.ecf @@ -30,4 +30,28 @@ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/library/test/selenium/examples/find_element_child.e b/library/test/selenium/examples/find_element_child.e new file mode 100644 index 00000000..67e32b06 --- /dev/null +++ b/library/test/selenium/examples/find_element_child.e @@ -0,0 +1,61 @@ +note + description: "The WEB_ELEMENT class also supports find methods that find child elements." + +class + FIND_ELEMENT_CHILD + +inherit + + ANY + redefine + default_create + end + +create + default_create + +feature + + default_create + do + search + end + +feature -- Search by id + + search + local + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT + do + --Create a new instance of a Web driver + create web_driver.make + + -- Start session with chrome + web_driver.start_session_chrome + + -- Go to EiffelRoom login page + web_driver.to_url ("http://www.eiffelroom.com/") + + -- Find the element div with id page,and then we can find a child element div page-inner + --
+ --
+ -- + --
+ --