From dcdc700bac652f09acf66c4d059b00660f6a3a99 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Tue, 30 Apr 2013 10:19:34 -0300 Subject: [PATCH] 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.