【发布时间】:2015-07-22 04:57:32
【问题描述】:
我正在尝试将 Stripe 集成到我正在构建的网络应用程序中。然而,当我尝试测试“用卡付款”按钮时,我遇到了一个小问题。无论我做什么,rspec 都会抛出 ElementNotFound 错误。
经过一番搜索,我发现这是因为默认驱动程序 rack_test 不支持 Javascript。然后我参考了一些文档:https://github.com/jnicklas/capybara#drivers 并将 :js => true 添加到我的 RSpec 场景之一,并将 selenium-webdriver gem 添加到我的 gemfile。
但是,这带来了另一组问题。现在,每当我运行测试时,我都会被告知我使用了无效的用户名/密码组合,并且我无法进入测试的下一部分以查看是否可以单击该死的按钮! Selenium 似乎没有识别和/或使我的用户工厂无效。
举手。
任何帮助将不胜感激。
spec/features/user_upgrade_premium_spec.rb:
require 'rails_helper'
describe "Upgrade from Standard to Premium Plan" do
before do
@user = create(:user)
visit root_path
click_link "Sign In"
fill_in 'Email', with: @user.email
fill_in 'Password', with: @user.password
click_button "Sign In"
expect(page).to have_content "Signed in successfully."
end
scenario "Successfully", :js => true do
click_link "My Account"
click_link "Upgrade Account"
click_button "Pay with Card"
end
end
spec/factories/user.rb
FactoryGirl.define do
factory :user do
name "User One"
sequence(:email, 100) { |n| "person#{n}@example.com" }
password "helloworld"
password_confirmation "helloworld"
confirmed_at Time.now
end
end
【问题讨论】:
-
你使用的是页面对象模式吗?
-
replace describe "Upgrade from Standard to Premium Plan" do with RSpec.describe "Upgrade from Standard to Premium Plan" do
标签: javascript ruby-on-rails ruby selenium rspec