From 9e8548d65a9217ea97dba59c0b70b4a06c509054 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 23 Apr 2013 08:26:02 -0300 Subject: [PATCH] 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.