Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Combating false positive failures in CI

code { color: inherit; background-color: inherit; padding: inherit; } h3 { font-weight: bold; } Scope and the problem

If you experience a CI build turning red due to an intermittent failure, such as in a Capybara test, this post is for you.

Read more »

LABS
Capybara's save_page with CSS

At Pivotal, we often use Capybara to write a suite of integration tests that navigate a browser through any scenario that can emerge in the application. We use these tests to guard against regressions and to drive out the design of the application in a red-green cycle throughout the day.

Read more »

LABS
How To Test PDFs with Capybara

Solution – GitHub Gist

Validating that a web app’s content is rendered correctly is an integral part of testing web apps. Displaying user-submitted input in HTML is the core functionality of almost any website. For example, the last couple of web sites you used most likely had you enter information in a text box that was later shown to you on another page.

Read more »

LABS
Accessibility Errors Are Breaking Your Build

Imagine if someone flipped a switch on your project that broke your entire integration test suite with failures that surfaced critical, long standing bugs in production that render your site useless to many thousands of users.

Hundreds of failures in CI, up on a monitor for everyone to see.

Read more »

LABS
Automated Accessibility Testing in Rails with capybara-accessible

capybara-accessible is an automated accessibility testing tool that has been recently released by Case Commons, with Pivotal Labs contributions. Here’s a description of capybara-accessible, how it works, and an explanation of some of the technical decisions we’ve made.

What does it do?

Read more »

LABS
Less is more in Capybara 2.1

One of my favorite changes in Capybara 2.1 is ignoring all hidden elements by default. This could be viewed as a limiting of Capybara’s feature set, since you can no longer (easily) test certain elements on a page. I will argue that it steers you into writing tests that are more realistic, causing this limitation to actually enhance the quality of your acceptance tests.

Read more »

PIVOTAL LABS
iFrame you frame…

Helps undefined method `fields' for nil

We keep getting this error across multiple projects & machines, with different versions of the pg gem and the PostgreSQL server, with varying consistency. Switching the tests to sqlite seems to fix it.

Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: NoMethodError: undefined method `fields' for nil:NilClass: SELECT "locations".* FROM "locations" WHERE "locations"."id" IN (11, 10, 5, 4, 1, 3, 2)

It appears that PG::Connection#async_exec is returning nil for some queries.

Read more »

LABS
without_page_refresh capybara helper

I recently had to write a small capybara helper:

def without_page_refresh
  page.execute_script("window._withoutPageRefresh = 'BAM'")
  yield
  page.evaluate_script("window._withoutPageRefresh").should == "BAM", "Page was navigated away"
end

Use case:

You are building a form that gracefully degrades when javascript is not enabled. It goes something like this:

# uses rack-test so no javascript
scenario "User can lose money in an accessible way" do
  visit "/your_account"
  page.should have_content "You have $100"
  click_button "Charge me"
  page.should have_content "You have $50"
end

Next step is to make that form do the ajax thingy. You copy test above and switch it to use javascript driver:

# uses selenium for javascript
scenario "User can lose money with style", :js => true do
  visit "/your_account"
  page.should have_content "You have $100"
  click_button "Charge me"
  page.should have_content "You have $50"
end

Newly written test is pretty good except that it passes without writing a single line of javascript. So here's when that helper comes into play. Our javascript test becomes:

# uses selenium for javascript
scenario "User can lose money with style", :js => true do
  visit "/your_account"

  without_page_refresh do
    page.should have_content "You have $100"
    click_button "Charge me"
    page.should have_content "You have $50"
  end
end

Now javascript test fails with "Page was navigated away" since nothing is preventing that form from submiting to another page.

LABS
Waiting for jQuery Ajax calls to finish in Cucumber

You may be asking yourself why you'd want to do this in the first place. Well here's why I would want to do it.

We had some Webdriver based Cucumber tests that passed fine locally but kept failing on our CI box. Our CI box is a bit underpowered at the moment so I thought what might be happening is that our tests weren't waiting long enough for the Ajaxy stuff to happen because the Ajax responses were taking a long time.

After some poking around in the source code of jQuery, I found the $.active property. This property keeps track of the number of active Ajax requests that are going on and I thought this might help us out.

What I came up with was this gist:

I added this step right after my Cucumber step that caused the Ajax call so that Cucumber would wait to move on until I knew that everything was done.

This step solved our CI failures and all was good in our test suite again.

LABS
Using Firebug with WebDriver in Capybara/Cucumber – New and Improved

Forget the steps I published earlier...just install the capybara-firebug gem and away you go.

Thanks jfirebaugh!