Integration of social networks is very common in every application. We have many gems are available for doing integration. But testing this social integration is complicated task. Using capybara with cucumber we can easily test this similar to the normal UI testing through capybara.
Set up default driver to selenium.
#features/support/env.rb Capybara.default_driver = :selenium
Generate cucumber feature and follow below steps to write step definitions:
1) To click on ‘Facebook’ login:
Here I am using xpath selector to find facebook login button.’Fb-login-button’ alt value of my facebook button.
2) Fill up the Facebook login form. This will differ if we are doing login through a popup.
For popup login:
begin within_window(page.driver.browser.window_handles.last) do fill_in('email', :with => Fb-Email) fill_in('pass', :with => Fb-password) click_on('Log In') end rescue Exception => e p "Selenium Exception: Session has no driver" end
Sometimes selenium will throw an exception. So its better to use exception handling.
For Standard Facebook login, just write:
fill_in('email', :with => Fb-Email) fill_in('pass', :with => Fb-password) click_on('Log In')
Now your are done. You automated social networking testing. Follow above steps even for ‘twitter’ login also.
I hope everyone will enjoy this article. Any queries or suggestions would be welcome.