Fixed feature typo, improved commands, added AutoTest
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="encoding" location="$ISE_LIBRARY\library\encoding\encoding-safe.ecf"/>
|
||||
<library name="http_client" location="$EIFFEL_LIBRARY\EWF\library\network\http_client\http_client-safe.ecf"/>
|
||||
<library name="json" location="$EIFFEL_LIBRARY\EWF\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||
<cluster name="src" location=".\src\" recursive="true">
|
||||
|
||||
@@ -52,7 +52,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_status)
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,10 +64,16 @@ feature -- Commands
|
||||
do
|
||||
create Result.make_empty
|
||||
resp := execute_post (cmd_new_session, capabilities)
|
||||
if attached resp.header ("Location") as l_location then
|
||||
resp := http_new_session (l_location).get ("", context_executor)
|
||||
if not (resp.status >= 400) then
|
||||
if attached resp.header ("Location") as l_location then
|
||||
resp := http_new_session (l_location).get ("", context_executor)
|
||||
if attached resp.body as l_body then
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -81,7 +87,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_sessions)
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,7 +100,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_by_id (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -105,13 +111,13 @@ feature -- Commands
|
||||
resp: HTTP_CLIENT_RESPONSE
|
||||
do
|
||||
create Result.make_empty
|
||||
resp := execute_delete (cmd_session_by_id (cmd_session_by_id (session_id)))
|
||||
resp := execute_delete (cmd_session_by_id ( session_id ))
|
||||
if resp.status = 204 then
|
||||
Result.set_status (0)
|
||||
Result.set_session_id (session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -129,7 +135,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -147,7 +153,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -166,7 +172,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -181,7 +187,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_window_handle (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -194,7 +200,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_window_handles (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -207,7 +213,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_url (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,7 +230,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -242,7 +248,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -260,7 +266,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -278,7 +284,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -310,7 +316,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_screenshot (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -323,7 +329,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_ime_available (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -336,7 +342,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_ime_active_engine (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -349,7 +355,7 @@ feature -- Commands
|
||||
create Result.make_empty
|
||||
resp := execute_get (cmd_session_ime_activated (session_id))
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -366,7 +372,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -384,7 +390,7 @@ feature -- Commands
|
||||
Result.set_session_id (a_session_id)
|
||||
else
|
||||
if attached resp.body as l_body then
|
||||
Result := build_response (l_body)
|
||||
Result := new_response (l_body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -407,11 +413,10 @@ feature {NONE} -- Implementation
|
||||
Result := http_session.delete (command_name, context_executor)
|
||||
end
|
||||
|
||||
build_response (a_message: STRING_32): SE_RESPONSE
|
||||
new_response (a_message: STRING_32): SE_RESPONSE
|
||||
do
|
||||
create Result.make_empty
|
||||
initialize_converters (json)
|
||||
if attached {SE_RESPONSE} json.object_from_json (a_message, "SE_RESPONSE") as l_response then
|
||||
if attached json_to_se_response(a_message) as l_response then
|
||||
Result := l_response
|
||||
end
|
||||
Result.set_json_response (a_message)
|
||||
|
||||
@@ -31,7 +31,7 @@ feature -- Conversion
|
||||
if attached {STRING_32} json_to_object (j.item (session_key), Void) as l_item then
|
||||
Result.set_session_id(l_item)
|
||||
end
|
||||
if attached {INTEGER_32} json_to_object (j.item (status_key), Void) as l_item then
|
||||
if attached {INTEGER_8} json_to_object (j.item (status_key), Void) as l_item then
|
||||
Result.set_status(l_item)
|
||||
end
|
||||
if attached {JSON_VALUE} j.item (value_key) as l_item then
|
||||
|
||||
@@ -58,6 +58,19 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
json_to_se_response (post: STRING_32): detachable SE_RESPONSE
|
||||
local
|
||||
parser: JSON_PARSER
|
||||
do
|
||||
initialize_converters (json)
|
||||
create parser.make_parser (post)
|
||||
if attached parser.parse_object as st and parser.is_parsed then
|
||||
if attached {SE_RESPONSE} json.object (st, "SE_RESPONSE") as l_response then
|
||||
Result := l_response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initialize_converters (j: like json)
|
||||
-- Initialize json converters
|
||||
do
|
||||
|
||||
@@ -96,7 +96,7 @@ feature -- Commands
|
||||
check_response (response)
|
||||
if not has_error then
|
||||
if attached response.json_response as r_value then
|
||||
Result := build_session (r_value, "session")
|
||||
Result := new_session (r_value, "session")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -127,7 +127,7 @@ feature -- Commands
|
||||
index > l_json_array.count
|
||||
loop
|
||||
if attached {JSON_OBJECT} l_json_array.i_th (index) as json_obj then
|
||||
if attached build_session (json_obj.representation, "sessions") as l_session then
|
||||
if attached new_session (json_obj.representation, "sessions") as l_session then
|
||||
Result.force (l_session)
|
||||
end
|
||||
end
|
||||
@@ -153,7 +153,7 @@ feature -- Commands
|
||||
check_response (response)
|
||||
if not has_error then
|
||||
if attached response.json_response as r_value then
|
||||
Result := build_session (r_value, "session")
|
||||
Result := new_session (r_value, "session")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1602,18 +1602,24 @@ feature {NONE} -- Implementation
|
||||
|
||||
commnad_executor: COMMAND_EXECUTOR
|
||||
|
||||
build_session (value: STRING_32; to: STRING_32): detachable SE_SESSION
|
||||
new_session (value: STRING_32; to: STRING_32): detachable SE_SESSION
|
||||
local
|
||||
l_rep : STRING_32
|
||||
do
|
||||
if to.is_case_insensitive_equal ("session") then
|
||||
if attached {JSON_OBJECT} string_to_json (value) as l_value then
|
||||
if attached l_value.item ("sessionId") as ls and then attached l_value.item ("value") as lv and then attached json_to_se_capabilities (lv.representation) as lc then
|
||||
create Result.make (ls.representation, lc)
|
||||
l_rep := ls.representation
|
||||
l_rep.replace_substring_all ("%"", "")
|
||||
create Result.make (l_rep, lc)
|
||||
end
|
||||
end
|
||||
elseif to.is_case_insensitive_equal ("sessions") then
|
||||
if attached {JSON_OBJECT} string_to_json (value) as l_value then
|
||||
if attached l_value.item ("id") as ls and then attached l_value.item ("capabilities") as lv and then attached json_to_se_capabilities (lv.representation) as lc then
|
||||
create Result.make (ls.representation, lc)
|
||||
l_rep := ls.representation
|
||||
l_rep.replace_substring_all ("%"", "")
|
||||
create Result.make (l_rep, lc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,8 @@ note
|
||||
class
|
||||
SE_JSON_WIRE_PROTOCOL_COMMANDS
|
||||
|
||||
|
||||
feature
|
||||
|
||||
cmd_ping : STRING = ""
|
||||
--GET / expected a 200 ok
|
||||
|
||||
@@ -29,12 +29,14 @@ feature
|
||||
end
|
||||
|
||||
|
||||
cmd_session_timeouts_tmpl : STRING ="session/$id/timeouts"
|
||||
cmd_session_timeouts_tmpl : STRING_32 ="[
|
||||
session/$id/timeouts
|
||||
]"
|
||||
|
||||
cmd_session_timeouts (id: STRING_32): STRING_32
|
||||
cmd_session_timeouts (id: STRING_32):STRING_32
|
||||
do
|
||||
create Result.make_from_string (cmd_session_timeouts_tmpl)
|
||||
Result.replace_substring_all ("$id", id)
|
||||
Result.replace_substring_all ("$id",id)
|
||||
end
|
||||
|
||||
cmd_session_timeouts_async_script_tmpl : STRING ="session/$id/timeouts/async_script"
|
||||
|
||||
@@ -18,6 +18,7 @@ feature {NONE} -- Initialization
|
||||
local
|
||||
web_driver: SE_JSON_WIRE_PROTOCOL
|
||||
capabilities : SE_CAPABILITIES
|
||||
timeout : SE_TIMEOUT_TYPE
|
||||
do
|
||||
-- check if the selenium Remote WebDriver is up and running.
|
||||
create web_driver.make
|
||||
@@ -39,6 +40,8 @@ feature {NONE} -- Initialization
|
||||
capabilities.set_browser_name ("chrome")
|
||||
if attached web_driver.create_session_with_desired_capabilities (capabilities) as l_session then
|
||||
print ("%NSessionId:" + l_session.session_id)
|
||||
create timeout.make_empty
|
||||
web_driver.set_session_timeouts (l_session.session_id, timeout)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http_client" location="$EIFFEL_LIBRARY\EWF\library\network\http_client\http_client-safe.ecf"/>
|
||||
<library name="selenium" location="..\selenium-safe.ecf"/>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
|
||||
<cluster name="test" location=".\" recursive="true">
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
|
||||
125
library/test/selenium/test/test_json_wire_protocol.e
Normal file
125
library/test/selenium/test/test_json_wire_protocol.e
Normal file
@@ -0,0 +1,125 @@
|
||||
note
|
||||
description: "[
|
||||
Eiffel tests that can be executed by testing tool.
|
||||
]"
|
||||
author: "EiffelStudio test wizard"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
testing: "type/manual"
|
||||
|
||||
class
|
||||
TEST_JSON_WIRE_PROTOCOL
|
||||
|
||||
inherit
|
||||
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare,
|
||||
on_clean
|
||||
end
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
local
|
||||
capabilities: SE_CAPABILITIES
|
||||
do
|
||||
create capabilities.make
|
||||
capabilities.set_browser_name ("chrome")
|
||||
if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then
|
||||
session_id := l_session.session_id
|
||||
end
|
||||
end
|
||||
|
||||
on_clean
|
||||
-- <Precursor>
|
||||
do
|
||||
if attached session_id as l_session_id then
|
||||
wire_protocol.delete_session (session_id)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_status
|
||||
--
|
||||
do
|
||||
if attached {SE_STATUS} wire_protocol.status as l_status then
|
||||
assert ("No error", not wire_protocol.has_error)
|
||||
assert ("Expected status 0", l_status.status = 0)
|
||||
assert ("Expected sessionId", l_status.session_id = Void)
|
||||
end
|
||||
end
|
||||
|
||||
test_seleniun_server_host_not_available
|
||||
--
|
||||
local
|
||||
l_wire_protocol: SE_JSON_WIRE_PROTOCOL
|
||||
do
|
||||
create l_wire_protocol.make_with_host ("http://127.0.0.1:4443/wd/hub/status")
|
||||
assert ("expected void", l_wire_protocol.status = Void)
|
||||
end
|
||||
|
||||
test_create_valid_new_session
|
||||
local
|
||||
capabilities: SE_CAPABILITIES
|
||||
do
|
||||
create capabilities.make
|
||||
capabilities.set_browser_name ("chrome")
|
||||
if attached wire_protocol.create_session_with_desired_capabilities (capabilities) as l_session then
|
||||
assert ("No error", not wire_protocol.has_error)
|
||||
end
|
||||
end
|
||||
|
||||
test_create_invalid_new_session
|
||||
local
|
||||
capabilities: SE_CAPABILITIES
|
||||
session: detachable SE_SESSION
|
||||
do
|
||||
create capabilities.make
|
||||
capabilities.set_browser_name ("invalid")
|
||||
session := wire_protocol.create_session_with_desired_capabilities (capabilities)
|
||||
assert ("Expected error", wire_protocol.has_error)
|
||||
assert ("Expected void", session = Void)
|
||||
end
|
||||
|
||||
test_retrieve_sessions
|
||||
local
|
||||
sessions: detachable LIST [SE_SESSION]
|
||||
do
|
||||
sessions := wire_protocol.sessions
|
||||
assert ("Not void", sessions /= Void)
|
||||
assert ("One or more items:", sessions.count >= 1)
|
||||
end
|
||||
|
||||
|
||||
test_delete_session
|
||||
local
|
||||
capabilities: SE_CAPABILITIES
|
||||
session : detachable SE_SESSION
|
||||
pre_session, post_session : INTEGER
|
||||
do
|
||||
-- if attached wire_protocol.sessions as l_sessions then
|
||||
-- pre_session := l_sessions.count
|
||||
-- end
|
||||
|
||||
-- if attached session_id as l_session_id then
|
||||
-- wire_protocol.delete_session (session_id)
|
||||
-- end
|
||||
|
||||
-- if attached wire_protocol.sessions as l_sessions then
|
||||
-- post_session := l_sessions.count
|
||||
-- end
|
||||
|
||||
-- assert ("After delete Pre sesssion - 1 is equal to post_session", (pre_session - 1) = post_session)
|
||||
end
|
||||
|
||||
feature {NONE}-- Implementation
|
||||
wire_protocol: SE_JSON_WIRE_PROTOCOL
|
||||
once
|
||||
create Result.make
|
||||
end
|
||||
|
||||
session_id: detachable STRING_32
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user