Capybara, Sweet-Alert, click_button seems to work, but does not trigger the action

203 views Asked by At

I'm trying to write a test. There is a site with an element and a delete-button, to delete that element. If done manually, it works as expected.

Currently, the test looks like this:

visit "/argumentation#!/overview"
expect(page).to have_content("Philosophie")

save_screenshot
click_button "Delete"

save_screenshot
click_button "Yes, delete it!"

save_screenshot
sleep 5

save_screenshot
expect(page).not_to have_content("Philosophie")

(Pictures of the screenshots are below).

To make sure, that click_button "Yes, delete it!" is actually the same button as displayed in the popup, I added click_button "Yes, delete it!" before the click_button "Delete"-action. This would happen:

 Capybara::ElementNotFound:
   Unable to find button "Yes, delete it!"

Does anyone know, why the test is failing?

In other stackoverflow-questions, some asked about the configuration in rails_helper.rb, here is mine:

Capybara.javascript_driver = :poltergeist
Capybara.default_driver = :poltergeist

First screenshot: enter image description here

Second screenshot: enter image description here

Third screenshot: enter image description here

Fourth screenshot: enter image description here

1

There are 1 answers

1
Metaphysiker On

I figured it out: The click_button "Yes, delete it!" is happening too fast. With a delay, it works:

click_button "Delete"
sleep 5
click_button "Yes, delete it!"