Module: Selenium::Client::Base

Includes:
Extensions, GeneratedDriver, Idiomatic, Protocol
Included in:
Driver
Defined in:
lib/selenium/client/base.rb

Overview

Driver constructor and session management commands

Instance Attribute Summary collapse

Attributes included from Protocol

#session_id

Instance Method Summary collapse

Methods included from Idiomatic

#actual_timeout_in_milliseconds, #alert, #alert?, #all_window_ids, #all_window_names, #all_window_titles, #body_text, #browser_network_traffic, #browser_xpath_library=, #checked?, #click, #confirmation, #confirmation?, #cookie, #cookie?, #cookies, #create_cookie, #delete_cookie, #element?, #execution_delay, #execution_delay=, #field, #go_back, #highlight_located_element=, #js_eval, #location, #prompt, #prompt?, #remote_control_timeout_in_seconds=, #table_cell_text, #text, #text?, #title, #value, #visible?, #wait_for, #wait_for_condition, #wait_for_page, #wait_for_popup

Methods included from Extensions

#active_javascript_framework, #wait_for_ajax, #wait_for_effects, #wait_for_element, #wait_for_field_value, #wait_for_no_element, #wait_for_no_field_value, #wait_for_no_text, #wait_for_not_visible, #wait_for_text, #wait_for_visible

Methods included from GeneratedDriver

#add_location_strategy, #add_script, #add_selection, #allow_native_xpath, #alt_key_down, #alt_key_up, #answer_on_next_prompt, #assign_id, #attach_file, #capture_entire_page_screenshot, #capture_entire_page_screenshot_to_string, #capture_screenshot, #capture_screenshot_to_string, #check, #choose_cancel_on_next_confirmation, #choose_ok_on_next_confirmation, #click, #click_at, #close, #context_menu, #context_menu_at, #control_key_down, #control_key_up, #create_cookie, #delete_all_visible_cookies, #delete_cookie, #deselect_pop_up, #double_click, #double_click_at, #drag_and_drop, #drag_and_drop_to_object, #dragdrop, #fire_event, #focus, #get_alert, #get_all_buttons, #get_all_fields, #get_all_links, #get_all_window_ids, #get_all_window_names, #get_all_window_titles, #get_attribute, #get_attribute_from_all_windows, #get_body_text, #get_confirmation, #get_cookie, #get_cookie_by_name, #get_css_count, #get_cursor_position, #get_element_height, #get_element_index, #get_element_position_left, #get_element_position_top, #get_element_width, #get_eval, #get_expression, #get_html_source, #get_location, #get_mouse_speed, #get_prompt, #get_select_options, #get_selected_id, #get_selected_ids, #get_selected_index, #get_selected_indexes, #get_selected_label, #get_selected_labels, #get_selected_value, #get_selected_values, #get_speed, #get_table, #get_text, #get_title, #get_value, #get_whether_this_frame_match_frame_expression, #get_whether_this_window_match_window_expression, #get_xpath_count, #go_back, #highlight, #ignore_attributes_without_value, #is_alert_present, #is_checked, #is_confirmation_present, #is_cookie_present, #is_editable, #is_element_present, #is_ordered, #is_prompt_present, #is_something_selected, #is_text_present, #is_visible, #key_down, #key_down_native, #key_press, #key_press_native, #key_up, #key_up_native, #meta_key_down, #meta_key_up, #mouse_down, #mouse_down_at, #mouse_down_right, #mouse_down_right_at, #mouse_move, #mouse_move_at, #mouse_out, #mouse_over, #mouse_up, #mouse_up_at, #mouse_up_right, #mouse_up_right_at, #open, #open_window, #refresh, #remove_all_selections, #remove_script, #remove_selection, #retrieve_last_remote_control_logs, #rollup, #run_script, #select, #select_frame, #select_pop_up, #select_window, #set_browser_log_level, #set_context, #set_cursor_position, #set_mouse_speed, #set_speed, #set_timeout, #shift_key_down, #shift_key_up, #shut_down_selenium_server, #submit, #type, #type_keys, #uncheck, #use_xpath_library, #wait_for_condition, #wait_for_frame_to_load, #wait_for_page_to_load, #wait_for_pop_up, #window_focus, #window_maximize

Methods included from Protocol

#boolean_array_command, #boolean_command, #number_array_command, #number_command, #remote_control_command, #string_array_command, #string_command

Instance Attribute Details

#browser_stringObject (readonly)

Returns the value of attribute browser_string.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def browser_string
  @browser_string
end

#browser_urlObject (readonly)

