capybara

How do I attach a file when the input.file has a dynamic id?

左心房为你撑大大i 提交于 2020-01-15 04:28:43
问题 I have run into a snag with dynamic ids. The attach_file command needs the id name of the input type="file". The problem is that the id is dynamic (id="document_22") #indicating the 22nd document uploaded to this section. Is there a way to get the id of an element? something like... attach_file(find(:xpath, ".//input[@name='file_upload']").get('@id'), 'C:\\Users\\testbox\\Documents\\testdoc.xls') 回答1: attach_file internally just passes filename to Capybara::Node::Element#set method. So you

Capybara::ElementNotFound: Unable to find xpath “/html”

谁说胖子不能爱 提交于 2020-01-14 10:13:08
问题 I'm following the Ruby on Rails tutorial at http://ruby.railstutorial.org/chapters/static-pages and came across the following error StaticPages Home page should have the content 'Sample App' Failure/Error: page.should have_content('Sample App') Capybara::ElementNotFound: Unable to find xpath "/html" # (eval):2:in `text' # ./spec/requests/static_pages_spec.rb:7:in `(root)' My Gem file is as follows source 'http://rubygems.org' gem 'rails', '3.0.10' gem 'jruby-openssl' gem 'activerecord

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

╄→гoц情女王★ 提交于 2020-01-14 09:42:50
问题 I'm reading through Rails 4 in Action. I'm getting the aforementioned error while testing with Rspec and Capybara. My viewing_projects_spec.rb looks like this: require 'spec_helper' feature "Viewing projects" do scenario "Listing all projectcs" do project = FactoryGirl.create(:project, name: "TextMate 2") visit '/' click_link 'TextMate 2' expect(page.current_url).to eql(project_url(project)) end end The rest of the error says Failure/Error: expect(page.current_url).to eql(project_url(project)

How to use Cucumber to test non-Ruby, non-Rack API's

不羁的心 提交于 2020-01-13 19:00:28
问题 I use cucumber for lots of things. I really like it as a BDD environment. So I'd like to use it as an external tool to test an API. I'd like to do things like: Scenario: Hit api /info path and get info back When I visit the API path '/info' Then I should see the following text "Here's info on the API" or something similar. I mainly want to treat the API as a black box and test only inputs and outputs. I don't plan on inspecting anything inside the API. Most of the libraries I've looked at

Undefined method 'visit' for #<Class:XYZ> (NoMethodError) [rspec]

瘦欲@ 提交于 2020-01-13 05:24:39
问题 I'm getting the following error when I try to run an rspec test: /srv/offerme/spec/requests/static_pages_spec.rb:13: undefined method `visit' for #<Class:0xb3436684> (NoMethodError) from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval' from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass' from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe' from /srv/offerme/spec

Capybara, Devise, CanCan and RSpec integration tests: valid sign in 302 redirects to example.com

你离开我真会死。 提交于 2020-01-11 06:21:56
问题 Update: see end of post for how the specs now work now that I have my specs in spec/requests instead of spec/controllers. Still wondering how to get a valid signed in user for integration tests with my controllers. I'm working with Devise and CanCan for the first time and am having difficulty doing the most basic of integration tests whereby I'm verifying that a logged in user is...well...logged in. I have read countless posts and answers dealing with Devise and RSpec integration tests (i.e.

Error while building native extensions for capybara-webkit

流过昼夜 提交于 2020-01-11 05:43:13
问题 I'm trying to install the webkit driver for capybara on Windows, and I'm getting the following error: $ gem install capybara-webkit-0.12.1.gem Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing capybara-webkit-0.12.1.gem: ERROR: Failed to build gem native extension. c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb Gem files will remain installed in c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/capybara

Facebook test accounts using selenium - failing to log in my fake users

夙愿已清 提交于 2020-01-11 03:42:06
问题 I am programmatically creating test accounts, and then immediately trying to log in w/ them using a selenium driven browser. Unfortunately, the browser is just redirected to the facebook homepage. I can briefly see what appears to be the correct url prior to the redirect flash by, so I have no reason to believe the browser isn't going where I intend it to. That said, if create a fake account, and then just paste the login_url into a browser, things work fine. Anyone have any idea why that

Why not use shared ActiveRecord connections for Rspec + Selenium?

扶醉桌前 提交于 2020-01-09 03:01:06
问题 It seems the most commonly accepted way to deal with Selenium and tests is to avoid using transactional fixtures and then using something like database_cleaner between tests/scenarios. I recently ran into the following article which suggested doing the following: spec_helper.rb class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || retrieve_connection end end # Forces all threads to share the same connection. This works

How to assert that image has been uploaded with Capybara?

我们两清 提交于 2020-01-07 06:36:23
问题 Let's say I have a form where user can create a post with an image attached to it. I want to make sure the image attached is displayed on the next page: visit url fill_in the_form click_on 'Create' assert_selector '.post' post = Post.first img = page.find '.post .image' assert_equal post.file.thumb.url, URI(img[:src]).path But I'm told asserting against database objects in system tests is to be avoided. What do I do then? 回答1: So long as there's no "complex" file renaming happening on the