Skip to content

Commit

Permalink
Tidy things up, add globify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed Apr 2, 2012
1 parent d9dd244 commit feec302
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
25 changes: 17 additions & 8 deletions lib/rsel/selenium_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ def see(text, scope=nil)
else
selector = loc("css=", '', scope).strip
fail_on_exception do
return pass_if selenium_compare(@browser.get_text(selector), allow_text_in_glob(text)), "'#{text}' not found in '#{@browser.get_text(selector)}'"
match = selenium_compare(@browser.get_text(selector), globify(text))
return pass_if match,
"'#{text}' not found in '#{@browser.get_text(selector)}'"
end
end
end
Expand All @@ -272,7 +274,9 @@ def do_not_see(text, scope=nil)
else
selector = loc("css=", '', scope).strip
begin
return pass_if !selenium_compare(@browser.get_text(selector), allow_text_in_glob(text)), "'#{text}' found in '#{@browser.get_text(selector)}'"
match = selenium_compare(@browser.get_text(selector), globify(text))
return pass_if !match,
"'#{text}' not expected, but found in '#{@browser.get_text(selector)}'"
rescue
# Do not see the selector, so do not see the text within it.
return true
Expand Down Expand Up @@ -317,7 +321,7 @@ def see_within_seconds(text, seconds=-1, scope=nil)
else
selector = loc("css=", '', scope).strip
return pass_if result_within(seconds) {
selenium_compare(@browser.get_text(selector), allow_text_in_glob(text))
selenium_compare(@browser.get_text(selector), globify(text))
}
end
end
Expand Down Expand Up @@ -353,7 +357,8 @@ def do_not_see_within_seconds(text, seconds=-1, scope=nil)
else
selector = loc("css=", '', scope).strip
# Re: rescue: If the scope is not found, the text is not seen.
return pass_if !(Integer(seconds)+1).times{ break if (!selenium_compare(@browser.get_text(selector), allow_text_in_glob(text)) rescue true); sleep 1 }
# TODO: Find a way to make this work with `result_within`
return pass_if !(Integer(seconds)+1).times{ break if (!selenium_compare(@browser.get_text(selector), globify(text)) rescue true); sleep 1 }
end
end

Expand All @@ -369,7 +374,8 @@ def do_not_see_within_seconds(text, seconds=-1, scope=nil)
#
def see_title(title)
return skip_status if skip_step?
pass_if @browser.get_title == title, "Page title is '#{@browser.get_title}', not '#{title}'"
pass_if @browser.get_title == title,
"Page title is '#{@browser.get_title}', not '#{title}'"
end


Expand Down Expand Up @@ -421,7 +427,8 @@ def see_alert_within_seconds(text=nil, seconds=-1)
}
if alert_text
return true if text.nil?
return pass_if selenium_compare(alert_text, text), "Expected alert '#{text}', but got '#{alert_text}'!"
return pass_if selenium_compare(alert_text, text),
"Expected alert '#{text}', but got '#{alert_text}'!"
else
return failure
end
Expand Down Expand Up @@ -480,7 +487,8 @@ def button_exists(locator, scope={})
#
def row_exists(cells)
return skip_status if skip_step?
pass_if @browser.element?("xpath=#{xpath_row_containing(cells.split(/, */).map{|s| escape_for_hash(s)})}")
cells = cells.split(/, */).map { |s| escape_for_hash(s) }
pass_if @browser.element?("xpath=#{xpath_row_containing(cells)}")
end

#
Expand Down Expand Up @@ -1260,7 +1268,8 @@ def method_missing(method, *args, &block)
# The method call succeeded
# Should we check this against another string?
if do_check
return pass_if selenium_compare(result.to_s, check_against), "Expected '#{check_against}', but got '#{result.to_s}'"
return pass_if selenium_compare(result.to_s, check_against),
"Expected '#{check_against}', but got '#{result.to_s}'"
end
# Did it return true or false?
return failure if result == false
Expand Down
12 changes: 9 additions & 3 deletions lib/rsel/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,15 @@ def selenium_compare(text, expected)
end
end

# Default selenium_compare does not allow text around a glob. Allow such text.
# TODO: Document/test this
def allow_text_in_glob(text)
# Return `text` with glob markers `*` on each end, unless the text
# begins with `exact:`, `regexp:`, or `regexpi:`. This effectively
# allows normal text to match as a "contains" search instead of
# matching the entire string.
#
# @param [String] text
# Text to globify
#
def globify(text)
if /^(exact|regexpi?):/ === text
return text
else
Expand Down
2 changes: 1 addition & 1 deletion spec/st_visibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
it "sees text within an id" do
@st.errors
@st.do_not_see("About this site", :within => 'header').should be_false
@st.errors.should eq("'About this site' found in 'About this site'")
@st.errors.should eq("'About this site' not expected, but found in 'About this site'")
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,28 @@
end
end

describe "#globify" do
it "leaves `exact:text` unchanged" do
globify('exact:text').should == 'exact:text'
end

it "leaves `regexp:text` unchanged" do
globify('regexp:text').should == 'regexp:text'
end

it "leaves `regexpi:text` unchanged" do
globify('regexpi:text').should == 'regexpi:text'
end

it "converts `glob:text` to `*text*`" do
globify('glob:text').should == '*text*'
end

it "adds *...* to text" do
globify('text').should == '*text*'
end
end

describe "#result_within" do
context "returns the result when" do
it "block evaluates to true immediately" do
Expand Down

0 comments on commit feec302

Please sign in to comment.