RSpec x Capybara Modal Is Displayed but Will Not Find

Asked 1 years ago, Updated 1 years ago, 102 views

I'd like to test the modal display when I press the user delete button
The following error will be displayed:

it "Can delete other users" do
  visit user_path(I18n.locale, other_user)
  page.dismiss_confirm(I18n.t("users.show.Delete this user completely.Are you sure you like it?")) do
    find(".card-link.delete-user").click#Click Delete Account
  end
end
Failure/Error:
   page.dismiss_confirm(I18n.t("users.show.Delete this user completely.Are you sure you like it?")) do
     find(".card-link.delete-user").click
   end
 
 Capybara::ModalNotFound:
   Unable to find modal dialog with Xaabỏngờ didùng này.Bnn cắchcc bạn munn làm ii nunyy?

However, when I looked at the screenshot, the modals were displayed and the words of the reminder were consistent.

·Bundle install capybara-webkit
·Originally, expect(page.driver.browser.switch_to.alert.text).to eq I18n.t~...
 When I was writing the test in , I received the following error:

Selenium::WebDriver::Error::NoSuchAlertError:
   no such alert
     (Session info: headerless chrome=85.0.4183.121)
<%=link_to "Delete Account", user_path(@user), method::delete, class:"card-link delete-user",
                                            data:{confirm:t(".Delete this user completely.Are you sure you like it?"), title:t(".Delete Confirm")%>
 group:development,:test do
  gem "byebug", platforms: [:mri,:mingw,:x64_mingw]
  gem "pry-rails"
  gem "pry-byebug"
  gem "pry-doc"
  gem "rspec-rails", "~>3.9"
  gem "factory_bot_rails", "~>4.11"
  gem "database_cleaner"
  gem "show_me_the_cookies"
  gem "faker",:git=>"https://github.com/faker-ruby/faker.git",:branch=>"master"
end

group —test do
  gem "capybara", ">=2.15"
  gem "capybara-webkit"
  gem "selenium-webdriver"
  gem "webdrivers"
end

spec_helper.rb

require "capybara/rspec"
require "database_cleaner"

RSpec.configure do | config |
  config.before(:each, type::system)do
    drive_by —Selenium_chrome_headless
  end

  config.expect_with —rspec do | expectations |
    expectations.include_chain_clauses_in_custom_matcher_descriptions=true
  end

  config.mock_with —rspec do|mocks|
    mocks.verify_partial_doubles=true
  end

  config.shared_context_metadata_behavior=:apply_to_host_groups

  config.before(:suite)do
    DatabaseCleaner.strategy=:truncation
  end

  config.before(:each)do
    DatabaseCleaner.start
  end

  config.after(:each)do
    DatabaseCleaner.clean
  end
  
end

Could someone please tell me how to solve this problem?
Thank you for your cooperation.

We have decided to deal with it as follows.
If you comment out the first line, you will get an error, so I think this is OK.

 find(".card-link.delete-user") .click# Click Delete Account
without ".modal-content" do
  expect(page).to have_content I18n.t("users.show.Delete Confirm")
  expect(page).to have_content I18n.t("users.show.Delete this user completely.Are you sure you like it?")
  expect {click_button "Confirm"}.to change {User.count}.by(-1)
end

ruby rspec capybara

2022-09-30 14:30

1 Answers

Unable to find modal dialog with Xaabỏngư didùng này.Bnn cắchcc bạn munn làm ềi nun ?y?

I'm curious that it's not in Japanese.

First of all, dismiss_confirm seemed to be able to omit the first argument (https://rubydoc.info/gems/capybara/3.33.0/Capybara/Session#dismiss_confirm-instance_method), so

it "Can delete other users" do
  visit user_path(I18n.locale, other_user)
  page.dismiss_confirm do
    find(".card-link.delete-user").click#Click Delete Account
  end
end

How about trying ?


2022-09-30 14:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.