Search code examples
capybarapoltergeistcapybara-webkit

Poltergeist is not recognising full url


I am trying to swap over from using webkit to poltergeist with Capybara feature specs. I have a test like

find_link('About')[:href].should == about_path

which works fine with webkit, but with poltergeist as the javascript_driver, I get the following error

expected: "/about"
     got: "http://127.0.0.1:63361/about"

How do I fix this?


Solution

  • Capybara-webkit is returning the href attribute here, whereas poltergeist (and selenium) returns the property. The best solution is to change your expectation to use the have_link matcher

    page.should have_link('About', href: about_path)
    

    This has the advantages of working across all drivers, being nicer to read, and also enabling Capybaras retrying behavior to be used.

    TL;DR - prefer the Capybara provided matchers over equality checks on attributes whenever possible