在Minitest中,切换到JS驱动程序会使断言失败

时间:2015-03-19 15:58:10

标签: javascript ruby-on-rails capybara minitest

在测试Javascript方面,我只是没有使用Minitest。希望我不会因为发出这么多问题而困扰任何人。

所以,现在我设法让Capybara工作,并且能够用新语法替换(部分)我现有的测试(因为正常的Minitest断言不适用于Capybara)。

test "study page & question screen" do

    assert_title "Study | Word Up"
    assert page.has_selector?('h3', text: "STUDY"), "Panel title missing or wrong"
    assert page.has_selector?("div.progress-bar"), "Progress bar missing or with wrong class"
end

测试是绿色的,都很好。

16:24:23 - INFO - Running: test/integration/study/study_test.rb
Started

StudyTest
test_answer_screen                                              PASS (0.98s)
test_study_page_&_question_screen                               PASS (0.27s)

Finished in 1.26314s
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips

现在是Javascript部分。我想测试是否存在我使用页面Javascript加载的span元素。因此,我将驱动程序切换为使用能够使用JS的驱动程序。

test "study page & question screen" do

    Capybara.javascript_driver = :webkit
    Capybara.current_driver = Capybara.javascript_driver
    assert_title "Study | Word Up"
    assert page.has_selector?('h3', text: "STUDY"), "Panel title missing or wrong"
    assert page.has_selector?("div.progress-bar"), "Progress bar missing or with wrong class"
end

突然之间的测试是红色的,因为第一个期望神秘地没有得到满足。(甚至没有尝试测试JS内容)

16:28:21 - INFO - Running: test/integration/study/study_test.rb
Started

StudyTest
test_answer_screen                                              PASS (1.12s)
test_study_page_&_question_screen                              ERROR (5.11s)
Capybara::ExpectationNotMet:         Capybara::ExpectationNotMet: expected "" to include "Study | Word Up"

但是,如果这不够奇怪,当取出所有非JS测试并且仅测试我通过页面JS插入的元素时:

test "study page & question screen" do

    Capybara.javascript_driver = :webkit
    Capybara.current_driver = Capybara.javascript_driver
    #assert_title "Study | Word Up"
    #assert page.has_selector?('h3', text: "STUDY"), "Panel title missing or wrong"
    #assert page.has_selector?("div.progress-bar"), "Progress bar missing or with wrong class"
    assert page.has_selector?('span'), "Frontside missing or wrong" 
end

我得到了一个失败的测试:

16:49:06 - INFO - Running: test/integration/study/study_test.rb
Started

StudyTest
test_answer_screen                                              PASS (0.99s)
test_study_page_&_question_screen                               FAIL (4.19s)
Minitest::Assertion:         Frontside missing or wrong

现在,我觉得我在随机尝试方法和驱动程序的组合,我不知道从现在开始到哪里去。它只是我还是minitest和提到的宝石的文档有点过于紧凑。我希望我不会冒犯任何人,或者这样说。可能只是因为我在使用宝石和组合它们方面没有太多经验。

0 个答案:

没有答案