webrat
Webrat - Ruby Acceptance Testing for Web applications
Documentation for brynary/webrat (master)
I am using Cucumber, webrat and selenium to test a web application. I use 'I should see "something"' to verify changes. However, in many places, text to be verified only changes from hidden to visible (this might be caused by removing 'hidden' class from itself or one of its ancestors). In this case, above test does not actually verify the change. I am trying to use 'response.should_not have_tag("div#myId.hidden")', which does not work. What is the recommended way to test this?
Environment: cucumber 0.3.11, selenium-client 1.2.17, webrat 0.6.0
Thank you.
Source: (StackOverflow)
I started migrating from cucumber + webrat to cucumber + capybara. Now the behavior of "I should see " seems to be somewhat different. Most of these fail now, although I didn't change anything on the page. I replaced the snippet that should be found with some stuff that is on every page and for some text it works and for other text it doesn't. I can't find any pattern in what is found in the page's content and what is not.
Webrat used to print what the page content is that it found, in case it did not contain the required phrase. Is there anyway to have capybara show what text it got from the page in which it tried to find the text?
Source: (StackOverflow)
We are running Webrat with Selenium2.0 aka WebDriver in our application.
WebDriver handles page reloading very well and do not start next steps if the browser is reloading entire page. The problem is that this mechanism doesn't work with Ajax requests. WebDriver doesn't do any idle when there some after click() or change().
Can anyone suggest how to make webdriver idle until the end of all ajax requests on the page?
Source: (StackOverflow)
I'm using webrat with cucumber and I would like to test if a radio button is checked already when I am on a page.
How can I do that ? I didn't find any step in webrat which can do that.
Source: (StackOverflow)
The scenario is as follows. My Order model has an after_create that contacts a remote payment gateway to retrieve a payment URL. In my Cucumber tests I don't want to perform this action, but return an arbitrary URL. My current cucumber tests looks like this:
Given there is a product "Product X"
When I enter my credentials
And I click "Order Now"
Then I should be redirected to "arbitrary url"
The problem is where/how do I make sure that my order model sets the url correctly and does not contact the remote payment gateway?
Source: (StackOverflow)
I'm writing some RSpec tests for my Rails 3 application and trying to switch from Webrat to Capybara. So far so good but the application uses HTTP basic auth to authorize my admin user, any idea how I can test that with Capybara?
Here is my current Webrat step:
it 'should authenticate for admin' do
basic_auth('user', 'secret')
visit '/admin'
response.status.should eql 200
response.status.should_not eql 401
end
How do I do this with Capybara? Thanks!
Source: (StackOverflow)
Is there a way to do integration tests with Rspec without using Cucumber? I prefer using just plain old Webrat. Thanks.
Source: (StackOverflow)
I have been using Cucumber and Webrat for a while. I now need to start writing behaviour that involve AJAX interactions so I was thinking to use the Selenium adapter for Webrat.
Can anyone point out a easy and updated step-by-step guide for installing and configuring selenium+webrat+cucumber?
I would like to be able to mix javascript scenario with non-javascript scenarios.
Source: (StackOverflow)
Just switched from Cucumber+Webrat to Cucumber+Capybara and I am wondering how you can POST content to a URL in Capybara.
In Cucumber+Webrat I was able to have a step:
When /^I send "([^\"]*)" to "([^\"]*)"$/ do |file, project|
proj = Project.find(:first, :conditions => "name='#{project}'")
f = File.new(File.join(::Rails.root.to_s, file))
visit "project/" + proj.id.to_s + "/upload",
:post, {:upload_path => File.join(::Rails.root.to_s, file)}
end
However, the Capybara documentation mentions:
The visit method only takes a single
parameter, the request method is
always GET.always GET.
How do I modify my step so that Cucumber+Capybara does a POST to the URL?
Source: (StackOverflow)
I am getting started with RSpec. I have a new rails 3 app which uses the HTTP_ACCEPT_HEADER or the request 2 letter subdomain to set the application language and redirect accordingly. I am successfully testing my redirection code using Cucumber.
Now I want to write my controller specs and I need to set the request subdomain before my test.
In my cucumber steps, I can specify:
header 'HTTP_HOST', 'es.mysite.local'
visit '/'
But when I try to do this in a spec file
header 'HTTP_HOST', 'es.mysite.local'
get 'index'
I get this error:
Failure/Error: header 'HTTP_HOST', "es.mysite.local"
LoadError:
no such file to load -- action_controller/integration
Any clue on how to solve this?
Source: (StackOverflow)
I am working on some Cucumber stories for a 'sign up' application which has a number of steps.
Rather then writing a Huuuuuuuge story to cover all the steps at once, which would be bad, I'd rather work through each action in the controller like a regular user. My problem here is that I am storing the account ID which is created in the first step as a session variable, so when step 2, step 3 etc are visited the existing registration data is loaded.
I'm aware of being able to access controller.session[..]
within RSpec specifications however when I try to do this in Cucumber stories it fails with the following error (and, I've also read somewhere this is an anti-pattern etc...):
Using controller.session[:whatever] or session[:whatever]
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.session (NoMethodError)
Using session(:whatever)
wrong number of arguments (1 for 0) (ArgumentError)
So, it seems accession the session store isn't really possible. What I'm wondering is if it might be possible to (and I guess which would be best..):
- Mock out the session store etc
- Have a method within the controller and stub that out (e.g.
get_registration
which assigns an instance variable...)
I've looked through the RSpec book (well, skimmed) and had a look through WebRat etc, but I haven't really found an answer to my problem...
To clarify a bit more, the signup process is more like a state machine - e.g. the user progresses through four steps before the registration is complete - hence 'logging in' isn't really an option (it breaks the model of how the site works)...
In my spec for the controller I was able to stub out the call to the method which loads the model based on the session var - but I'm not sure if the 'antipattern' line also applies to stubs as well as mocks?
Thanks!
Source: (StackOverflow)
is it possible to follow a link by it's class name instead of the id, text or title? Given I have (haha, cucumber insider he?) the following html code:
<div id="some_information_container">
<a rel='nofollow' href="edit" class="edit_button">Translation here</a>
</div>
- I do not want to match by text because I'd have to care about the translation values in my tests
- I want to have my buttons look all the same style, so I will use the CSS class.
- I don't want to assign a id to every single link, because some of them are perfectly identified through the container and the link class
Is there anything I missed in Cucumber/Webrat? Or do you have some advices to solve this in a better way?
Thanks for your help and best regards,
Joe
edit: I found an interesting discussion going on about this topic right here - seems to remain an open issue for now. Do you have any other solutions for this?
Source: (StackOverflow)
I am using Cucumber for BDD development in my Ruby on Rails project and I'm running into some confusion on how the path.rb handles paths used in rails applications.
Given I have:
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
and I have the following Cucumber feature:
Scenario: A test feature
Given I am on the parent page
When I follow "Link to Children"
Then I should be on the children list page
with the path defined as:
def path_to(page_name)
case page_name
when /the children list page/
'/parents/:id/children'
end
The problem I come across is the following error when running the feature:
Spec::Expectations::ExpectationNotMetError: expected: "/parents/:id/children",
got: "/parents/1726/children" (using ==)
I don't really care what the :id is. What should I do instead? Is this even possible with the default web steps? Am I thinking about the problem in the wrong way?
Source: (StackOverflow)
I've been using Capybara for integration/request testing, but have only just realised I can't do view testing with it.
This SO answer suggests Webrat and Capybara can be used in tandem; but the RSpec docs suggest one must choose between the two. Here's another github thread that suggests webrat can be used for views and capybara for integration.
I've found that if I include Webrat in my gemfile, I can use webrat for views with no problem, but my capybara-styled integration tests no longer work. Specifically, I get an error with the following simple example:
it "should have a Home page at '/'" do
visit '/'
page.should have_selector('title', :content => "Home page")
end
I get the error:
No response yet. Request a page first.
What's the best way (if any?) to get webrat and capybara to like eachother?
Source: (StackOverflow)
I am learning how to write tests with cucumber/webrat. One of my test scenarios is set to test form validation (leaving field(s) empty). Strangely enough, fields that I do not fill-in with fill_in
are set to the field's name
attribute. This only happens when I run cucumber, when using a browser this does not happen.
The step I'm using is straight forward:
When /^I submit the form$/ do
# Not filling in the 'Name' field here
fill_in 'Description', :with => 'This is a description'
click_button 'Save'
end
After running the scenario that uses the step above, I can see that the text field "Name" is set to "name" instead of being empty. This is also the case if I fill in that field with an empty space or nil
:
fill_in 'Name', :with => ''
The form I'm testing on is simple enough:
<form action="/item/create" method="post">
<div>
<label for="ItemName">Name</label>
<input type="text" name="name" id="ItemName" />
</div>
<div>
<label for="ItemDescription">Description</label>
<textarea name="description" id="ItemDescription"></textarea>
</div>
<input type="submit" value="Save" />
</form>
Any idea why this is happening?
Source: (StackOverflow)