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.
Step 1:
Set up default driver to selenium.
#features/support/env.rb Capybara.default_driver = :selenium
Step 2:
Generate cucumber feature and follow below steps to write step definitions:
1) To click on ‘Facebook’ login:
page.find(:xpath, "//a/img[@alt='Fb-login-button']/..").click
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.