Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed see to use studying less; more spec tests

  • Loading branch information...
commit 0b053490742b2c18d93e4900a5b5661631255bfb 1 parent a0e9521
Ken Ken-g6 authored
22 lib/rsel/selenium_test.rb
View
@@ -328,9 +328,7 @@ def maximize_browser
def see(text, scope=nil)
return skip_status if skip_step?
if scope == nil
- # Study workaround when possible.
- bodynode = @study.get_node('xpath=/html/body')
- return true if bodynode && bodynode.inner_text.include?(text)
+ # Can't do a Study workaround - it doesn't know what's visible.
return pass_if @browser.text?(text)
else
selector = loc("css=", '', scope).strip
@@ -338,9 +336,7 @@ def see(text, scope=nil)
# Default selenium_compare does not allow text around a glob. Allow such text.
searchtext = text
searchtext = text.sub(/^(glob:)?\*?/, '*').sub(/\*?$/, '*') unless /^(exact|regexpi?):/ === text
- # Study workaround when possible.
- bodynode = @study.get_node(selector)
- return true if bodynode && selenium_compare(bodynode.inner_text, searchtext)
+ # Can't do a Study workaround - it doesn't know what's visible.
fail_on_exception do
return pass_if selenium_compare(@browser.get_text(selector), searchtext), "'#{text}' not found in '#{@browser.get_text(selector)}'"
end
@@ -362,9 +358,7 @@ def see(text, scope=nil)
def do_not_see(text, scope=nil)
return skip_status if skip_step?
if scope == nil
- # Study workaround when possible.
- bodynode = @study.get_node('xpath=/html/body')
- return true if bodynode && !bodynode.inner_text.include?(text)
+ # Can't do a Study workaround - it doesn't know what's visible.
return pass_if !@browser.text?(text)
else
selector = loc("css=", '', scope).strip
@@ -373,9 +367,7 @@ def do_not_see(text, scope=nil)
# Default selenium_compare does not allow text around a glob. Allow such text.
searchtext = text
searchtext = text.sub(/^(glob:)?\*?/, '*').sub(/\*?$/, '*') unless /^(exact|regexpi?):/ === text
- # Study workaround when possible.
- bodynode = @study.get_node(selector)
- return true if @study.clean? && (!bodynode || !selenium_compare(bodynode.inner_text, searchtext))
+ # Can't do a Study workaround - it doesn't know what's visible.
return pass_if !selenium_compare(@browser.get_text(selector), searchtext), "'#{text}' found in '#{@browser.get_text(selector)}'"
rescue
# Do not see the selector, so do not see the text within it.
@@ -1657,7 +1649,11 @@ def loc(locator, kind='', scope={}, try_study=true)
locator = super(locator, kind, scope)
return locator unless try_study
@study.study(page_to_study) if(@fields_study_min == 1 && !@study.clean? && locator[0,6] == 'xpath=' && locator.length >= @xpath_study_length_min)
- retval = @study.simplify_locator(locator)
+ begin
+ retval = @study.simplify_locator(locator)
+ rescue
+ retval = locator
+ end
@study.dirty
return retval
end
48 spec/st_visibility_spec.rb
View
@@ -24,11 +24,35 @@
@st.see("Some bogus text").should be_false
@st.errors.should eq('')
end
+ it "text is present, but invisible" do
+ @st.errors
+ @st.see("unseen").should be_false
+ @st.errors.should eq('')
+ end
+ it "text is present, but invisible, using studying" do
+ @st.errors
+ @st.begin_study
+ @st.see("unseen").should be_false
+ @st.end_study
+ @st.errors.should eq('')
+ end
it "text is present, but not within the scope" do
@st.errors
@st.see("This is a Sinatra webapp", :within => 'header').should be_false
@st.errors.should eq("'This is a Sinatra webapp' not found in 'About this site'")
end
+ it "text is present, within scope, but invisible" do
+ @st.errors
+ @st.see("unseen", :within => 'header').should be_false
+ @st.errors.should eq("'unseen' not found in 'About this site'")
+ end
+ it "text is present, studied within scope, but invisible" do
+ @st.errors
+ @st.begin_study
+ @st.see("unseen", :within => 'header').should be_false
+ @st.end_study
+ @st.errors.should eq("'unseen' not found in 'About this site'")
+ end
it "scope is not present" do
@st.see("This is a Sinatra webapp", :within => 'bogus_id').should be_false
end
@@ -46,9 +70,33 @@
@st.do_not_see("Nonexistent").should be_true
@st.do_not_see("Some bogus text").should be_true
end
+ it "text is present, but invisible" do
+ @st.errors
+ @st.do_not_see("unseen").should be_true
+ @st.errors.should eq('')
+ end
+ it "text is present, but invisible, using studying" do
+ @st.errors
+ @st.begin_study
+ @st.do_not_see("unseen").should be_true
+ @st.end_study
+ @st.errors.should eq('')
+ end
it "text is present, but not within the scope" do
@st.do_not_see("This is a Sinatra webapp", :within => 'header').should be_true
end
+ it "text is present, within scope, but invisible" do
+ @st.errors
+ @st.do_not_see("unseen", :within => 'header').should be_true
+ @st.errors.should eq('')
+ end
+ it "text is present, studied within scope, but invisible" do
+ @st.errors
+ @st.begin_study
+ @st.do_not_see("unseen", :within => 'header').should be_true
+ @st.end_study
+ @st.errors.should eq('')
+ end
it "scope is not present" do
@st.do_not_see("This is a Sinatra webapp", :within => 'bogus_id').should be_true
end
1  test/views/index.erb
View
@@ -6,6 +6,7 @@
<p>This is a Sinatra webapp for unit testing Rsel.</p>
<div id="header">
+ <p style="display:none">But some things are better left unseen.</p>
<ul>
<li><a href="/about">About this site</a></li>
</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.