<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2013, Quviq AB
%%%
%%% @doc {@link gen_server} wrapper for a WebDriver session.
%%%
%%% A WebDriver session (normally the interaction with one browser instance) is associated
%%% to a <tt>SessionId</tt>, and the <tt>URI</tt> of the WebDriver server-side. It quickly
%%% gets painful to carry the id and the URL around, therefore this wrapper module was
%%% created. By using this module, each session is associated to a name (an {@link
%%% atom()}), simplifiying issuing a WebDriver command.
%%%
%%% The implementation is a {@link gen_server}, which keeps the SessionId and the URL (and
%%% a timeout) in its state. A typical interaction with this module could be:
%%%<pre>
%%% webdrv_session:start_session(test, Selenium, webdrv_cap:default_htmlunit(), 10000),
%%% webdrv_session:set_url(test, SomeUrl),
%%% PageSource = webdrv_session:get_page_source(test),
%%% io:format("Source: ~p\n", [PageSource]),
%%% webdrv_session:stop_session(test). </pre>
%%%
%%% The individual functions are not documented. They have type annotations, for more
%%% information on the particular functions, we refer to (<a
%%% href="https://code.google.com/p/selenium/wiki/JsonWireProtocol">The WebDriver
%%% Wire Protocol</a>).
%%%
%%% <h2>License</h2>
%%% <pre>
%%% Permission is hereby granted, free of charge, to any person
%%% obtaining a copy of this software and associated documentation
%%% files (the "Software"), to deal in the Software without
%%% restriction, including without limitation the rights to use, copy,
%%% modify, merge, publish, distribute, sublicense, and/or sell copies
%%% of the Software, and to permit persons to whom the Software is
%%% furnished to do so, subject to the following conditions:
%%%
%%% The above copyright notice and this permission notice shall be
%%% included in all copies or substantial portions of the Software.
%%%
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
%%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
%%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
%%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
%%% BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
%%% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
%%% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
%%% SOFTWARE. </pre>
%%% @end
%%%-------------------------------------------------------------------
-module(webdrv_session).

-include("../include/webdrv.hrl").

-behaviour(gen_server).

-define(TIMEOUT, 30000).

%% API
-export([execute/3, execute_async/3, get_screenshot/1, get_status/1,
         get_window_handle/1, get_window_handles/1,
         get_ime_available_engines/1, get_ime_active_engine/1, get_ime_activated/1,
         ime_deactivate/1, ime_activate/2,
         set_frame/2, set_window_focus/2, close_window/1, set_window_size/3,
         set_window_size/4, get_window_size/1, get_window_size/2, set_window_position/3,
         set_window_position/4, get_window_position/1, get_window_position/2,
         set_window_maximize/1, set_window_maximize/2, get_cookies/1, add_cookie/2,
         delete_cookies/1, delete_cookie/2, get_page_source/1, get_page_title/1,
         find_element/3, find_elements/3, get_active_element/1, find_element_rel/4,
         find_elements_rel/4, click_element/2, submit/2, get_text/2, send_value/3,
         send_keys/2, element_name/2, clear_element/2, is_selected_element/2,
         is_enabled_element/2, element_attribute/3, are_elements_equal/3,
         is_displayed_element/2, get_element_info/2,
         element_location/2, is_element_location_in_view/2, element_size/2,
         element_css_property/3, get_browser_orientation/1, set_browser_orientation/2,
         get_alert_text/1, set_alert_text/2, accept_alert/1, dismiss_alert/1, moveto/4,
         click/2, buttondown/2, buttonup/2, doubleclick/1, get_log/2,
         get_log_types/1, get_cache_status/1, set_timeout/3, set_async_script_timeout/2,
         set_implicit_wait_timeout/2, forward/1, back/1, refresh/1, set_url/2, get_url/1,
         start_session/3, start_session/4, stop_session/1, stop/1
        ]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, { url
               , capabilities
               , session_id
               , timeout}).

%%%===================================================================
%%% API
%%%===================================================================

%% @equiv start_session(Name, Url, DesiredCapabilities, null, 5000)
-spec start_session(atom(), url(), capability()) ->
                       {ok, pid()} | request_error().
start_session(Name, Url, DesiredCapabilities) ->
  start_session(Name, Url, DesiredCapabilities, null, 5000).

%% @equiv start_session(Name, Url, DesiredCapabilities, null, ConnTimeout)
-spec start_session(atom(), url(), capability(), number()) ->
                       {ok, pid()} | request_error().<commit_msg>Increased timeout for starting a session.<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2013, Quviq AB
