Obromios
Obromios

Reputation: 16383

How to test if onclick: javascript:print() is working in a feature spec

I have a link embedded in a page:

<%= link_to "<span class ='glyphicon glyphicon-print'></span>".html_safe, '#', onclick: 'javascript:print()',
  class: 'print_link', id: 'printable' %>

If I click it, then it opens a browser overlay to print the page. In a feature spec, how do I test that this browser overlay opens?

Upvotes: 2

Views: 407

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

That opens a system dialog which Capybara has no access to, so you can't really check it. With most drivers you can verify the value of the onclick attribute by doing something like

expect(find(:link, 'printable')['onclick']).to eq 'javascript:print()'

which would verify the link is there with the correct click handler, but verifying the actual behavior really isn't possible

Upvotes: 1

Related Questions