Testing social networks using capybara, cucumber-rails, selenium

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.

Advertisements

About Siva Gollapalli

Being a programmer is a huge possibility to learn
This entry was posted in Ruby on Rails, Tutorials and tagged , , , . Bookmark the permalink.

One Response to Testing social networks using capybara, cucumber-rails, selenium

  1. Buying Guide says:

    Thank you Sir. Today I learn something new because of you, Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s