Skip to content

Instantly share code, notes, and snippets.

@cemre
Created March 2, 2012 04:45
Show Gist options
  • Save cemre/1955752 to your computer and use it in GitHub Desktop.
Save cemre/1955752 to your computer and use it in GitHub Desktop.
Twitter authentication/login with Capybara and Selenium
# Call this function after you click the 'sign in with twitter' button on your website
# It switches to the popup, logs in, then switches back to your site.
def auth_with_twitter(username, password = @@default_password)
# Twitter auth
page.driver.browser.switch_to.window page.driver.browser.window_handles.last do
# If logged in, force log out.
if !page.has_css? "#username_or_email"
find('.current-user a').click
within('.signout') do
find('input[type=submit]').click
end
end
fill_in "username_or_email", :with => username
fill_in "password", :with => password
click_button "Authorize app"
end
# Come back to this window
page.driver.browser.switch_to.window(page.driver.browser.window_handles[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment