From 63beaabfa0442061f4ca26852416f24b682406a0 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Wed, 29 May 2013 09:43:14 -0300 Subject: [PATCH] Added command POST /session/:sessionId/modifier Initial implementation of KeyBoard. Added Mouse class, but not implemented. --- .../test/selenium/examples/example_search.e | 69 +++++---- .../src/protocol/executor/command_executor.e | 11 ++ .../src/protocol/se_json_wire_protocol.e | 15 ++ .../protocol/se_json_wire_protocol_commands.e | 9 ++ library/test/selenium/src/se_key_constants.e | 128 ++++++++++++++++ library/test/selenium/src/se_key_stroke.e | 141 ++++-------------- library/test/selenium/src/se_keyboard.e | 63 ++++++++ library/test/selenium/src/se_mouse.e | 11 ++ library/test/selenium/src/web_driver.e | 3 +- 9 files changed, 302 insertions(+), 148 deletions(-) create mode 100644 library/test/selenium/src/se_key_constants.e create mode 100644 library/test/selenium/src/se_keyboard.e create mode 100644 library/test/selenium/src/se_mouse.e diff --git a/library/test/selenium/examples/example_search.e b/library/test/selenium/examples/example_search.e index 727e10a5..3a42d4f3 100644 --- a/library/test/selenium/examples/example_search.e +++ b/library/test/selenium/examples/example_search.e @@ -6,60 +6,63 @@ note class EXAMPLE_SEARCH - inherit - ANY + +inherit + + ANY redefine default_create end + feature - default_create + + default_create do search end + feature -- Example + search local - web_driver : WEB_DRIVER - wait : WEB_DRIVER_WAIT + web_driver: WEB_DRIVER + wait: WEB_DRIVER_WAIT do - --Create a new instance of a Web driver - create web_driver.make + --Create a new instance of a Web driver + create web_driver.make - -- Start session with chrome - web_driver.start_session_chrome + -- Start session with chrome + web_driver.start_session_chrome - -- Go to Google - web_driver.to_url ("http://www.google.com/") + -- 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 + -- 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">>) + -- 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 + -- 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 - 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 (agent expected_title(web_driver, "Eiffel Room")) + 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 (agent expected_title (web_driver, "Eiffel Room")) - - - if attached web_driver.get_page_tile as l_title then - print ("%NPage title is:" + l_title) - end - - -- close the window + -- close the window web_driver.window_close end - expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN + 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 diff --git a/library/test/selenium/src/protocol/executor/command_executor.e b/library/test/selenium/src/protocol/executor/command_executor.e index fd29528a..891d29d5 100644 --- a/library/test/selenium/src/protocol/executor/command_executor.e +++ b/library/test/selenium/src/protocol/executor/command_executor.e @@ -700,6 +700,17 @@ feature -- Commands Result := new_response (a_session_id, resp) end + modifier (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_modifier (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 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 af84773b..a0cb274a 100644 --- a/library/test/selenium/src/protocol/se_json_wire_protocol.e +++ b/library/test/selenium/src/protocol/se_json_wire_protocol.e @@ -1736,6 +1736,21 @@ feature -- Commands end end + + modifier (a_session_id: STRING_32; data: STRING) + -- POST /session/:sessionId/modifier + -- Not documented + -- For info look + -- http://grepcode.com/file/repo1.maven.org/maven2/org.seleniumhq.selenium/selenium-remote-driver/2.0.0/org/openqa/selenium/remote/HttpCommandExecutor.java?av=h#HttpCommandExecutor + local + resp : SE_RESPONSE + do + if commnad_executor.is_available then + resp := commnad_executor.modifier (a_session_id, data) + check_response (resp) + end + end + 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). 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 a1ba2bd7..574beb4d 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 @@ -485,6 +485,15 @@ feature Result.replace_substring_all ("$sessionId", sessionId) end + + cmd_session_modifier_tmpl : STRING = "/session/$sessionId/modifier" + cmd_session_modifier (sessionId: STRING_32): STRING_32 + do + create Result.make_from_string (cmd_session_modifier_tmpl) + Result.replace_substring_all ("$sessionId", sessionId) + end + + cmd_session_click_tmpl: STRING = "session/$sessionId/click" cmd_session_click (sessionId: STRING_32): STRING_32 diff --git a/library/test/selenium/src/se_key_constants.e b/library/test/selenium/src/se_key_constants.e new file mode 100644 index 00000000..124c3bf9 --- /dev/null +++ b/library/test/selenium/src/se_key_constants.e @@ -0,0 +1,128 @@ +note + description: "Summary description for {SE_KEY_CONSTANTS}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_KEY_CONSTANTS + +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_key_stroke.e b/library/test/selenium/src/se_key_stroke.e index c8b18370..6bbf75d3 100644 --- a/library/test/selenium/src/se_key_stroke.e +++ b/library/test/selenium/src/se_key_stroke.e @@ -7,123 +7,38 @@ note class SE_KEY_STROKE +inherit + + SE_KEY_CONSTANTS + +create + make + +feature {NONE} -- Initialization + + make (a_key: STRING_32) + require + is_valid: keys.has (a_key) + do + set_key (a_key) + ensure + end + feature -- Access - Null_key: STRING_32 = "\uE000" + key: STRING_32 + -- current key - Cancel_key: STRING_32 = "\uE001" +feature -- Change Element - 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 := <> + set_key (a_key: STRING_32) + --Set `key' to `a_key' + require + is_valid: keys.has (a_key) + do + key := a_key + ensure + key_set: key = a_key end end diff --git a/library/test/selenium/src/se_keyboard.e b/library/test/selenium/src/se_keyboard.e new file mode 100644 index 00000000..1f834376 --- /dev/null +++ b/library/test/selenium/src/se_keyboard.e @@ -0,0 +1,63 @@ +note + description: "Objects representing basic keyboards operations" + author: "" + date: "$Date$" + revision: "$Revision$" + +class + SE_KEYBOARD + +create + make +feature {NONE} -- Initialization + make ( a_web_driver : like driver) + -- Create an object se_keyboard with his driver + do + driver := a_web_driver + ensure + web_driver_set : driver = a_web_driver + end + +feature --Access + send_keys (keys : ARRAY[STRING_32]) + do + if attached driver.active_element as l_active_element then + l_active_element.send_keys (keys) + end + end + + press_key ( key : SE_KEY_STROKE) + local + l_data : STRING_32 + do + create l_data.make_from_string (json_template) + l_data.replace_substring_all ("$value", key.key) + l_data.replace_substring_all ("$boolean", "True") + if attached driver.session as l_session then + driver.api.modifier (l_session.session_id, l_data) + end + end + + release_key ( key : SE_KEY_STROKE) + local + l_data : STRING_32 + do + create l_data.make_from_string (json_template) + l_data.replace_substring_all ("$value", key.key) + l_data.replace_substring_all ("$boolean", "False") + if attached driver.session as l_session then + driver.api.modifier (l_session.session_id, l_data ) + end + end + + + +feature {NONE} -- Implementation + driver : WEB_DRIVER + -- web_driver + + json_template : String = "[ + {"value" :"$value", + "isdown" : $boolean} + ]" +end diff --git a/library/test/selenium/src/se_mouse.e b/library/test/selenium/src/se_mouse.e new file mode 100644 index 00000000..86966c06 --- /dev/null +++ b/library/test/selenium/src/se_mouse.e @@ -0,0 +1,11 @@ +note + description: "Summary description for {SE_MOUSE}." + author: "" + date: "$Date$" + revision: "$Revision$" + + class + SE_MOUSE + + end + \ No newline at end of file diff --git a/library/test/selenium/src/web_driver.e b/library/test/selenium/src/web_driver.e index 8bc3c221..0f77efdf 100644 --- a/library/test/selenium/src/web_driver.e +++ b/library/test/selenium/src/web_driver.e @@ -476,12 +476,11 @@ feature {WEB_DRIVER, WEB_DRIVER_WAIT} end end -feature {NONE} -- Implementation +feature {SE_KEYBOARD} -- Implementation session: detachable SE_SESSION status: BOOLEAN - api: SE_JSON_WIRE_PROTOCOL end