【发布时间】:2019-04-24 12:16:07
【问题描述】:
我正在尝试使用 RSpec Capybara 和 selenium-chrome 驱动程序在 Rails 上运行集成测试。
我也在使用capybara-angular gem。
我对到底发生了什么有点困惑,因为当我睡觉时我看不到我的脚本我的 rspec 测试检查了 chrome 调试器中的源选项卡,它似乎没有加载我的资产,尽管它似乎 ng-if 语句在页面被隐藏时正在工作。
所以我不太确定发生了什么。该页面在开发中按预期工作,但 $scope 上的变量未在测试中设置。
这是我在“system.rb”中的设置
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :selenium_chrome
end
end
require "capybara-screenshot/rspec"
include Capybara::Angular::DSL
这是我正在运行的测试:
it "shows changes to the budget when the budget is changed", :js do
visit(root_path)
sleep 0.5
fill_in "inputEmail", with: "test@tester.com"
fill_in "password", with: "test"
click_on("Log In")
sleep 0.25
click_on("Budgeting")
sleep 10
expect(page).to have_selector("#current_project_name", text: "Project A")
expect(page).to have_selector("#budgetInput1")
fill_in "#budgetInput1", with: "100"
# Fail on next line with 'expected to find visible css "#budgetInput1" but there were no matches'
page.should have_selector("#budgetInput1", text: "100") # <--test fails with
end
据我所知,找不到它的原因是该元素出现在带有ng-if="showBudget" 的div 中。 $scope.showBudget=true 在控制器中设置,但控制器似乎没有加载,{{showBudget==unknown}} 返回 true,这表明 AngularJS 正在加载,但页面清单加载的脚本没有。
如何解决这个问题?
【问题讨论】:
标签: angularjs rspec capybara rspec2