加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rspec系统测试在单独运行时通过,在使用整个套

发布时间:2020-12-17 03:11:01 所属栏目:百科 来源:网络整理
导读:当我单独运行时,我有以下测试通过: require 'rails_helper'RSpec.describe 'deleting a non-recurring user event',js: true do let(:user) { create(:proofreader_user) } let(:date) { Date.current.strftime('%Y-%m-%d') } let(:date_time) { date + ' 0
当我单独运行时,我有以下测试通过:

require 'rails_helper'

RSpec.describe 'deleting a non-recurring user event',js: true do

  let(:user)       { create(:proofreader_user) }
  let(:date)       { Date.current.strftime('%Y-%m-%d') }
  let(:date_time)  { date + ' 00:00'}

  it 'deletes the event' do
    visit root_path
    click_on "Login"
    fill_in  "Email",with: user.email
    fill_in  "Password",with: user.password
    click_on "Sign In"
    visit calendar_path
    expect(current_path).to eq(calendar_path)
    expect(page).to have_css("#complete_registration:disabled")
    expect(page).to_not have_css("td.fc-event-container")
    find("td.fc-day[data-date='#{date}']").click
    expect(page).to have_css("div#user-event-modal")
    expect(page).to have_select('user_event[title]',:options => UserEvent.titles.keys)
    expect(find('input',id: 'user_event_starting').value).to eq date_time
    expect(find('input',id: 'user_event_ending').value).to eq date_time
    page.execute_script("$('input#user_event_starting').val('#{date} 09:00')")
    expect(find('input',id: 'user_event_starting').value).to eq date + ' 09:00'
    page.execute_script("$('input#user_event_ending').val('#{date} 12:00')")
    expect(find('input',id: 'user_event_ending').value).to eq date + ' 12:00'
    click_on 'Save'
    expect(page).to have_css("td.fc-event-container a.fc-day-grid-event")
    expect(page).to have_css("span.fc-time",text: '9a - 12p')
    expect(page).to have_css("span.fc-title",text: 'work')
    find("span.fc-time",text: '9a - 12p').click
    expect(page).to have_css("div#user-event-modal")
    find("#del_one_event").click
    within('.swal2-actions') { click_button('Yes') }
    wait_for { page }.to_not have_css("div#user-event-modal")
    expect(page).to_not have_css("td.fc-event-container")
    expect(page).to_not have_css("span.fc-time",text: '10a - 14p')
  end
end

但是,当我运行所有测试时,我收到以下错误:

Failure/Error: within('.swal2-actions') { click_button('Yes') }

     Capybara::ElementNotFound:
       Unable to find visible css ".swal2-actions"

当我使用其他测试运行它时,为什么此测试失败?我如何修复它以便在运行所有测试时通过它?

解决方法

没有更多信息无法确定.如果您可以创建和发布 minimum complete verifiable example,那将是最好的.

根据给出的信息,我猜测与其他测试一起运行时失败的测试没有被正确隔离.其他示例正在更改应用程序的状态,导致此测试失败.所以看一下你之前和之后的钩子并确保你在rails_helper.rb中设置config.use_transactional_fixtures = true

如果在单击#del_one_event和出现.swal2-actions之间存在延迟,则更改

within('.swal2-actions') { click_button('Yes') }

find('.swal2-actions').click_button('Yes')

如果这些都没有解决问题,那么browser caching可能会出现问题,但这更难以调试.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读