Returns the value of attribute browser_url.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def browser_url
  @browser_url
end

#default_javascript_frameworkObject (readonly)

Returns the value of attribute default_javascript_framework.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def default_javascript_framework
  @default_javascript_framework
end

#default_timeout_in_secondsObject (readonly)

Returns the value of attribute default_timeout_in_seconds.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def default_timeout_in_seconds
  @default_timeout_in_seconds
end

#highlight_located_element_by_defaultObject (readonly)

Returns the value of attribute highlight_located_element_by_default.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def highlight_located_element_by_default
  @highlight_located_element_by_default
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/selenium/client/base.rb', line 11

def port
  @port
end

Instance Method Details

#chrome_backend?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/selenium/client/base.rb', line 120

def chrome_backend?
  ["*chrome", "*firefox", "*firefox2", "*firefox3"].include?(@browser_string)
end

#close_current_browser_sessionObject



107
108
109
110
# File 'lib/selenium/client/base.rb', line 107

def close_current_browser_session
  remote_control_command "testComplete" if @session_id
  @session_id = nil
end

#initialize(*args) ⇒ Object

Create a new client driver

Example:

Selenium::Client::Driver.new \

:host => "localhost",
:port => 4444,
:browser => "*firefox",
:timeout_in_seconds => 10,
:url => "http://localhost:3000",

You can also set the default javascript framework used for :wait_for AJAX and effects semantics (:prototype is the default value):

Selenium::Client::Driver.new \

:host => "localhost",
:port => 4444,
:browser => "*firefox",
:timeout_in_seconds => 10,
:url => "http://localhost:3000",
:javascript_framework => :jquery

You can also enables automatic highlighting of located elements by passing the highlight_located_element option, e.g.

Selenium::Client::Driver.new \

:host => "localhost",
:port => 4444,
:browser => "*firefox",
:highlight_located_element => true


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/selenium/client/base.rb', line 48

def initialize(*args)
  if args[0].kind_of?(Hash)
    options = args[0]
    @host = options[:host]
    @port = options[:port].to_i
    @browser_string = options[:browser]
    @browser_url = options[:url]
    @default_timeout_in_seconds = (options[:timeout_in_seconds] || 300).to_i
    @default_javascript_framework = options[:javascript_framework] || :prototype
    @highlight_located_element_by_default = options[:highlight_located_element] || false
  else
    @host = args[0]
    @port = args[1].to_i
    @browser_string = args[2]
    @browser_url = args[3]
    @default_timeout_in_seconds = (args[4] || 300).to_i
    @default_javascript_framework = :prototype
    @highlight_located_element_by_default = false
  end

  @extension_js = ""
  @session_id = nil
end

#javascript_extension=(new_javascript_extension) ⇒ Object Also known as: set_extension_js



124
125
126
# File 'lib/selenium/client/base.rb', line 124

def javascript_extension=(new_javascript_extension)
  @extension_js = new_javascript_extension
end

#session_started?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/selenium/client/base.rb', line 72

def session_started?
  not @session_id.nil?
end

#start(opts = {}) ⇒ Object



112
113
114
# File 'lib/selenium/client/base.rb', line 112

def start(opts = {})
  start_new_browser_session opts
end

#start_new_browser_session(options = {}) ⇒ Object

Starts a new browser session (launching a new browser matching configuration provided at driver creation time).

Browser session specific option can also be provided. e.g.

driver.start_new_browser_session(:captureNetworkTraffic => true)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/selenium/client/base.rb', line 83

def start_new_browser_session(options={})
  start_args = [@browser_string, @browser_url, @extension_js]

  if driver = options.delete(:driver)
    expected_browser_string = "*webdriver"
    unless @browser_string == expected_browser_string
      raise ArgumentError, "can't use :driver unless the browser string is #{expected_browser_string.inspect} (got #{@browser_string.inspect})"
    end

    sid = driver.capabilities['webdriver.remote.sessionid']
    sid or raise ArgumentError, "This driver can not be wrapped in the RC API."

    start_args << "webdriver.remote.sessionid=#{sid}"
  end

  start_args << options.collect {|key,value| "#{key.to_s}=#{value.to_s}"}.sort.join(";")

  @session_id = string_command "getNewBrowserSession", start_args
  # Consistent timeout on the remote control and driver side.
  # Intuitive and this is what you want 90% of the time
  self.remote_control_timeout_in_seconds = @default_timeout_in_seconds
  self.highlight_located_element = true if highlight_located_element_by_default
end

#stopObject



116
117
118
# File 'lib/selenium/client/base.rb', line 116

def stop
 close_current_browser_session
end