Added a simple search example.

Updated web_driver, use the API as delegation instead of inheritance.
Updated web_element class.
This commit is contained in:
jvelilla
2013-04-30 10:19:34 -03:00
parent 31c2be768f
commit dcdc700bac
7 changed files with 121 additions and 74 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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.