Every repository with this icon (
Every repository with this icon (
| Description: | Webrat - Ruby Acceptance Testing for Web applications edit |
-
We've come across an issue where webrat won't follow a redirect coming from Metal. If you run a cucumber feature to test a link and have that link run through metal, then have the metal change the headers and do a 301,302, or a 303 redirect, the feature will fail. We don't know exactly why webrat won't follow the redirect, but it won't.
headers.merge!({"Location" => "http://someurl.com"})
[303, headers, ["redirecting ..."]]Comments
-
field_labled doesn't match when ":" is in the label
6 comments Created 5 months ago by thillersonUsing 0.4.4.
I have the following erb:
<label for="permalink">Use the following URL for sharing:</label> <input type="text" id="permalink" class="text-input" value="<%= permalink %>"/>And I'm using (through Cucumber):
Then "the \"Use the following URL for sharing\" field should contain \"#{permalink}\""Which uses this:
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should =~ /#{value}/ endWhen I have a colon in the label, e.g. "Use the following URL for sharing:", field_labeled will not match. If I take the colon out, e.g. "Use the following URL for sharing", it will match.
Comments
Yea, Im also having the same issue my colleague has same versions of webrat, nokogiri, libxml2 and it works on his machine.
Some others seem to have the same issue
http://stackoverflow.com/questions/1186547/regular-expressions-in-cucumber-stepsI had a similar problem that I solved by loosening the regexp in webrat's field matcher:
Here's what I have in my code to work around the issue: http://gist.github.com/169215
This is confusing in general in my experience and I'd love to see this land.
I can fork and make the change to the actual codebase and see what brynary thinks. The trade-off with my regexp is that there is a possibility for unexpected matches on pages with very similar labels. I think it's probably worth the change though.
So I started with some tests on my fork, and it turns out that with the current code, it looks like it will match a colon suffix, but it won't match with a number prefix.
Check it out here: phinze/webrat@d31f1ee
There is another test elsewhere that states that "fill_in should anchor at the beginning of label strings" which would be in direct conflict with my changed regexp... so I'm not sure where that leaves us.
-
Would be nice to see something like:
have_selector('span', 'This is the contents of the span')
or
have_selector('ul li', :count => 2..3)
extra goodies like that. I was going to replace rspec_hpricot_matchers with webrat's matchers but at least from what I can see they do not do as much. They also do not (appear to) accept blocks for asserting children.
have_attr would be useful as well. Perhaps these are just not documented but if any of this is interesting let me know and I will fork and commit some changes
Comments
-
The docs say this:
# Which rails environment should the selenium tests be run in? Defaults to selenium. attr_accessor :application_environmentBut the initializer does this:
def initialize # :nodoc: self.open_error_files = true self.parse_with_nokogiri = !Webrat.on_java? self.application_environment = :testThis matches the behavior I was seeing -- had to manually set the environment to selenium in order to get Mongrel to see it.
Thanks,
RobComments
If I recall correctly, brynary made changes to Selenium shortly after Ryan Bates Railscast episode, in which he (brynary) changed the environment to test to make the transition smooter. The documentation for application_environment is is need of an update apparently.
-
Add a scope argument to assert_contain and should contain
1 comment Created 3 months ago by djanowskiThis patch adds an optional argument to
assert_containand the RSpec equivalent, which allows for this kind of assertions:assert_contain "Bryan", "#login" last_response.should contain("Name", "#errors")We've been using this on a project and it works really well. It helps avoid false positives (for example, when you want to assert that the response contains a user name, but that user name is always present in the login area, you can scope it by a different div).
Pull from http://github.com/djanowski/webrat/commit/9544b8d7e1f13258a5edaf2a07c6feb055c6ce62
Comments
-
generated paths dont include the get-parameters
0 comments Created 3 months ago by lichtambergIf you have a path, "/addresses/new?timepoint_id=1"
and try to check this path with"Then I should be on the new address path" and the path is new_address_path(:timepoint_id => @timepoint.id)
Then the errormassage shows something like:
got "/addresses/new?timepoint_id=1"
expected: "/addresses/new"But I think thats the wrong behaviour?
Fix would be:
Then /^I should be on (.+)$/ do |page_name|
path = URI.parse(current_url).path
path += "?" + URI.parse(current_url).query.to_s if URI.parse(current_url).query
path.should == path_to(page_name)
end
Comments
-
Consider this sample code:
def test_should_persist_sessions @request ||= ActionController::TestRequest.new @request.session[:user] = @paul.id puts @request.session.inspect # => {"user"=>46} visit "/" puts @request.session.inspect # => {} @request.session[:user] = @paul.id puts @request.session.inspect # => {"user"=>46} visit "/" puts @request.session.inspect # => {} endTwo things here. Firstly, I have to set @request because it isn't available before a visit.
Secondly, the session vars I set don't need to be persisting between events. If I save and open page where I print the session, it never makes it into the request.
Both of these things are stopping some big speed boosts. Our app has multiple user levels, and currently, to test them, we need to logout, and back in. The total times comes to around 10m for our test suite. It would be nice to edit the session directly! (along with many other of our tests which could use this technique to speed things up drastically!).
Comments
imho this is crazy. restoring a cookie jar may make sense but my sinatra/merb apps have no concept of @request and would hate to see this bleed over from rails.
Well obviously the example would be altered for each framework, but large Rails apps in particular could benefit from this. Webrat should be able to read the session encryption, and use the framework to decrypt, change, and reencrypt cookies before requests.
-
Webrat does not remember the hostname thus does not follows redirects.
4 comments Created 2 months ago by 3scaleI'm in a webrat session. I do something like
visit "http://foo.com/something". So now I'm on the "foo.com" hostname. Now I doclick_button("Whatever"). If the result of this action is redirect, it won't be followed, because webrat thinks it's an external redirect. That's because it does not remembers that it is on "foo.com", but uses the hardcoded default "www.example.com".The reason why this matters is, that you may want to test an application which has logic which depends on the domain/subdomain it is accessed on (for example with the subdomain_fu plugin).
Comments
We have the same problem. We work around it manually now but we would love to see this in webrat proper.
The workaround is, in your tests, to use only domains which are subdomains of example.com (foo.example.com, bar.example.com). This works for us for now, but may not work for someone else. It would be much better if this problem is properly solved.
I have the same problem, it worked in older versions...
michelefranzin
Fri Nov 06 01:59:49 -0800 2009
| link
same issue :-(
-
I've run my features today with Webrat 0.5.1 and latest Cucumber 0.3.98 and found out that it just fails with strange:
undefined method `visit' for # (NoMethodError) (eval):2:in `visit' /Volumes/Data/Users/Pavel/Sites/mujy/features/steps/webrat_steps.rb:5:in `/^I go to (.*)$/' features/activations.feature:15:in `When I go to /activate'So I've tried to get Git version of Webrat and did this setup of world by myself support/env.rb:
require 'webrat' require 'webrat/adapters/merb' module Merb module Cucumber class World include ::Merb::Test::Matchers include ::Merb::Test::ControllerHelper include ::Merb::Test::RouteHelper include ::Merb::Test::ViewHelper include ::Webrat::Methods end end end World do Merb::Cucumber::World.new endWhich fails again with:
undefined method `request' for # (NoMethodError) /Volumes/Data/Users/Pavel/Sites/mujy/features/steps/shared_steps.rb:19:in `/^I log in as (\w+)$/' features/activations.feature:22:in `Given I log in as Marcus'I've also noticed that new version of Merb::Test::RequestHelper#request is much much slimmer than the original one in the Merb which results again in massive problems at least in my features.
Comments
Grr. That undefined methods are always for the MerbAdapter: Webrat::MerbAdapter:0x442c298, github eaten the markup.
OK I've some solution for this:
http://github.com/pk/webrat/commit/fc177e675214488ea83a7ec4384031a97b1e6c3fPatch for merb_cucumber:
http://github.com/pk/merb_cucumber/commit/a42e179dfe19bfc369ad8dd52145681503179267However switching to the Rack::MockResponse is good for standard stuff, it is missing url which was Merb addition. So all steps which has webrat_session.response.url will fail.
It seems that I like to talk to myself :-) The last issue with the
webrat.response.urlis easily solved by changing the steps towebrat.current_url. How easy when I read the source.Just another question how does the webrat and rack/test works together? I tried to include Rack::Test::Methods to the cucumber world which resulted in just exceptions. So... with cucumber/webrat I don't use rack/test directly but with plain RSpec I do?
-
current_url does not reflect redirects in a Mechanize session
1 comment Created 2 months ago by sandroWhen I visit a protected page within a mechanize session and it redirects me to the sign in page, the current_url still points to the protected url, not the url of the redirect. I assume this happens because mechanize follows redirects by default.
A possible solution:
module Webrat class MechanizeSession def current_url response.uri.to_s end end class Session def current_url if @adapter.respond_to?(:current_url) @adapter.current_url else @current_url end end end endComments
-
In SeleniumSession there's no current call to selenium.wait_for_page_to_load
1 comment Created 2 months ago by andygoundryCurrently, it appears that i am forced to use the direct call to selenium.wait_for_page_to_load in my Cucumber step, but this is hacky.
Have i missed something and perhaps the code is somewhere else? If not, what's the process of adding this in? I'll add to my code for now.
Thanks
Andy
Comments
andygoundry
Mon Sep 07 08:51:30 -0700 2009
| link
For now, i've add this to my support/env.rb
module Webrat class SeleniumSession def wait_for_page_to_load selenium.wait_for_page_to_load end end end -
Links to protocols other than http don't work
0 comments Created about 1 month ago by aiwilliamsForgive me if I've posted this before, but I could not find where/if I did.
When a page has a link to webcal://www.example.com, and it is clicked on, the url webrate attempts to fetch is http://www.example.com/webcal://www.example.com.
>Comments
-
Currently the selenium page response time is hard coded to 5 seconds. I think this should be a configuration option. I have added this in my fork.
http://github.com/kbaum/webrat/commit/9b91693ea048dd74bc2768e3d011b31a4c3d5601
thx.
Comments
-
wait_for swallows Selenium CommandErrors
1 comment Created about 1 month ago by schubertWhen using wait for and there is a command error inside of the block (like a typo in an xpath selector) you get a timeout failure because the command error is swallowed and silently ignored. This makes troubleshooting typos extremely difficult because the failures become misleading.
This is in selenium_session.rb WebRat::SeleniumSession#is_ignorable_wait_for_exception
Comments
-
When webrat is run in selenium mode,
Version
Webrat: 0.6.rc1
Rails: 2.3.4
rspec: 1.2.7
rspec-rails:1.2.7On asserting with response.should have_tag("...", "..."), The following error message is thrown.
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.content_type (NoMethodError)vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:in
__send__'<br/> vendor/plugins/rspec-rails/lib/spec/rails/matchers/assert_select.rb:25:inmatches?'
vendor/plugins/rspec/lib/spec/expectations/handler.rb:11:inhandle_matcher'<br/> vendor/plugins/rspec/lib/spec/expectations/extensions/kernel.rb:27:inshould'
Comments
-
Rspec-rails integration does not include the 'integration' type
0 comments Created about 1 month ago by sandrolib/webrat/integrations/rspec-rails.rb
'integration' should be included in the array of types which include the webrat matchers now that rspec-rails supports the integration directory.config.include(Webrat::Matchers, :type => [:controller, :helper, :view, :integration])Comments
-
Webrat includes an empty file field as part of the fom submission
0 comments Created 29 days ago by jhendersonNormally in a browser, when a form is submitted with an empty file input field, the file field is ignored and doesn't appear in the params hash. However, webrat doesn't conform to this rule. If a file field is empty, the params hash will still show an empty string for the uploaded data causing problems with nested attributes for example. It would great if this could be looked at in more detail.
Cheers
Comments
-
It looks like 0.6 is depending on the rack-test gem. Can you add this to the gemspec dependency so it'll be automatically installed and avoid these errors:
no such file to load -- rack/testThanks!
Comments
-
I add this spec, and it does not pass.
it "should support nested attributes" do with_html <<-HTML <html> <form method="post" action="/albums"> <label for="photo_file1">Photo</label> <input type="file" id="photo_file1" name="album[photos_attributes][][image]" /> <input type="submit" /> </form> </html> HTML webrat_session.should_receive(:post).with("/albums", { "album" => { "photos_attributes" => [{"image" => @uploaded_file}] } }) attach_file "Photo", @filename click_button endComments
-
Hi,
Seeing a recent tendency for developers to omit URL scheme's in some pages in order to bypass security issues with IE. Please see this article for an explanation:
http://sharovatov.wordpress.com/2009/04/17/common-internet-scheme-syntax-detailed-post/
It's arguable as to whether this is a good idea or just a hack but it's happening and all the browsers seem to allow it. Would be good if Webrat could follow this pattern of behaviour too.
Cheers,
Matt
Comments
-
find_button does not match button elements with html entities.
2 comments Created 20 days ago by martinemdeI've fixed this in my branch at http://github.com/martinemde/webrat/commit/85b4a07be774d3209f4636642db131424a42d8d7
If you try to match
<button>Erase & Restart</button>It doesn't match correctly:
find_button("Erase & Restart") # Does not match find_button("Erase & Restart") # Matches (but is nasty)Note that this works as expected with the following html:
<input type="submit" value="Erase & Restart">Simple fix is in my branch.
Comments
martinemde
Sun Oct 18 17:01:28 -0700 2009
| link
Updated the commit url.
-
Difficult to find label containing non-breaking space ( )
3 comments Created 19 days ago by mislavI frequently use non-breaking spaces in labels because they should be kept on one line, even if there are multiple words.
<label for="password_confirmation">Repeat password</label>Of course, this is not a regular space character and, when converted from HTML entity to unicode character, it isn't recognized as space in regular expressions.
As a result, both of these don't work:
fill_in("Repeat password", :with => "test") # /^Repeat password\b/ fill_in("Repeat", :with => "test") # /^Repeat\b/A non-breaking space isn't recognized as space or as a word boundary.
A monkeypatch that solves this augments the
#all_inner_textmethod to convert all non-breaking spaces to ordinary space:class << Webrat::XML alias :all_inner_text_with_nbsp :all_inner_text # convert non-breaking spaces ( ) to regular space def all_inner_text(element) all_inner_text_with_nbsp(element).gsub("\302\240", ' ') end endThis solves the issue globally throughout Webrat.
Comments
martinemde
Mon Oct 19 10:48:33 -0700 2009
| link
It might be a good idea to take a look at where and how all html entities should be handled. I'm sure there's some general rules that would help. For example, should be removed entirely (not sure if this already happens).
I agree, but I'd rather call them "characters" instead of "entities", since HTML entities are merely an encoding scheme for special characters in HTML and they get decoded to Unicode (or other) once you start extracting text from web pages using a capable parser like Nokogiri.
Interesting to see that GitHub Flavored Markdown didn't escape
­in your comment above, but rendered it as-is.
martinemde
Mon Oct 19 13:16:18 -0700 2009
| link
Good point.
Also, very curious about the
­. I sorta breezed right over it assuming it would be escaped. Not sure if I'm escaping it right this time even. -
I am using the webrat integration with rspec, and in a view spec I have this line:
response.should have_selector("form",
:method => 'post', :action => beta_invite_path ) do |form|; endWhen I have that in the spec, I get an error about an undefined method 'configuration' for Webrat:Module. As soon as I remove/comment that out, it runs just fine.
Comments












We're using it with lots of straight up rack apps and not seeing this issue. What does your response(including headers) look like?