Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

auto-higlight located element full support

  • Loading branch information...
commit 54695a6bf7d8e97981b3a12bce11aa4745fb8e99 1 parent 79e22f0
@ph7 ph7 authored
View
7 ChangeLog
@@ -15,6 +15,13 @@
end
- Ruby 1.9.1 compatibility
+
+ - Added support for turning on/off automatic hightlighting of the element
+ driven or inspected by Selenium. Useful when recording videos. Thank
+ you Aaron Tinio. See the `highlight_located_element` option when
+ creating the driver and the `highlight_located_element=` method on
+ the driver for more details.
+
1.2.15 (2009-05-13)
===================
View
1  README.markdown 100644 → 100755
@@ -303,6 +303,7 @@ Contributors
- Support for locator including single quotes in `wait_for_...` methods
- Do not capture system state on execution errors for pending examples
(ExamplePendingError, NotYetImplementedError)
+ - Auto-highlighting support
* Rick Lee-Morlang (`rleemorlang`):
- Fix for incremental calls to `wait_for_text`
View
14 lib/selenium/client/base.rb
@@ -11,7 +11,7 @@ module Base
attr_reader :host, :port, :browser_string, :browser_url,
:default_timeout_in_seconds,
:default_javascript_framework,
- :highlight_located_element
+ :highlight_located_element_by_default
#
# Create a new client driver
@@ -54,7 +54,7 @@ def initialize(*args)
@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 = options[:highlight_located_element] || false
+ @highlight_located_element_by_default = options[:highlight_located_element] || false
else
@host = args[0]
@port = args[1].to_i
@@ -62,7 +62,7 @@ def initialize(*args)
@browser_url = args[3]
@default_timeout_in_seconds = (args[4] || 300).to_i
@default_javascript_framework = :prototype
- @highlight_located_element = false
+ @highlight_located_element_by_default = false
end
@extension_js = ""
@@ -86,7 +86,8 @@ def start_new_browser_session(options={})
@session_id = result
# 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.remote_control_timeout_in_seconds = @default_timeout_in_seconds
+ self.highlight_located_element = true if highlight_located_element_by_default
end
def close_current_browser_session
@@ -109,10 +110,7 @@ def chrome_backend?
def javascript_extension=(new_javascript_extension)
@extension_js = new_javascript_extension
end
-
- def set_extension_js(new_javascript_extension)
- javascript_extension = new_javascript_extension
- end
+ alias :set_extension_js :javascript_extension=
end
View
26 lib/selenium/client/idiomatic.rb
@@ -442,7 +442,31 @@ def browser_xpath_library=(library_name)
remote_control_command "useXpathLibrary", [library_name.to_s]
end
+ #
+ # Turn on/off the automatic hightlighting of the element driven or
+ # inspected by Selenium core. Useful when recording videos
+ #
+ def highlight_located_element=(enabled)
+ boolean = (true == enabled)
+ js_eval "selenium.browserbot.shouldHighlightLocatedElement = #{boolean}"
+ end
+
+ # Get execution delay in milliseconds, i.e. a pause delay following
+ # each selenium operation. By default, there is no such delay
+ # (value is 0).
+ def execution_delay
+ string_command "getSpeed"
+ end
+
+ # Set the execution delay in milliseconds, i.e. a pause delay following
+ # each selenium operation. By default, there is no such delay.
+ #
+ # Setting an execution can be useful to troubleshoot of capture videos
+ def execution_delay=(delay_in_milliseconds)
+ remote_control_command "setSpeed", [delay_in_milliseconds]
+ end
+
end
-
+
end
end
View
26 test/unit/selenium/client/base_tests.rb
@@ -109,6 +109,20 @@
client.expects(:remote_control_timeout_in_seconds=).with(24)
client.start_new_browser_session
end
+
+ test "start_new_browser_session setup auto-higlight of located element when option is set" do
+ client = Class.new { include Selenium::Client::Base }.new :highlight_located_element => true
+ client.stubs(:remote_control_command)
+ client.expects(:highlight_located_element=).with(true)
+ client.start_new_browser_session
+ end
+
+ test "start_new_browser_session do not setup auto-higlight of located element when option is not set" do
+ client = Class.new { include Selenium::Client::Base }.new :highlight_located_element => false
+ client.stubs(:remote_control_command)
+ client.expects(:highlight_located_element=).never
+ client.start_new_browser_session
+ end
test "session_started? returns false when no session has been started" do
client = Class.new { include Selenium::Client::Base }.new :host, 24, :browser, :url
@@ -177,20 +191,20 @@
assert_false client.chrome_backend?
end
- test "Hash initializer sets highlight_located_element" do
+ test "Hash initializer sets highlight_located_element_by_default" do
client_class = Class.new { include Selenium::Client::Base }
client = client_class.new :highlight_located_element => true
- assert_true client.highlight_located_element
+ assert_true client.highlight_located_element_by_default
end
- test "basic initializer sets highlight_located_element to false by default" do
+ test "basic initializer sets highlight_located_element_by_default to false by default" do
client = Class.new { include Selenium::Client::Base }.new
- assert_false client.highlight_located_element
+ assert_false client.highlight_located_element_by_default
end
- test "Hash initializer sets highlight_located_element to false by default" do
+ test "Hash initializer sets highlight_located_element_by_default to false by default" do
client = Class.new { include Selenium::Client::Base }.new :host => :a_host
- assert_false client.highlight_located_element
+ assert_false client.highlight_located_element_by_default
end
end
View
26 test/unit/selenium/client/idiomatic_tests.rb
@@ -453,5 +453,29 @@
client = Class.new { include Selenium::Client::Idiomatic }.new
assert_raises(RuntimeError) { client.browser_xpath_library = :random_library }
end
-
+
+ test "setting highlight_located_element to true enables auto-hilighting in selenium core" do
+ client = Class.new { include Selenium::Client::Idiomatic }.new
+ client.expects(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = true")
+ client.highlight_located_element = true
+ end
+
+ test "setting highlight_located_element to false disables auto-hilighting in selenium core" do
+ client = Class.new { include Selenium::Client::Idiomatic }.new
+ client.expects(:js_eval).with("selenium.browserbot.shouldHighlightLocatedElement = false")
+ client.highlight_located_element = false
+ end
+
+ test "execution_delay returns the result of the getSpeed command" do
+ client = Class.new { include Selenium::Client::Idiomatic }.new
+ client.expects(:string_command).with("getSpeed").returns(:the_speed)
+ assert_equal :the_speed, client.execution_delay
+ end
+
+ test "execution_delay= executes the setSpeed command" do
+ client = Class.new { include Selenium::Client::Idiomatic }.new
+ client.expects(:remote_control_command).with("setSpeed", [24])
+ client.execution_delay= 24
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.