Home>

Currently, tests are created under SPEC /SYSTEM as follows.
The latest article about RSPEC's CONFIRM is only about the following articles,
I do not know how to solve. It would be nice if you could have a professor.

We are implementing this article with reference to this article.
[Rails] Testing a Confirm Dialog with Selenium /RSPEC-QIITA

The following error is displayed.

CapyBara :: NotSupportedByDriverEror: CapyBara :: Driver :: Base # dismiss_modal
CAPYBARA :: NOTSUPPORTEDBYDRIVERERROR: CAPYBARA :: Driver :: Base # accept_modal

Code written at the time of data deletion

<
%= Link_To "Photo Delete", Post, Method: Delete, id: 'delete_button', data: {confirm: "Do you want to delete?"}% >

spec /system /aaa_spec.rb

Require 'RAILS_HELPER'
RSPEC.DESCRIBE "AAA", TYPE :: SYSTEM, JS: TRUE DO
  Let (: user) {factorybot.create (: user)}
  Let (: other_user) {factorybot.create (: user)}
  Let (: img_path) {rails.root.join ("spec /img /aaa.jpg")}
  Context "WHEN A User Posts A IMG" DO
    IT "TEST1" DO
      VISIT NEW_USER_SESSION_PATH
      Fill_in "E-mail address", with: user.email
      Fill_in "Password", with: user.password
      Find ('. Signin-BTN'). Click_link_or_button "Login"
      Expect (page) .to have_current_path root_path
      expect {
        upload_img (IMG_PATH)
      } .To Change {user.posts.count} .by (1)
      Expect (Page) .to Have_current_path User_Path (User)
      Expect (page) .to have_text "number of photos (1)"
      Expect (Page) .To Have_Selector '# POST-1'
      Expect (Page) .To Have_Selector '# Favorite-Form-1'
      Click_button "Favorites Registration"
      Expect (user.favorites.count) .To EQ 1
      VISIT USERS_PATH
      Expect (Page) .To Have_Selector '# POST-1'
      Expect (Page) .NOT_TO HAVE_SELECTOR '# Favorite-Form-1'
      VISIT USER_PATH (USER)
      Expect (Page) .To Have_Selector '# Favorite-Form-1'
      Click_button "Favorites"
      Expect (user.favorites.count) .To EQ 0
      VISIT ROOT_PATH
      find ('# post-1'). Find ('img'). Click
      Expect (Page) .TO HAVE_SELECTOR '# showimgmodal-1'
      Expect (Page) .to haselector '.post-delete', Text: 'Photo delete'
      Expect (Page) .TO HAVE_SELECTOR '# Comment-Form-1'
      WITHIN ('# comment-form-1') DO
        Fill_in "Comment column", with: "Hello"
        Click_link_or_button "Comment"
      END
      expect (user.comments.count) .to Eq 1
      Expect (Page) .TO Have_SElector '.Comment', TEXT: "Comment Delete"
      Page.dismiss_confirm ("Do you want to delete?") DO
        Click_on: delete_button
      END
      Page.accept_confirm DO
        Click_on: delete_button
      END
    END
  END
END

The test has come to pass all after changing the part of the problem code below.
Is this really suitable?

page.dismiss_confirm ("Do you want to delete?") DO
  Click_on: delete_button
END
Page.accept_confirm DO
  Click_on: delete_button
END
↓ ↓
Click_link "Photo Delete"
Expect (Page) .to Have_Content "Photo has been deleted"

Support /capybara.rb

RSPEC.Configure Do | CONFIG |
  config.before (: Each, Type :: System) Do
    driven_by: rack_test
  END
END
CAPYBARA.JAVASCRIPT_DRIVER=: SELENIUM_CHROME_HEADLESS

Changing the code and the test has been repeated, because Rack_Test does not support JavaScript, it may not be displayed, and it may be possible to continuously press the button as it is.

Masafumi Okura2021-04-30 05:03:14