ruby-on-rails,rspec,tdd,capybara,bdd
Try: expect(page).to have_selector('title', :text => "Ruby on Rails Tutorial Sample App | Home", :visible => false) Since the title tag is in <head> element, it is considered hidden. Specifying :visible => false includes those tags for consideration in the have_selector matcher....
After thinking this was a Asynchronous issue, I first changed the Capybara wait time for requests, and then finally implemented this much cleaner and reliable solution to guarantee that all asynchronous requests had been completed by following this tutorial: http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara So after implementing the helper function, I know knew for...
ruby-on-rails,rspec,tdd,capybara,response.redirect
response is not available in feature specs. If you want to assert that the user is on a specific page after clicking a link, try: expect(current_path).to eq about_index_path A feature spec is used to test some functionality through an external interface, such as the browser. In feature specs, you'll generally...
ruby-on-rails,rspec,automation,capybara
Answer: If I understand you correctly then errors that appeared while completing the task @done = Module::Task.something(self.attribute) can be accessed via @done.errors.messages Example: If I have User model where attribute username has 2 validations: presence and format then error messages display like this: irb(main):019:0* u = User.new irb(main):022:0* u.save #...
ruby-on-rails,testing,capybara,stripe-payments,poltergeist
If I understand correctly... Capybara won't know about your ajax requests. You should be able to stub out AJAX requests with Sinatra. Have it return a fixtures much the same as VCR. Here's an article on it. https://robots.thoughtbot.com/using-capybara-to-test-javascript-that-makes-http You need to boot the Sinatra app in Capybara and then match...
ruby-on-rails,ruby,rspec,capybara
I discovered the answer thanks to Малъ Скрылевъ and Marek Lipka. I grepped for any "puts" in my code or any dependencies. YAMLs dump_steam method outputs "--- []" I was using a gem called smart_listing and inside one of the helper methods I found the code: puts args.to_yaml Newer versions...
looks like a validation error as you have validate :list, presence: true in your model and you didn't specify list in view. Can you recheck?
ruby-on-rails-4,rspec,capybara
I found 2 answers that might help people trying to use session in type: :view : You can use that gem: rack_session_access You have no other choice then reproduce all the needed steps to get the session you need ...
UPDATE: possible problems related to capybara/rspec: Avoid creating models in feature specs, because they're created in a different thread. Instead, create the user using capybara steps (i.e. "sign up" the user every time). If you really need the database prepared for scenario in a way impossible to create from clicking...
editor,capybara,capybara-webkit
So, this isn't the answer that I was expecting, and I'm not sure if this is the best way of doing it, but I found something that works. Some research revealed that I'm able to populate the content of the Editor using javascript, specifically editor.codemirror.setValue();. So I ensured the editor...
ruby-on-rails,testing,rspec,capybara,rspec-rails
The server is running in a separate thread. Since click on 'Save' doesn't wait for a response, when you immediately check the database, the server hasn't had a chance to do its work. When you wait for text to appear, you know the server update has completed.
ruby-on-rails,capybara,minitest
The problem is likely that "string_1", "string_2" and "string_3" are on different lines. In a regular expression, the dot (.) matches any single character except line breaks. You will see that the match works if the three strings are on the same line (ie no line breaks in between): html...
jquery,ruby-on-rails,rspec,capybara,bootstrap
You can simply check which environment Rails is running: if Rails.env.production? javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" else javascript_include_tag "/scripts/jquery/1.7.1/jquery.js" end There is most likly a plethora of gems for this though. Added: A nice eat the cake and keep it approach if you still want to use gems (like jquery-rails) and the sprockets...
php,ruby-on-rails,magento,capybara
Yes this is possible. You have to define the url where your server serves the pages you want to test. For example, if you use rspec simply do it in the spec_helper.rb. Additionally you have to specify a different driver that does not want to start the app (which is...
ruby-on-rails,testing,rspec,capybara
This should work if you only have one delete button on the page: it "is successful when clicking the destroy link" do visit "/users" click_link "Destroy" expect(page).to have_content("User was successfully destroyed.") Edit: I'm going to assume you are not very familiar with CSS selectors. With Capybara, when you say: #user_#{user.id}...
ruby-on-rails,ruby,cucumber,capybara,capybara-webkit
You mentioned that you edited many files. Could it be that you didn't revert all the changes you made? I think Capybara would pick the 'rack_test' driver by default, and your system could not find the 'rack' driver. Since you're doing Cucumber testing, you must have a file called 'env.rb'...
I think the rows_hash method will help you. def question_correct?(cucumber_table, question, answer) hash = cucumber_table.rows_hash return false if hash[question].nil? return hash[question] == answer end The code works by converting a two column data table into a hash, where the first column is the key and the second is the value....
Did not need database_cleaner gem. Turns out I was running rake spec which was truncating my DB each time. Instead if I run rspec spec the DB is NOT truncated.
capybara,phantomjs,poltergeist
It turns out file uploading is currently broken on Phantomjs 2.0. I downgraded v1.9.8 and attach_file works now.
rspec,capybara,poltergeist,summernote
Capybaras fill_in only works with html form elements. Since the JS version of your page is using a DIV with the contenteditable attribute as its text area to be filled #fill_in will not work. Instead you need to find the div and call #set on it directly. In your project...
previous_count = page.all('input').size click_on("Hide") new_count = page.all('input').size expect(new_count).to_not eq(previous_count) or expect do click_on("Hide") end.to change { page.all('input').size } ...
ruby-on-rails,fullcalendar,capybara
Use the select method http://fullcalendar.io/docs/selection/select_method/ It will trigger the select callback....
There are two issues: The href attribute exist on the a element rather than the li element. Elements do not have an href method. To get the attribute value use the [] method. Depending on your preference, any of the following would work: page.all('li').map { |li| li.find('a')['href'] } page.all('li a').map...
ruby,selenium,cucumber,capybara
This bug is fixed in this commit on April 1: https://github.com/cucumber/cucumber/commit/e92917c8f10a4907dedf26d77665116b69f3e3b9 The most recent release of Cucumber is 2.0.0, released March 27, so it seems the fix hasn't been released yet. You can point to the github repo in your Gemfile to get the latest available code: gem 'cucumber', git:...
php,ruby-on-rails,ruby,capybara,mamp
I don't know what kind of conflicts you expect from running Rails app and MAMP. But if you have ruby install on your mac then you simply can install gem with: gem install capybara Although I can't understand how would you use it out of rails app environment. RVM will...
ruby-on-rails,devise,capybara,minitest
Given your last comment, you are failing to authenticate. You want to avoid using a Factory. So you want to use a Fixture, which is what I am also using. In my case, here's my users.yml file (I call my users owners), which for me is in test/fixtures: owner: #...
I think this should work: # capture an array of the three stats: impressions/clicks/AVT stats = page.all('.sub').map(&:text) expect(stats).to contain_exactly("Impressions", "Clicks", "Average") Update Starting with Rspec 3, you could do the following, if you're looking for partial matching: expect(stats).to contain_exactly( a_string_matching(/Impressions/), a_string_matching(/Clicks/), a_string_matching(/Average/) ) ...
ruby-on-rails-4,rspec,devise,capybara,factory-girl
Apparently there are issues with Devise::TestHelpers and integration testing, so perhaps that's the problem here. https://github.com/plataformatec/devise (mentioned in README, Issues, etc.; also see related SO questions)...
ruby-on-rails,rspec,selenium-webdriver,capybara
After some more debugging, I realized that there was a subtle (didn't show in the logs, since server logs weren't being printed in my test environment) 414 error happening. Capybara apparently prevents long GET requests (though major browsers now support them), so I posted an issue here: https://github.com/jnicklas/capybara/issues/1467 I'd rather...
You can get the value of a select by calling .value on a Capybara::Node::Element. assert_nil page.find("#franchise_id").value or # Rails specific assert_blank page.find("#franchise_id").value ...
ruby-on-rails,rspec,selenium-webdriver,capybara
Looks to me like the logger is getting silenced via a call to logger.silence() by some other thread. When you put the sleep() in the code, then you yielded to some other thread that fixed the logging level - that's why it didn't matter how long the sleep was, it...
ruby-on-rails,capybara,phantomjs,poltergeist
Right, as of Feb 5th 2014 and v1.6 of poltergeist, you can do this, as ... @session.click_on "link_with_target _blank" @session.switch_to_window(@session.windows.last) #Do whatever you're doing @session.current_window.close @session.switch_to_window(@session.windows.first) Hope that clears things up for somebody......
ruby-on-rails,selenium,rspec,websocket,capybara
I solved this by writing a helper method that accepts a block of code. The helper method records the current time, then adds a function to the ajax start event that records the time that the ajax started in a sessionStorage variable. I can then run the code block passed...
Solved: was an issue related to the on document ready not being called (and in turn a portion of the javascript not being called) in certain contexts, solution was to use on window load function
ruby-on-rails,ruby,rspec,capybara
When testing the presence of a select list, there are two filters related to the options: :options - This checks that the select list options exactly match the specified array. :with_options - This checks that the select list options contains at least those in the specified array. The test is...
ruby-on-rails,ruby,rspec,capybara
Apologies, for I have done something embarrassingly dumb. I needed to have the user signed in to see the form content. Everything is working now.
ruby,date,datepicker,cucumber,capybara
Ideally, don't select by text if you can avoid it. But in this case try using a regex instead of just plain text. find('.day', :text => Regexp.new("^#{day.day}$"), match: :prefer_exact).click There's a little related reading at the end of this (currently unimplemented) issue: https://github.com/jnicklas/capybara/issues/1256...
ruby-on-rails,ruby,testing,selenium,capybara
One thing that helps is to use the save_and_open_page in your capybara tests. This way you can open up the html source of the test page and verify if your html id's and classes actually exist / are rendering the way you think they are. This has especially been the...
ruby-on-rails,ruby,devise,capybara,warden
1. As you can see here, login_as calls set_user with the same set of options. Here's the source code of set_user (click "View source"). On line 165, you'll see that if the :scope option is empty, the default scope will be used. In your Rails application, open config/initializers/devise.rb, you'll find...
you can do find(".element:nth-of-type(1)") find(".element:nth-of-type(2)") find(".element:nth-of-type(3)") or all(".element")[0] all(".element")[1] all(".element")[3] ...
ruby-on-rails,selenium,rspec,capybara
When you use the javascript-enabled driver, you'll want to use the truncation strategy instead of transaction. Replace your before(:suite) configuration with: # need to reset the database to a clean state before running the whole test config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end # set the default strategy to transactions since we want...
ruby,selenium,cucumber,capybara
I found the problem, it was because I had several files xxx_steps.rb in step_defintions folder and in each xxx_steps.rb I had "require 'watir-webdriver'" So each time cucumber met require 'watir-webdriver' it opened a new browser....
ruby,ruby-on-rails-4,rspec,capybara,capybara-webkit
It could be a couple of things The most obvious is that you could be having async problems because you're using Capybara. The Capybara/test thread tells the browser to click the button and then continues on. It doesn't wait for anything else to happen, so the browser could still be...
ruby-on-rails,ajax,capybara,poltergeist
This works when the expectations are flipped. find(someLocator).click expect(page).to have_css(appearingElementLocator) expect(page).not_to have_css(disappearingPlaceholderLocator) ...
ruby,ruby-on-rails-4,selenium,capybara,selectize.js
I got an answer on the capybara forums. Looks like it was a browser focus issue as @tmg mentioned. Thanks....
ruby-on-rails,rspec,capybara,automated-tests
you need to pass company_calender_id in params in specs, because you are passing it through hidden field and using it to find record in first line of update_by_day action. Try below one: put :update_by_day, {:day => company_calendar.day, company_id: @company.to_param, :company_calendar => { time_from: "2014-09-25 08:00:00", time_to: "2014-09-25 12:00:00" },:company_calendars_ids =>...
If your button is hidden, I think you need to do this: find(".playback", visible: false).click You can also try Capybara.ignore_hidden_elements = false find(".playback").click Capybara.ignore_hidden_elements = true ...
ruby-on-rails,angularjs,rspec,capybara
My guess is that your create(:fighter) call is running in a different thread (and database transaction) than the AJAX get request. Try adding this snippet to your rails_helper. class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || retrieve_connection end end ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection Source: https://github.com/jnicklas/capybara#transactions-and-database-setup...
ruby-on-rails,ruby-on-rails-4,rspec,capybara
From rspec 3.1, you can use compound matcher expressions with block expectations. expect { click_button 'Create Account' }.to change(User, :count).by(1).and change(Account, :count).by(1) http://rspec.info/blog/2014/09/rspec-3-1-has-been-released/#expectations-block-matchers-can-now-be-used-in-compound-expressions...
ruby,selenium-webdriver,cucumber,capybara
So, I just had to get the body and save its contents to a YAML file. body = @browser.find_element(:tag_name => 'body') f = File.new "#{path}/info.yml" f.write body.text ...
try: visit("http://#{user_environment}.myurl.co.uk")
ruby-on-rails,ajax,rspec,capybara,capybara-webkit
The key is telling rspec to wait for the ajax call to complete before doing any expectations. This is a great post on the solution that I used. Thoughtbot - automatically wait for ajax wioth capybara http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara ""...
By default capybara won't find non-displayed elements - if you really want find to return both visible and non-displayed elements you can do find(:xpath, "//td[text()='#{subtab}']", visible: :all) a better solution would be to do if page.has_no_xpath?("//td[text()='#{subtab}']") # if the subtab is not visible click the tab find(:xpath, "//td[text()='#{tab}']").click end find(:xpath,...
I agree with Raza. Definitely try to set a class on the elements you're looking for. If that turns out to be impossible for whatever reason, here are a couple more options. 1) You could try regular expressions: # match text that doesn't contain 'Main' page.all('li.tab.exist', text: /^(?:(?!Main).)*$/) That's not...
selenium,selenium-webdriver,capybara,homebrew,homebrew-cask
As the error msg says: You have to specify Selenium::WebDriver::Firefox::Binary.path for custom app paths. # in spec_helper.rb Selenium::WebDriver::Firefox::Binary.path = "/opt/homebrew-cask/Caskroom/Firefox/latest/Firefox.app" # or the path to the exact binary, cannot test atm, please tell which one works: Selenium::WebDriver::Firefox::Binary.path = "/opt/homebrew-cask/Caskroom/Firefox/latest/Firefox.app/Contents/MacOS/firefox" If you don't want to touch the test framework, you can...
routes,cucumber,capybara,padrino
Capybara deliberately uses example.com if you don't set app_host, and since I redirect if the domain is incorrect, that's unacceptable so I have to set app host in my features/support/env.rb file like so: Capybara.app_host = 'http://arewesmallyet.dev'...
ruby-on-rails,ruby,testing,rspec,capybara
let block is not executed unless it is called in the test itself. Because you are not using this variable prior to visit_page, crew model is not created and hence it is not displayed on the page capybara is playing with. If you want it to execute before each test,...
ruby-on-rails,rspec,tdd,capybara
In the "Display the todos list" block you are not logging in: you need to either have a similar before(:each) as in the "User login" block or move the entire "display todos" block inside the "User login" block.
ruby-on-rails,ruby,rspec,capybara
There's no easy way to accomplish what you want. The feature spec is handled mostly by Capybara, not RSpec. Capybara runs the majority of the browser / rails server behavior in an external process. This make it inaccessible from RSpec's point-of-view. Thus you cannot use stubs / doubles in this...
The exception is occurring in the within_frame method when trying to switch back to the parent frame. It seems like a bug, so th best thing to do would be to raise it as an issue in the Capybara project. In the meantime, the quickest solution would be to rescue/ignore...
ruby,selenium,selenium-webdriver,webdriver,capybara
There are different location techniques and ways to get to the desired element. stock-description-input class looks like a good thing to rely on. Use send_keys() to fill the area: text_area = first(:css, 'textarea.stock-description-input').native text_area.send_keys('Test') ...
ruby-on-rails,testing,rspec,capybara
I tried to success this spec. Please check out I commented here in spec file. You selected Dec 15 Dec 2018. That's why the result was also 15 Dec 2018. Prerequisite: rails g scaffold Appointment title date:date starts_at:time ends_at:time Spec file: require 'rails_helper' describe "Appointments", :type => :feature do describe...
ruby-on-rails,ruby,rspec,capybara
I've managed to fix it. It was caused by Strong Params and Devise. I've set Devise to work with name and username parameters and they were not being authorized, even when explicitly cleared in controller. Here is what I did: Generated Devise Controllers: $ rails g devise:controllers Added the new...
ruby-on-rails,ruby,rspec,capybara
You need to require rails_helper not spec_helper. The problem is that Capybara is calling Rails.root.join before your Rails app has fired up (which is taken care of in your Rails helper).
capybara,integration-testing,poltergeist
I think I understand your question. You could do something like this: it "doesn't find element" do visit whatever_path expect { select "NotARealOption", from: "bo" }.to raise_error(SomeCapybaraError, "no match found") end ...
Update that works: prompt = page.driver.browser.switch_to.alert prompt.send_keys('test') prompt.accept ...
ruby-on-rails,unit-testing,rspec,capybara
Libraries such as Machinist and FactoryGirl allow you to create entities using a template which has reasonable defaults, so that you only need to specify the properties that are relevant to the test. It's very common to use them in tests, as an alternative to fixtures.
After more investigation, it seems that the element was rightly not disappearing, because of another issue. Failure/Error: expect(@page.thing.results.map(&:text)).to include a_string_matching 'search_query' expected ["Searching…"] to include (a string matching "search_query") Diff: @@ -1,2 +1,2 @@ -[(a string matching "search_query")] +["Searching…"] That "Searching..." display happens for a split second, and needs to...
You could test with Capybara, so long as you use a driver that supports javascript, such as Selenium or Poltergeist - see https://github.com/jnicklas/capybara#drivers However, although I'm not an AngularJS user, I do know that it's designed to be testable, and I imagine you'd be much better off using a tool...
ruby-on-rails,rspec,capybara,poltergeist
This should work: Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, timeout: 1.minute) end Are you having long running javascript or ajax? https://coderwall.com/p/aklybw/wait-for-ajax-with-capybara-2-0 and http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara - how to handle ajax There is also a way to disable animation in tests, to make it run faster. And you have some elements with position: fixed...
In standard ruby delegation is handled by the module Forwadable. You need to require and then extend forwardable to access these methods like so: require 'forwardable' module Capybara::DSL extend Forwardable #notice syntax is accessor, *methods def_delegators :page, :datepick, :datetimepick, :timepick end The type of delegation you are trying to use...
rspec,webkit,capybara,phantomjs,headless-browser
Phantom 1.9 (and earlier) uses a version of webkit that is a few years old (roughly equivalent to Chrome 13), whereas the just-released Phantom 2.0 uses a webkit that was released in mid 2014 IIRC. There is quite a large difference between the amount of supported HTML5 features in them,...
ruby-on-rails,rspec,capybara,capybara-webkit
accept_confirm and dismiss_confirm will only accept or dismiss the modal. If you want to compare the text the you can take the return value of accept_confirm in a variable and then later you can compare it. message = accept_prompt(with: 'Linus Torvalds') do click_link('Show Prompt About Linux') end expect(message).to eq('Who is...
ruby-on-rails,rspec,capybara,poltergeist
Whenever I run into these inconsistencies, I try to find other things to assert against so that you don't have to count on sleep. If there are any sort of animations that start/stop, you can try to assert against those. You can also try to be more specific in your...
Where possible, you should try to avoid using the underlying driver directly. By using Capybara's API, you would be (in theory) in a better position if you want to change driver's and there are driver API differences. From Capyabara's project page, the way to handle modal dialogs is: In drivers...
I think what you are looking for is the string value of an element. The string value of an element node is just the concatenation of all its descendant text nodes. Using the expression string(//a) on almost (to avoid any unrelated problem with single or double quotes in the text...
You are mapping a label and trying to treat it as a radio? perhaps map the input which has type=radio, most likely then you will be able to use choose method for that element: choose("i-20-1") not sure if you really need the # prior to the id for choose method......
javascript,ruby-on-rails,ruby,rspec,capybara
Eventually I found that the path to one of my javascript files was incorrect. Thus, a parse error was determined. To find this error, I used remote debugging with Poltergeist and was able to see this error more clearly. To do this: Capybara.register_driver :poltergeist_debug do |app| Capybara::Poltergeist::Driver.new(app, :inspector => true)...
google-maps,capybara,phantomjs
Using the latest experimental version of Google Maps (v3.19), which includes a workaround, fixed this problem for me: https://code.google.com/p/gmaps-api-issues/issues/detail?id=7475#c20 [Edit] Google Maps v3.19 was released as the production version on 17 Feb 2015. Also, PhantomJS version 2 was released on 23 Jan 2015 incorporating an updated WebKit module which doesn't...
SOlved it guys. i had to make sure i was referencing the tag which includes the link **find("ul.nav.nav-tabs li.col-sm-4.col-md-4 a", :text=> 'TOOLS').click** ...
ruby,selenium,rspec,capybara,browserstack
The bits of advice I can give you is: 1:. Each test should be a single use case scenario. If it fails you know why 2:. If you need to perform many steps to achieve a use case scenario then you should be abstracting your elements into classes that represent...
Yes, Capybara is right tool for it. You can also use Ruby with Selenium webdriver(Would be awesome with page object gem) or Ruby with Watir webdriver. To visit and test any web application, you can use Ruby and Capybara. For this you need to set app_host. Add this one in...
ruby-on-rails,ruby,devise,capybara
Found an answer. I installed the warden gem to (gem 'warden') and factory girl gem (gem "factory_girl_rails", "~> 4.0") and ran a bundle install. I then created a user fixture with factory girl as follows in a factory.rb file in the spec folder: # This is a user factory, to...
ruby,testing,sinatra,capybara,minitest
I've done some research for you, and I'll share with you what I've found. In order for doing this, you should consider "converting" your Minitest tests, to specs. This gives you access for similar syntax, as RSpec's - describe with capability of nesting them. I'll simplify the code to provide...
CSS In CSS you could use a sibling selector. These allow you to select sibling elements; or those at the same nesting level and with the same parent element. There are two types of sibling selectors: '+' the adjacent sibling selector '~' the general sibling selector (adjacent or non-adjacent siblings)...
ruby,ajax,ruby-on-rails-4,rspec,capybara
After posting on the capybara forums, I have found out that some selectors have wait for async calls to finish and some don't. All I had to do to get this spec to pass was to update the expectation to the below expect(page).to have_css('.follow-up', count: 30) Some useful resources I...
ruby-on-rails,ruby,rspec,capybara
I think you are overengineering the task. Since you are to run it once, just run it: cb = lambda { puts 'I am run once' } RSpec.configure do |config| cb.call end ...
Cucumber takes control of all puts messages so it can pass it along to all the formatters. In the After hook try STDOUT.puts instead...
Your spec is getting run, but because it is malformed, there are no examples in it. If you were to format it properly (e.g. in terms of indentation), it would be more clear, but your background blocks include both of the associated scenarios. You need to delete the last two...
Maybe try: resources :items, only: [:new, :create, :show, :index] If you run rake routes at the command line, it should show you the routes available for your app (and help explain the above). Also, in case you haven't already read it: http://guides.rubyonrails.org/routing.html...
ruby-on-rails,ruby,rspec,capybara
You should use mocks - https://www.relishapp.com/rspec/rspec-mocks/docs. user = double("user", id: 1, save: true) Then you should mock you method with double you've just created expect(User).to receive(:new).and_return(user) And then test redirect. expect(response).to redirect_to user_path(user) I hope this will help....