<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,8 @@
-* XXX
-** Internal
-- Change selenium_api and selenium_session build
-- Edoc
+*rXX
+** Changes
+- Add an option to set an timeout on HTTP requests
+- Change the return value of selenium:cmd; 'failed' become 'error'
+*r83
 * 20080913
 ** Bug Fix:
 - Remove R12 specific APIs introduced with 20080907</diff>
      <filename>lib/selenium_remote/CHANGES</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,14 @@
-%%% Copyright(c) 2007,2008 Nicolas Charpentier
+%%% Copyright(c) 2007-2009 Nicolas Charpentier
 %%% All rights reserved.
 %%% See file $TOP_DIR/COPYING.
 
 %% @author Nicolas Charpentier &lt;open_source@charpi.net&gt; [http://charpi.net]
-%% @copyright 2007,2008 Nicolas Charpentier
+%% @copyright 2007-2009 Nicolas Charpentier
 
 -module(selenium).
 
+-export([set_options/2]).
+
 -export([start/4, stop/1]).
 -export([launch_session/4]).
 -export([cmd/2, cmd/3]).
@@ -18,20 +20,20 @@
 -export([parse_body/2]).
 -export([command_to_string/1]).
 
--type(selenium_session() :: tuple()).
--type(selenium_command_result() :: {ok, none} | {ok, term()} | {failed, term()}).
--type(module_instance() :: term()).
+-type(selenium_session() :: {string(), integer(), any(), [term()]}).
+-type(selenium_command_result() :: {ok, none | [any()] |  number()} | {error, any()}).
+-type(module_instance() :: any()).
+
+%% @doc Set HTTP options that will be used for each commands.
+-spec(set_options(selenium_session(), [term()]) -&gt; selenium_session()).
+set_options ({H, P, Id, _ }, Options) when is_list(Options), is_list(H), is_integer(P) -&gt;
+    {H, P , Id, Options}.
 
 %% @doc Starts a selenium session which can be used with cmd/3 and cmd_array/3
 %% functions.
 -spec(start(Host :: string(), integer(), string(), string()) -&gt; selenium_session()).
 start(Host, Port, Command, URL) -&gt;
-    application:start(inets),
-    Get_new_browser = {getNewBrowserSession, [Command, URL]},
-    RequestUrl = build_request_without_id(Host, Port, Get_new_browser),
-    Result = send_request(RequestUrl),
-    {ok, Body} = parse_body(standard, Result),
-    {Host, Port, normalize_session_id(Body)}.
+    start(Host, Port, Command, URL, []).
 
 %% @doc Returns a module selenium_session which can be used directly.
 -spec(launch_session(string(),integer(),string(),string()) -&gt; module_instance()).
@@ -73,6 +75,17 @@ cmd_array(Session, Command) -&gt;
 cmd_array(Session, Command, Params) -&gt;
     cmd(Session, Command, Params, fun result_as_array/1).
 
+%% @private
+start(Host, Port, Command, URL, HTTP_options) -&gt;
+    application:start(inets),
+    Get_new_browser = {getNewBrowserSession, [Command, URL]},
+    RequestUrl = build_request_without_id(Host, Port, Get_new_browser),
+    
+    Result = send_request(RequestUrl, HTTP_options),
+    {ok, Body} = result_as_standard(Result),
+    {Host, Port, normalize_session_id(Body), HTTP_options}.
+
+
 run(Config, Commands) when is_list(Config) -&gt;
     Session = launch_command_session(Config),
     Excecute = fun(Command) -&gt; run_command(Session, Command) end,
@@ -81,9 +94,9 @@ run(Config, Commands) when is_list(Config) -&gt;
     Results.
 
 cmd(Session, Command, Params, Fun) when is_list(Params) -&gt;
-    {Host, Port, Id} = Session,
+    {Host, Port, Id, HTTP_options} = Session,
     Request = build_request(Host, Port, Id, {Command, Params}),
-    Result = send_request(Request),
+    Result = send_request(Request, HTTP_options),
     Fun(Result).
 
 launch_command_session(Config) -&gt;
@@ -131,7 +144,7 @@ request_url(Host, Port) -&gt;
 
 %% @private
 build_request_without_id(Host, Port, Command)  -&gt;
-    {request_url(Host, Port),command_to_string(Command)}.
+    {request_url(Host, Port), command_to_string(Command)}.
 
 %% @private
 build_request(Host, Port, Id, Command) -&gt;
@@ -140,7 +153,7 @@ build_request(Host, Port, Id, Command) -&gt;
 
 %% @private
 command_to_string({Command, Parameters}) when is_atom(Command), 
-                                               is_list(Parameters)-&gt;
+					      is_list(Parameters)-&gt;
     Build_parameter = fun(X, {Index,Acc}) -&gt;
                               {Index+1,
                                Acc ++ &quot;&amp;&quot; ++ integer_to_list(Index)
@@ -157,12 +170,11 @@ server_url(Host, Port) when is_integer(Port) -&gt;
     Port_value = integer_to_list(Port),
     &quot;http://&quot; ++ Host ++ &quot;:&quot; ++ Port_value ++ Driver_url.
 
-send_request({Url, Body}) -&gt;
+send_request({Url, Body}, HTTP_options) -&gt;
     Content_type = &quot;application/x-www-form-urlencoded; charset=utf-8&quot;,
     Request = {Url, [], Content_type, Body},
-    Result = http:request(post, Request, [], []),
-    {ok, {{_,200,_}, _, Response}} = Result,
-    Response.
+    Result = http:request(post, Request, HTTP_options, []),
+    Result.
 
 %% @private
 parse_body(_, &quot;OK&quot;) -&gt;
@@ -170,7 +182,7 @@ parse_body(_, &quot;OK&quot;) -&gt;
 parse_body(Type, &quot;OK,&quot; ++ Rest) -&gt;
     {ok, parse_body_value(Type, Rest)};
 parse_body(_, X) -&gt;
-    {failed, X}.
+    {error, X}.
 
 parse_body_value(Type, [$-|T]) -&gt;
     parse_number(Type, T, [$-],number);
@@ -269,9 +281,13 @@ normalize_session_id(SessionId) when is_list(SessionId) -&gt;
 normalize_session_id(SessionId) -&gt;
     integer_to_list(SessionId).
 
-result_as_array(Result) -&gt;
-    parse_body(array, Result).
+result_as_array({error, _} = Error) -&gt;
+    Error;
+result_as_array({ok, {{_,200,_}, _, Response}}) -&gt;
+    parse_body(array, Response).
 
-result_as_standard(Result) -&gt;
-    parse_body(standard, Result).
+result_as_standard({error, _} = Error) -&gt;
+    Error;
+result_as_standard({ok, {{_,200,_}, _, Response}}) -&gt;
+    parse_body(standard, Response).
 </diff>
      <filename>lib/selenium_remote/src/selenium.erl</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,7 @@
 
 all_test_() -&gt;
     [{inparallel, 2, [{timeout, 60, fun start_session/0},
+		      {timeout, 60, fun session_with_timeout/0},
 		      {timeout, 60, fun high_level/0}]}].
 
 fast_test_() -&gt;
@@ -153,7 +154,7 @@ parse_body_test () -&gt;
                    {Input,Expected} = {Input,selenium:parse_body (standard, Input)}
            end,
     lists:map (Test,
-               [{{failed,&quot;toto&quot;},&quot;toto&quot;},
+               [{{error,&quot;toto&quot;},&quot;toto&quot;},
                 {{ok,none},&quot;OK&quot;},
                 {{ok,[]},&quot;OK,&quot;},
                 {{ok,1} ,&quot;OK,01&quot;},
@@ -176,7 +177,6 @@ parse_body_test () -&gt;
 
 start_session () -&gt;
     URL = &quot;http://localhost:4444&quot;,
-    io:format(&quot;Test~n&quot;),
     Session = selenium: start (?HOST,
                                ?PORT,
                                ?COMMAND,
@@ -184,6 +184,17 @@ start_session () -&gt;
     selenium: stop (Session),
     ok.
 
+session_with_timeout () -&gt;
+    URL = &quot;http://localhost:4444&quot;,
+    HTTP_options = [{timeout, 1}],
+
+    Session = selenium: start (?HOST, ?PORT, ?COMMAND, URL),
+    Session_with_timeout = selenium: set_options (Session, HTTP_options),
+    Start_url = &quot;/selenium-server/tests/html/test_click_page1.html&quot;,
+    {error, timeout} = selenium:cmd (Session_with_timeout, open, [Start_url]),
+    selenium: stop (Session_with_timeout),
+    ok.
+    
 high_level () -&gt;
     Config = selenium_config (),
     Commands = commands (),</diff>
      <filename>lib/selenium_remote/test/selenium_tests.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>75f077395c1f4bfd519322a52edd026e0a40eab2</id>
    </parent>
  </parents>
  <author>
    <name>charpi</name>
    <email>charpi@3ab005ec-33ed-11dd-9e78-a92e4af85449</email>
  </author>
  <url>http://github.com/charpi/erl_selenium/commit/55a49f0745dab1c1952ad09f83079aba940f13ea</url>
  <id>55a49f0745dab1c1952ad09f83079aba940f13ea</id>
  <committed-date>2009-07-04T01:26:52-07:00</committed-date>
  <authored-date>2009-07-04T01:26:52-07:00</authored-date>
  <message>Add timeout on http request</message>
  <tree>25d29e6b5a9de41b3ef8877cae0f2fd2d6e365fb</tree>
  <committer>
    <name>charpi</name>
    <email>charpi@3ab005ec-33ed-11dd-9e78-a92e4af85449</email>
  </committer>
</commit>