%%%
%%% @doc {@link gen_server} wrapper for a WebDriver session.
%%%
%%% A WebDriver session (normally the interaction with one browser instance) is associated
%%% to a <tt>SessionId</tt>, and the <tt>URI</tt> of the WebDriver server-side. It quickly
%%% gets painful to carry the id and the URL around, therefore this wrapper module was
%%% created. By using this module, each session is associated to a name (an {@link
%%% atom()}), simplifiying issuing a WebDriver command.
%%%
%%% The implementation is a {@link gen_server}, which keeps the SessionId and the URL (and
%%% a timeout) in its state. A typical interaction with this module could be:
%%%<pre>
%%% webdrv_session:start_session(test, Selenium, webdrv_cap:default_htmlunit(), 10000),
%%% webdrv_session:set_url(test, SomeUrl),
%%% PageSource = webdrv_session:get_page_source(test),
%%% io:format("Source: ~p\n", [PageSource]),
%%% webdrv_session:stop_session(test). </pre>
%%%
%%% The individual functions are not documented. They have type annotations, for more
%%% information on the particular functions, we refer to (<a
%%% href="https://code.google.com/p/selenium/wiki/JsonWireProtocol">The WebDriver
%%% Wire Protocol</a>).
%%%
%%% <h2>License</h2>
%%% <pre>
%%% Permission is hereby granted, free of charge, to any person
%%% obtaining a copy of this software and associated documentation
%%% files (the "Software"), to deal in the Software without
%%% restriction, including without limitation the rights to use, copy,
%%% modify, merge, publish, distribute, sublicense, and/or sell copies
%%% of the Software, and to permit persons to whom the Software is
%%% furnished to do so, subject to the following conditions:
%%%
%%% The above copyright notice and this permission notice shall be
%%% included in all copies or substantial portions of the Software.
%%%
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
%%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
%%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
%%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
%%% BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
%%% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
%%% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
%%% SOFTWARE. </pre>
%%% @end
%%%-------------------------------------------------------------------
-module(webdrv_session).

-include("../include/webdrv.hrl").

-behaviour(gen_server).

-define(TIMEOUT, 30000).

%% API
-export([execute/3, execute_async/3, get_screenshot/1, get_status/1,
         get_window_handle/1, get_window_handles/1,
         get_ime_available_engines/1, get_ime_active_engine/1, get_ime_activated/1,
         ime_deactivate/1, ime_activate/2,
         set_frame/2, set_window_focus/2, close_window/1, set_window_size/3,
         set_window_size/4, get_window_size/1, get_window_size/2, set_window_position/3,
         set_window_position/4, get_window_position/1, get_window_position/2,
         set_window_maximize/1, set_window_maximize/2, get_cookies/1, add_cookie/2,
         delete_cookies/1, delete_cookie/2, get_page_source/1, get_page_title/1,
         find_element/3, find_elements/3, get_active_element/1, find_element_rel/4,
         find_elements_rel/4, click_element/2, submit/2, get_text/2, send_value/3,
         send_keys/2, element_name/2, clear_element/2, is_selected_element/2,
         is_enabled_element/2, element_attribute/3, are_elements_equal/3,
         is_displayed_element/2, get_element_info/2,
         element_location/2, is_element_location_in_view/2, element_size/2,
         element_css_property/3, get_browser_orientation/1, set_browser_orientation/2,
         get_alert_text/1, set_alert_text/2, accept_alert/1, dismiss_alert/1, moveto/4,
         click/2, buttondown/2, buttonup/2, doubleclick/1, get_log/2,
         get_log_types/1, get_cache_status/1, set_timeout/3, set_async_script_timeout/2,
         set_implicit_wait_timeout/2, forward/1, back/1, refresh/1, set_url/2, get_url/1,
         start_session/3, start_session/4, stop_session/1, stop/1
        ]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, { url
               , capabilities
               , session_id
               , timeout}).

%%%===================================================================
%%% API
%%%===================================================================

%% @equiv start_session(Name, Url, DesiredCapabilities, null, 5000)
-spec start_session(atom(), url(), capability()) ->
                       {ok, pid()} | request_error().
start_session(Name, Url, DesiredCapabilities) ->
  start_session(Name, Url, DesiredCapabilities, null, 10000).

%% @equiv start_session(Name, Url, DesiredCapabilities, null, ConnTimeout)
-spec start_session(atom(), url(), capability(), number()) ->
                       {ok, pid()} | request_error().
{'fraction_non_alphanumeric': 0.17012849000096608, 'fraction_numerical': 0.02096415805236209, 'mean_word_length': 3.790374826469227, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1840787', 'n_tokens_mistral': 3213, 'n_tokens_neox': 3094, 'n_words': 886}