Ruby on rails 轨道&x2B;水豚+;selenium测试GoogleOAuth2回调
我正在使用selenium测试我的google oauth2登录:Ruby on rails 轨道&x2B;水豚+;selenium测试GoogleOAuth2回调,ruby-on-rails,selenium,capybara,Ruby On Rails,Selenium,Capybara,我正在使用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)
#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
我该如何处理这个callaback?如果你做了一个真实的测试,那么127.0.01:58272我有localhost:3000,它可以工作
解决方案
在spec_helper.rb中,或者更具体地说,在before块中的spec文件中
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
重定向_uri
仅在您在控制台上生成了客户端ID时才起作用
创建客户端ID时,必须选择
已安装的应用程序
,使其正常工作。有关生成客户端ID的更多信息:检查此问题:我有一个不同的问题,我可以访问外部链接,但无法管理回调URL我刚刚发布了我的解决方案您是否在google控制台中创建了127.0.0.1:3000的客户端ID?请记住,通过将测试环境的端口设置为3000,您必须确保没有处于开发模式的服务器在端口3000上运行。