FAQ Database Discussion Community


Could I use Capybara on frameworks outside Rails (PHP)? [closed]

php,ruby-on-rails,magento,capybara
I would like to test my php web app (specifically Magento) with Capybara. I've used Capybara with success when I used rails before so I want to replicate the success. Does anyone know if this is possible or maybe there is a Capybara for php?

Testing Rails app with RSpec and Capybara

ruby-on-rails,rspec,capybara
In testing my rails app (using RSpec and Capybara) I am having troubles testing AngularJS functions (from the Users point of view). Can I not test with only RSpec and Capybara or do I also need something like protractor? any help would be great! thank you!...

After-hook scenario.exception does not exist in Cucumber 2.0

ruby,selenium,cucumber,capybara
I'm using Capybara, Cucumber, and Selenium-Webdriver for basic web testing. If a test fails, I want to capture the failure message and send it to a separate log file. Cucumber offers hooks to catch the failure message after the scenario fails (from their wiki): After do |scenario| if scenario.failed? subject...

Entering text into an alert

selenium,capybara
I'm currently having difficulty writing a test that enters text into an alert prior to accepting/dismissing said alert. I'm able to accept an alert with: page.driver.browser.switch_to.alert.accept However, when I attempt to use the following to enter text into the alert with: page.driver.browser.switch_to.alert.text("test") I get the following error: Failure/Error: page.driver.browser.switch_to.alert.text("test") ArgumentError:...

Faking instance variable in RSpec and Capybara feature spec

ruby-on-rails,ruby,rspec,capybara
I'm trying to set up some feature specs before I get into refactoring some of my company's old code. It's kind of an unconventional setup, but I was able to figure out enough about test doubles to bypass the authentication enough to get started. One problem I'm still having is...

How can I test multistep forms with Capybara & Minitest?

ruby,testing,sinatra,capybara,minitest
I have a single page Sinatra app that has a multistep form/wizard interface. If I want to test the form with Capybara, will need to repeat all the steps for each test? I'm hoping to avoid something like this: it "visits the home page" do vist "/" page.should have_content('foo') end...

Logging for rspec selenium/capybara tests running in Browserstack

ruby,selenium,rspec,capybara,browserstack
I am building a set of automated regression tests in ruby using rspec and capybara. To give you an idea of a test, imagine logging in to a website, adding a new data item with all of its fields, saving it, validating the new row, updating the row, changing fields,...

Rspec. Delete action doesn't work with let()

ruby-on-rails,ruby,testing,rspec,capybara
I have Rspec testing controller actions via visiting pages. And when I'm declaring new object through let() for create and edit actions - it's all fine. But for delete it doesn't work and I have to declare instance variable to make it pass. My goal is to get rid of...

Run block once before all capybara tests

ruby-on-rails,ruby,rspec,capybara
I'm using Capybara with Rspec for integration testing a rails app. Is there any way to run a before block once before the first Capybara test runs without it running before every feature spec? Putting a block in my RSpec.configure block as such causes it to run before each feature...

Capybara testing with jQuery, Bootstrap, and jQuery-ui from CDN

jquery,ruby-on-rails,rspec,capybara,bootstrap
I am getting jQuery, jQuery-ui, and Bootstrap from CDNs in my app. Since I switched over to using CDNs instead of gems, I am getting errors in my specs that they can't find $. Is there a way to download a copy of these scripts and have my specs use...

Rails 4 Rspec test session when assigned in spec

ruby-on-rails-4,rspec,capybara
In my test i assign session to a specific value but when i run the test and print from my app controller, the session is nil. Any idea how should i do this ? Here is my spec : RSpec.describe "welcome/index.html.haml", type: :view do before(:each) do session[:followed_repos] = ["rails/rails"] end...

Capybara - Determine if selector count has changed

ruby,rspec,capybara
I am writing a test to confirm that hidden (Note: not destroyed. They are hidden using a boolean DB field) items no longer show up on my page. I know with Capybara I can use the following to confirm a selector's count: expect(page).to have_selector('input', count: 12) Is it possible to...

Rspec/Capybara features tests not running, even with _spec.rb ending

