【发布时间】:2013-12-09 14:55:29
【问题描述】:
我正在使用 selenium 测试我的 google oauth2 登录:
#spec/featurers/google_spec.rb
require 'spec_helper'
describe "the signin process", type: :feature do
before do
Capybara.current_driver = :selenium
visit user_omniauth_authorize_path(:google_oauth2)
fill_in "Email", :with => 'test@gmail.com'
fill_in "Password", :with => 'test'
click_button 'Accedi'
#in this point it crash
click_button 'Consenti'
end
it { page.should have_content('Google') }
end
它有效,但我在管理 google 回调时遇到问题:
Errore:redirect_uri_mismatch
The redirect URI in the request: http://127.0.0.1:58272/users/auth/google_oauth2/callback did not match a registered redirect URI
我该如何管理这个回调?如果进行真正的测试,而不是 127.0.01:58272 我有 localhost:3000 并且它可以工作。
解决方案
在 spec_helper.rb 中,或者更具体地说,在你的规范文件中的 before 块中。
describe "the signin process" do
before do
Capybara.run_server = true #Whether start server when testing
Capybara.current_driver = :selenium
Capybara.server_host= 'localhost' #this is the goal
Capybara.server_port = 3000
visit user_omniauth_authorize_path(:google_oauth2)
end
it {#some}
end
【问题讨论】:
-
我有一个不同的问题,我可以访问外部链接,但我无法管理回调 url
标签: ruby-on-rails selenium capybara