0

I'm switching from the Poltergeist to Cuprite driver for Capybara.

I have Javascript code which sets the message for a confirmation modal which I want to check in my feature specs.

The javascript is confirm("....").

With Poltergiest I could do page.driver.browser.modal_message.

This is unsupported by Cuprite, it there another way?

Kris
  • 19,188
  • 9
  • 91
  • 111

2 Answers2

1

Capybaras accept_confirm (which cuprite supports) returns the string from the system modal:

text = accept_confirm do
   # ... the actions that triggers the modal to appear
end

Or you can pass a string to accept_confirm to have it verify the string:

accept_confirm('the text to check') do
   # ... the actions that triggers the modal to appear
end
Kris
  • 19,188
  • 9
  • 91
  • 111
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
0

Looking at the ferrum driver which Cuprite uses under the hood I can see it is possible register a hook for a dialog appearing.

message = nil

page.driver.browser.on(:dialog) do |dialog|
  message = dialog.message
end

accept_confirm do
  click_on progress_tab.name      
  expect(message).to eq text('...')
end

It isn't pretty.

Kris
  • 19,188
  • 9
  • 91
  • 111