How to inspect modal text with Cuprite?

295 Views Asked by At

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?

2

There are 2 best solutions below

2
Thomas Walpole On BEST ANSWER

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
0
Kris On

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.