相关疑难解决方法(0)

一些JS运行后如何让Capybara检查可见性?

加载页面后,我有运行和隐藏的代码,并根据xhr返回的数据显示各种项目.

我的集成测试看起来像这样:

it "should not show the blah" do
    page.find('#blah').visible?.should be_true
end 
Run Code Online (Sandbox Code Playgroud)

当我在上下文中手动转到该测试运行的页面时,#blah 并不像我预期的那样可见.我怀疑Capybara正在查看页面的初始状态(在这种情况下是不可见的),在JS运行之前评估DOM的状态并且未通过测试.

是的,我设置:js => true了包含的描述块:)

任何想法将不胜感激!我希望我不必在这里故意拖延,感觉不稳定,会减慢速度.

ruby integration-testing rspec capybara

79
推荐指数
6
解决办法
7万
查看次数

模糊匹配,发现2个元素匹配css - Capybara

我有一个测试,在页面上呈现两个相同的元素.我理解错误的问题是什么,但我不确定如何修复它?这是我的测试:

测试

 it "deletes the correct snitch" do
        user    = login_user
        snitch  = create(:snitch, :healthy, owner: user.accounts.first)
        snitch2 = create(:snitch, :healthy, owner: user.accounts.first)

        visit root_path
        delete = page.find(".icon-delete")
        first(delete).click
        expect(page).to have_content("Please confirm this delete.")


 end
Run Code Online (Sandbox Code Playgroud)

错误

 Managing snitches deleting a snitch from the index page deletes the correct snitch
 Failure/Error: delete = page.find(".icon-delete")

 Capybara::Ambiguous:
   Ambiguous match, found 2 elements matching css ".icon-delete"
Run Code Online (Sandbox Code Playgroud)

如何选择页面上的其中一个图标删除?

css rspec ruby-on-rails capybara

5
推荐指数
3
解决办法
8436
查看次数

标签 统计

capybara ×2

rspec ×2

css ×1

integration-testing ×1

ruby ×1

ruby-on-rails ×1