1

I am trying to write a test and I am getting really stumped. I am using a helper to render a link

module DeleteLinksHelper
  def link_to_destroy(object)
    opts = {
      method: :delete,
      remote: true,
      id: "#{object.class.name.downcase}-#{object.id}-delete" 
       ### have tried with and without giving it an id
    }

     link_to object, opts do
       content_tag(:span, nil , class: "glyphicon glyphicon-remove")
     end
  end
end

this all works fine when I run the server it deletes the object i hand it. the problems start when I try to write an integration test with capybara.

Capybara.current_driver = Capybara.javascript_driver = :webkit

  # Have tried many ways of selecting/clicking the link and span elements
  page.find('span.glyphicon-remove').click
  page.find("#component-#{c.id}-delete > span").click

Capybara::Webkit::ClickFailed: Failed to find position for element /html/body/div/div[@id='main']/div[1]/div[2]/div[@id='components-pane']/ul/li[@id='component497695656']/div/a[@id='component-497695656-delete']/span

I saved the page just before and it has the entire page of html as it should be.

<a id="component-497695656-delete" data-remote="true" rel="nofollow" data-method="delete" href="/components/497695656">
     <span class="glyphicon glyphicon-remove"></span>
</a>

However if i save a screenshot at the same time it only shows the footer.

screenshot just before click

Yeah!!! That's the whole screenshot! Whats going on here? Does it have to do with the webkit driver?

mkrinblk
  • 896
  • 9
  • 21
  • On potential issue is that the capybara-webkit driver replaces all custom fonts with Arial - https://github.com/thoughtbot/capybara-webkit/blob/43ebe80704e118ba690d62049fe346fbe787e050/src/WebPage.cpp#L117 - due to a bug in an older version of QtWebKit. If the character code glyphicon uses for the remove icon doesn't exist in Arial then your span will have 0 width on the page and not be locatable. The blank screenshot could happen if you're using CSS features unsupported by capybara-webkit (it's basically a 5 year old browser) or the page isn't yet fully loaded. – Thomas Walpole Jan 25 '17 at 22:38
  • I am using the bootstrap glyphicons. since you mentioned that bug I have been reading [this](https://github.com/thoughtbot/capybara-webkit/issues/494) issue which seems to have a lot of workarounds and a possible answer pointing at the version of qt. – mkrinblk Jan 25 '17 at 23:11
  • If you didn't originally build capybara-webkit with Qt5.5.1 definitely try that. You should also look at issues https://github.com/thoughtbot/capybara-webkit/issues/728 and https://github.com/thoughtbot/capybara-webkit/issues/808 – Thomas Walpole Jan 25 '17 at 23:18
  • I ran `qmake --version` says using Qt version 5.5.1 should I rebuld capybara-webkit? – mkrinblk Jan 25 '17 at 23:21
  • sure nothing to lose - no guarantee that it fixes it though due to the other issues – Thomas Walpole Jan 25 '17 at 23:21
  • I made sure I was using qt 5.5.1 uninstalled and reinstalled capybara-webkit to no avail. I did get it to find the element using [this workaround](http://stackoverflow.com/a/36620706/4017627) but the click never makes it to the controller. – mkrinblk Jan 26 '17 at 23:33

0 Answers0