Skip to content

Commit

Permalink
Added wait_for_visible to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotsykes committed Jul 10, 2009
1 parent f5e4d2e commit 4c7f3d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/selenium/client/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Client
# Convenience methods not explicitely part of the protocol
module Extensions

# These for all Ajax request to finish (Only works if you are using prototype, the wait in happenning browser side)
# These for all Ajax request to finish (Only works if you are using prototype, the wait happens in the browser)
#
# See http://davidvollbracht.com/2008/6/4/30-days-of-tech-day-3-waitforajax for
# more background.
Expand All @@ -14,7 +14,7 @@ def wait_for_ajax(options={})
options[:timeout_in_seconds]
end

# Wait for all Prototype effects to be processed (the wait in happenning browser side).
# Wait for all Prototype effects to be processed (the wait happens in the browser).
#
# Credits to http://github.com/brynary/webrat/tree/master
def wait_for_effects(options={})
Expand All @@ -23,14 +23,14 @@ def wait_for_effects(options={})
options[:timeout_in_seconds]
end

# Wait for an element to be present (the wait in happenning browser side).
# Wait for an element to be present (the wait happens in the browser).
def wait_for_element(locator, options={})
builder = JavascriptExpressionBuilder.new
builder.find_element(locator).append("element != null;")
wait_for_condition builder.script, options[:timeout_in_seconds]
end

# Wait for an element to NOT be present (the wait in happenning browser side).
# Wait for an element to NOT be present (the wait happens in the browser).
def wait_for_no_element(locator, options={})
builder = JavascriptExpressionBuilder.new
builder.find_element(locator).append("element == null;")
Expand Down Expand Up @@ -73,7 +73,7 @@ def wait_for_text(pattern, options={})
wait_for_condition builder.script, options[:timeout_in_seconds]
end

# Wait for some text to NOT be present (the wait in happenning browser side).
# Wait for some text to NOT be present (the wait happens in the browser).
#
# See wait_for_text for usage details.
def wait_for_no_text(pattern, options={})
Expand All @@ -82,7 +82,7 @@ def wait_for_no_text(pattern, options={})
wait_for_condition builder.script, options[:timeout_in_seconds]
end

# Wait for a field to get a specific value (the wait in happenning browser side).
# Wait for a field to get a specific value (the wait happens in the browser).
def wait_for_field_value(locator, expected_value, options={})
builder = JavascriptExpressionBuilder.new
builder.find_element(locator).element_value_is(expected_value)
Expand All @@ -95,6 +95,12 @@ def wait_for_no_field_value(locator, expected_value, options={})
wait_for_condition builder.script, options[:timeout_in_seconds]
end

# Wait for something to be visible (the wait happens in the browser).
def wait_for_visible(locator, options={})
builder = JavascriptExpressionBuilder.new
wait_for_condition builder.visible(locator).script, options[:timeout_in_seconds]
end

def active_javascript_framework(options)
options[:javascript_framework] || default_javascript_framework
end
Expand Down
4 changes: 4 additions & 0 deletions lib/selenium/client/javascript_expression_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def no_pending_effects
append window_script("Effect.Queue.size() == 0")
end

def visible(locator)
append "selenium.isVisible('#{quote_escaped(locator)}')"
end

def find_element(locator)
append <<-EOS
var element;
Expand Down
11 changes: 11 additions & 0 deletions test/unit/selenium/client/extensions_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,15 @@
client.wait_for_no_field_value "a_locator", "a value", :timeout_in_seconds => :the_timeout
end

test "wait_for_visible uses provided locator" do
client = Class.new { include Selenium::Client::Extensions }.new
client.expects(:wait_for_visible).with(regexp_matches(/selenium.isVisible('a_locator')/), anything)
client.wait_for_visible "a_locator"
end

test "wait_for_visible uses explicit timeout when provided" do
client = Class.new { include Selenium::Client::Extensions }.new
client.expects(:wait_for_visible).with(anything, :the_timeout)
client.wait_for_visible "a_locator", :timeout_in_seconds => :the_timeout
end
end

0 comments on commit 4c7f3d0

Please sign in to comment.