Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Created September 11, 2018 08:47
Show Gist options
  • Save bernardo-cs/a623e0da4ab3311382a49dec1bbc3d8c to your computer and use it in GitHub Desktop.
Save bernardo-cs/a623e0da4ab3311382a49dec1bbc3d8c to your computer and use it in GitHub Desktop.
Rails system test that:Creates new facebook test user with koala gem. Signs in user on facebook.com. Accepts facebook "continue as #{username}" iframe.
# frozen_string_literal: true
require 'application_system_test_case'
class FacebookLoginTest < ApplicationSystemTestCase
# create new test user with Koala Gem
def setup
@test_users = Koala::Facebook::TestUsers.new
@user = @test_users.create(false)
login_in_facebook(@user)
end
def teardown
@test_users.delete(@user)
end
def test_login_with_facebook
visit spa_page_with_facebook_login_url
# on your app click on the "Login with facebook" button
facebook_login_window = window_opened_by do
click_on 'Login with facebook'
end
# click on "continue as USERNAME" on the facebook iframe
within_window(facebook_login_window) do
find(:xpath, "//button[contains(@name, '__CONFIRM__')]").click
end
end
private
# Logs in test user on facebook.com
def login_in_facebook(user)
Capybara.always_include_port = false
visit 'https://www.facebook.com'
fill_in :email, with: user['email']
fill_in :pass, with: user['password']
find('#loginbutton').click
Capybara.always_include_port = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment