From c7e6fe38fbaebbfad6ab8bf7313eea18a43e94de Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 23 Apr 2013 09:09:57 -0300 Subject: [PATCH] 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)