rspec,capybara,rspec-rails
When I run my Rspec feature examples, they are not being detected. When I specify the route to my /features folder, the message I get is " No examples found". I'm not sure if it's a requirement issue or something I'm missing with my test. my feature test: require "rails_helper"...

How to select repeated element with Capybara

ruby,rspec,capybara
I know how to get the first element, but how can I get the second or third element found with that class x ? Only way is by choosing from an Array like below? If so, starts at zero or one ? find(".element")[1]...

Is it possible to download an YAML contained in a webpage using Page Objects / Capybara / Selenium Webdriver?

ruby,selenium-webdriver,cucumber,capybara
I have a webpage that just displays a YAML file. Is there anyway I can get that YAML file so I can save it using a cucumber project (that uses Page Object, Capybara and Selenium Webdriver and it's in Ruby). Thanks...

Why is rspec example with AJAX not working correctly?

ruby,ajax,ruby-on-rails-4,rspec,capybara
I am having a problem with running integration tests that contain ajax in them. For example the test below scenario 'displays next page when scrolling to the bottom of the page', js: true do scroll_to_bottom_of_page wait_for_ajax expect(all('.follow-up').count).to eq(30) end Implementation for scroll_to_bottom of page method def scroll_to_bottom_of_page page.execute_script "$('.off-canvas-wrap').scrollTo('.exit-off-canvas');" end...

How to wait until an element disappears in Capybara?

ruby,capybara,site-prism
Note: by the time I finished writing up this question, the solution presented itself, but maybe others may find this useful, or could offer alternatives. I have read the following articles: this thread: https://groups.google.com/forum/#!topic/ruby-capybara/Mz7txv1Sm0U this poltergeist issue: https://github.com/jnicklas/capybara/issues/19 this blog: https://nulogy.com/articles/sleep-is-for-the-weak#.VNVcIrDF8vs and this stackoverflow question: Capybara synchronize with has_no_css? but...

How can I find a certain element that comes right after another element with Capybara?

capybara
I am trying to use learn Capybara for a scraping task I have. I have heretofore only used it for testing. There are a million things I want to learn, but at the very basic part of it I want to know how to find a certain element that is...

How do I install ruby gems on OS X without rails? [closed]

php,ruby-on-rails,ruby,capybara,mamp
I'm trying to install the capybara gem on OS X. The issue is I am running MAMP, and do not wish to run rails due to potential conflicts. How can i install a gem? Where would a Gemfile even be without a application folder?

Capybara can't find user for delete action

ruby-on-rails,testing,rspec,capybara
I'm using RSpec (v. 3.1.0) and Capybara (v. 2.4.3) to test my Rails 4 application. My user delete spec.rb contains the following code: it "is successful when clicking the destroy link" do visit "/users" save_and_open_page within "#user_#{user.id}" do click_link "Destroy" end expect(page).to have_content("User was successfully destroyed.") Capybara throws the following...

Can rspec be used to feature test an integrated rails-angular app?

ruby-on-rails,angularjs,rspec,capybara
I have a very basic, integrated rails-angular app. It just renders a link, which uses data from a get request to rails: 'use strict'; angular.module('angularRspec.controllers') .controller('FightersController', function($scope, $http){ console.log("FightersController is loaded..."); $scope.fighters = []; $http.get('./fighters.json'). success(function(data, status){ $scope.fighters = data; console.log(status); console.log(data); }). error(function(data, status, headers, config) { console.log(status); console.log(headers);...

Capybara: Sometimes finds elements, sometimes doesn't

ruby-on-rails,ruby,testing,selenium,capybara
Hello dear Stackoverflowers. I'm having some seriously insanely annoying trouble with my capybara test. It seems to have a mind of its own and will sometimes decide to run with zero issue and sometimes decide to not find elements, click anything and generally just suck. I have no idea why...

Capybara error: undefined method `join' for nil:NilClass

ruby-on-rails,ruby,rspec,capybara
After installing Capybara, I get the error: NoMethodError: undefined method `join' for nil:NilClass whenever I try to run rspec. I've been trying to add and remove different requirements, but nothing seems to work. Does anyone have any idea what's happening? spec_helper.rb RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions =...

Hidden buttons Capybara

ruby-on-rails,ruby,capybara
I am trying to test a hidden button in capybara but so far have not been able to get it to work without the following error. undefined method `click_on' for [#<Capybara::Element tag="button">] Could someone possibly suggest the correct syntax to do so. The call is below: When(/^I tap on the...

How do I match link text that is wrapped in an html tag using xpath?

html,xpath,capybara
I have this link: <a href="/stores/non-consequatur-totam/products/search?term=yellow"> Search all categories in <span style="font-weight: bold;">non consequatur totam's</span> store for “yellow” </a> I am trying to match it using xpath, but I can only match the portion before the span, using contains and text(). I am using capybara. page.all(:xpath, "//a[contains(text(), 'Search all categories...

Fill in Editor textarea using capybara-webkit

editor,capybara,capybara-webkit
I'm using a markdown editor on my page, which I'm trying to target, and fill in, using capybara-webkit, but without any luck. My template looks like this <%= simple_form_for form, url: url, method: :put do |f| %> <%= f.input :notes, as: :text %> <%= f.button :submit, class: 'fluid' %> <%...

Issue getting element to display on page Capybara

ruby-on-rails,ruby,capybara
context: element x clicked (initiates request) in the background, request intercepted by javascript, default action prevented (submit form), new element (element y) added to page (confirmation dialog) The problem is that it seems that the request is not being intercepted by the javascript and element y, is in turn not...

Creating a url with a method result

ruby,cucumber,capybara
I am trying to create a dynamic url so that multiple users can use an application on their VM. I have this method def user_environment env = ENV['SERVERNAME'] return env end Which will return environment1 environment2 for example. I want to use the method to construct a url and then...

Minitest/Capybara/Devise login is not progressing past sign in page

ruby-on-rails,devise,capybara,minitest
Following some information from this example: http://snippets.aktagon.com/snippets/644-how-to-test-authentication-with-devise-capybara-minitest I have the test half running. But the click_on method isn't submitting the form. I've also tried click_button 'Sign in' and page.execute_script("$('form').submit()") without any luck. Here' the test: # test/integration/login_test.rb require "test_helper" require "minitest/rails/capybara" class LoginTest < ActionDispatch::IntegrationTest include Rails.application.routes.url_helpers include...

Opening a new tab in Capybara / Poltergeist

ruby-on-rails,capybara,phantomjs,poltergeist
I'm trying to open a link by clicking on it using capybara/poltergeist which opens up in a new tab. I can't seem to get it working. @session.find(<link>).click just seems to stay on the same page, as does click_link "<link>" @session.driver.window_handles Only seems to give me 1 window whatever I'm doing....

Is element visible?

ruby,capybara
I have an error when I try to check if some element is visible. My method is the following: if find(:xpath, "//td[text()='#{subtab}']").visible? find(:xpath, "//td[text()='#{subtab}']").click else find(:xpath, "//td[text()='#{tab}']").click find(:xpath, "//td[text()='#{subtab}']").click end In if find(:xpath, "//td[text()='#{subtab}']").visible?, I have: Capybara::ElementNotFound: Unable to find xpath "//td[text()='Plan List2']" but when the element is correctly visible,...

Rails RSpec testing a simple link redirect_to path

ruby-on-rails,rspec,tdd,capybara,response.redirect
I am having difficulty writing an RSpec test in a rails app to make sure that a simple link from my app's homepage redirects to the about page. I have the following in my feature test file: scenario "Have links redirect to the correct paths" do visit '/' click_link('about') expect(response).to...

Can I configure rspec + capybara to not blow away by DB each time?

ruby-on-rails,rspec,capybara
I know that generally you want your test suite to run against a freshly configured set of data each time tests are run. However, I have a site with a fairly set of static data. Is it possible to have my tests run against my local db that has been...

Capybara won't fill in form fields (although it finds them)

ruby-on-rails,ruby,rspec,capybara
I'm developing a Rails 4.2.1 using Ruby 2.2.1 and Capybara 2.2.4. Writing a spec to sign up users, Capybara does find the fields (I'm not getting the ElementNotFound Error) but when I try to validate I get a failure that all fields were empty and also opening launchy before telling...

Make capybara wait for an element to disappear

ruby-on-rails,ajax,capybara,poltergeist
After a click on some element I expect a placeholder to disappear and another element to appear after an AJAX call is finished. find(someLocator).click expect(page).not_to have_css(disappearingPlaceholderLocator) expect(page).to have_css(appearingElementLocator) The first expectation fails though and the AJAX call is not executed. I think this is somehow related to this SO question...

Capybara assert nothing selected from dropdown

ruby-on-rails,capybara
I'm trying to assert that none of the options from my dropdown have been selected, but the following all fail: assert page.has_select? "franchise_id", selected: nil assert page.has_select? "franchise_id", selected: false assert page.has_select? "franchise_id", selected: "Pick a Franchise" I just want to test that my select input has nothing selected. How...

If I stub out .save method in my controller test how can I check the correct show template is rendered?

ruby-on-rails,ruby,rspec,capybara
I am trying to test a controller create method in a rails app using RSpec as shown below: def create @user = User.new(user_params) if @user.save redirect_to user_path(@user.id) else render new_user_path flash[:error] = "User not saved" end end However if i stub out .new to prevent the test from using Active...

What is the difference between User.make and User.new?

ruby-on-rails,unit-testing,rspec,capybara
In Capybara docs, it has describe "the signin process", :type => :feature do before :each do User.make(:email => '[email protected]', :password => 'password') end it "signs me in" do visit '/sessions/new' within("#session") do fill_in 'Email', :with => '[email protected]' fill_in 'Password', :with => 'password' end click_button 'Sign in' expect(page).to have_content 'Success' end...

Increasing timeout of poltergeist

ruby-on-rails,rspec,capybara,poltergeist
I need to increase the length of the timeout in Poltergeist. The poltergeist documentation says I need to put this code in my test setup Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, options) end I am new to testing I am not sure where the test setup. I am using Rpsec and...

How to set text into Summernote textarea with Capybara + Poltergeist

rspec,capybara,poltergeist,summernote
I have a textarea which is using Summernote and I set onChange event to it. I want to write test with RSpec + Capybara + Poltergeist to confirm the onChange event is working. As far as I checked, the textarea displayed in browser is actually div tag with 'note-editable' css...

Using After hooks for each tag specified

ruby,cucumber,capybara
I am trying to get to grips with Cucumbers After Hooks and would like to run a hook after every tag in a feature. So for example within my feature login.feature I have multiple scenarios, each with their own tag Feature: Login to myApp with various Users @login_user_1 Scenario: Load...

How can I test Stripe.js using poltergeist and Capybara?

ruby-on-rails,testing,capybara,stripe-payments,poltergeist
I've been going nuts trying to write an automated test for my user sign up page. Users will be charged a recurring subscription via Stripe. They input their basic details (email, password, etc) and their credit card details on the same form, then the following flow happens: (On the client-side)...

How to map browser dialog using capybara/selenium

ruby,selenium,capybara
What is the best way to handle browser dialogs (with ok/cancel buttons) using capybara/selenium? The way I found easiest is by running the following: dialog = page.driver.browser.switch_to.alert dialog.accept Any thoughts for a better approach? Whoever downed this post please give a valid reason... it's not helpful to down vote with...

Capybara::ElementNotFound radio by id

ruby-on-rails-4,capybara
I understand the syntax for Capybara choosing a radio button is the following choose("Label Name") I am running into an issue with doing this for a label that has its default name changed to an #id. Here is my HTML <label for="school_application_I_20"> Do you require an I-20 Form?</label> <br> <label...

Capybara: How to fill a textarea without an 'id'?

ruby,selenium,selenium-webdriver,webdriver,capybara
I am in need to fill_in a textarea which does not have an id. Following the inspection: <textarea class="stock-description-input js-short-description-textarea" placeholder="Select a product or enter a description" maxlength="64"></textarea> Have you got an idea how to do it?...

How can I trigger the select callback in FullCalendar for testing purposes?

ruby-on-rails,fullcalendar,capybara
I'm trying to test the select callback of FullCalendar in Ruby on Rails app with Capybara (poltergeist as driver). Any idea how to do this?...

Using result of raise_error (capybara)

ruby-on-rails,rspec,automation,capybara
I'm using capybara to do some web automation. There are various points in the code where it says things like raise_error 'Failed as this is a duplicate' if duplicate? or raise_error 'Failed to log in' if logged_in? == false All of this is abstracted to a module and I'd prefer...

Capybara: simple way to find elements without particular text

capybara
There are several elements on the page, and I need an array of them, but without an element with particular text. What I do now is tabs_quantity = page.all(:css, 'div.class1 ul.tabs li.tab.exist', visible: true) tabs_quantity.each { |x| if x.text != 'Main' ...blah-blah-blah... I`ve seen only ":text => 'Text' everywhere but...

cucumber capybara testing date picker selects wrong day

ruby,date,datepicker,cucumber,capybara
I am trying to write a cucumber test for a page that includes a datepicker. I swear this was working yesterday, but not so much today. Then(/^select date (\d+) day(?:s|) prior to today$/) do |n| day=Date.today-(n.to_i) target = Date.strptime("#{day}",'%Y-%m-%d') target_month_year = target.strftime('%B %Y') selected_month_year = (find('.datepicker-switch').native.text) unless target_month_year == selected_month_year...

Wait for Websocket Rails event to finish in test environment

ruby-on-rails,selenium,rspec,websocket,capybara
I am using the Websocket Rails gem in my Rails application to send an event that triggers a refresh of part of the page. All is working fine, but in my testing (I am using Rspec + Capybara + Selenium) I can't seem to find a way to wait for...

Switch between windows with frames

ruby,capybara
I have main window with frames and a popup where I do some operations: within_frame("MainFrame") do find("btnNewItem").click #opens popup window end within_window(windows.last) do within_frame("frmFrame2"){ some_operations find("btnOK").click #closes a popup } end within_window(switch_to_window(windows.first)) do within_frame("MainFrame") do find("btnDeleteItem").click #deletes item accept_popup_dialog end end But when operations are done in popup window and...

Dropdown not getting selected when it should be … why?

ruby,ruby-on-rails-4,selenium,capybara,selectize.js
I am trying to solve a bug in our tests that in my opinion should be working. I am pretty sure it's a bug in selectize or capybara, but I can't figure out why. I have gone into the source for capybara and everything seems like it is working like...

How do I use phantomjs uploadFile with Capybara and poltergeist?

capybara,phantomjs,poltergeist
I am trying to attach a file in my spec, but the capybara attach_file method does not work for me in poltergeist (it returns true but nothing gets attached). It does work in Selenium, but for other reasons I want to use poltergeist. I know that the phantomjs uploadFile method...

How do I use the latest Webkit version for Capybara specs using PhantomJS?

rspec,webkit,capybara,phantomjs,headless-browser
A fellow developer told me that PhantomJS uses an old version of Webkit, and that this prevents him from always trusting the results he gets from running Capybara specs using PhantomJS. To my knowledge, PhantomJS is the best headless browser available for running Capybara specs. The only alternatives I've found...

Poltergeist/Capybara test unable to find CSS intermittently

ruby-on-rails,rspec,capybara,poltergeist
I'm using Capybara and Poltergeist and cannot for the life of me get all my tests to consistently pass. I have this one issue in particular with a date selector. It should be really simple - user clicks on input, out puts a selection of months (first image). A month...

Step definitions for cucumber data tables for storing correct answers

ruby,cucumber,capybara
I am trying to find a way to test multiple choice questions. The structure is that a lesson has 8 stages and each stage contains multiple choice questions with only one correct answer. The loading of the questions is random each time so i have been looking for the best...

Writing multiple feature spec expectations from a single action

ruby-on-rails,ruby-on-rails-4,rspec,capybara
So I'm writing my feature test and it goes something like this, note the [[place_holder]] feature 'Accounts' do scenario 'creating an account' do # visit and fill form expect { click_button 'Create Account' }.to [[place_holder]] success_message = 'Your account has been successfully created.' expect(page).to have_content(success_message) end end Now I want...