Integration Testing

w/ Capybara

A tool to create a manageable cycle of professional development and evaluation

Task:

Test the professional development approval options in Folio

4 options:

Testing Process

  • Login as Folio Admin

  • Go to admin panel

  • Select approval option to test

  • Click Update
  • Logout
  • Login as corresponding approver

  • Click on notification to review

  • Approve PD

  • Logout

  • Login as another user

  • Go to PDs page

  • Click to Add PD button

  • Fill in 5 required form fields
  • Click Submit
  • Logout
  • Login as user who submitted PD

  • Click on reviewed PD notification

  • Expect 'Approval Status: Approved'

1. Change Approval Setting

2. Submit a PD Item

3. Approve PD Item

4. Check Approval of PD Item

  • 30 clicks
  • 20 url changes
  • 5 text fields
  • ~3 - 5 minutes per test

Manually testing:

That's gross.

When a feature affecting PD approval is added or changed, each option should be re-checked.

Over time, this could lead to hours spent going through the same repetitive, tedious testing process

ENTER CAPYBARA

This is bad.

If only there were a better way....

What is it?

"Capybara helps you test web applications by simulating how a real user would interact with your app."

  • Test framework
  • Easy to read and write
  • Automates testing process

User-friendly DSL

visit('page_url') # navigate to page

click_link('id_of_link') # click link by id

click_link('link_text') # click link by link text

click_button('button_name') # fill text field

fill_in('First Name', :with => 'John') # fiil in form field

choose('radio_button') # choose radio button

check('checkbox') # check in checkbox

uncheck('checkbox') # uncheck in checkbox

select('option', :from=>'select_box') # select from dropdown

attach_file('image', 'path_to_image') # upload file

Unit Testing vs Integration Testing

Quick Aside

Unit Testing

  • Tests individual units in isolation (fn, controllers, etc)
  • Relatively straight-forward
  • Tests run quickly

Integration Testing

  • Tests integrated functionality (how does this thing affect this other thing?) 
  • Less straight-forward
  • Tests run much longer

An illustration.

So all this...

  • Login as Folio Admin

  • Go to admin panel

  • Select approval option to test

  • Click Update
  • Logout
  • Login as corresponding approver

  • Click on notification to review

  • Approve PD

  • Logout

  • Login as another user

  • Go to PDs page

  • Click to Add PD button

  • Fill in 5 required form fields
  • Click Submit
  • Logout
  • Login as user who submitted PD

  • Click on reviewed PD notification

  • Expect 'Approval Status: Approved'

1. Change Approval Setting

2. Submit a PD Item

3. Approve PD Item

4. Check Approval of PD Item

scenario 'pd item can be submitted and approved' do
  sign_in admin_user
  visit('/customization-manager')
  within '#pd-approvals-required' do
    find("option[value='1']").select_option
  end
  click_on('Update')
  click_on('Logout')

  sign_in user
  visit new_professional_development_path
  fill_in 'professional_development_title', with: 'Example Title'
  click_on('Save')
  visit professional_developments_path
  click_on('Submit for Approval')
  visit employee_professional_developments_path(employee_id: user.employee.id)
  click_on('Logout')

  .
  .
  .

  sign_in user
  visit employee_professional_developments_path(employee_id: user.employee.id)
  expect(page).to have_content('Approval Status: Approved')
end  

...became this...

scenario 'pd item can be submitted and approved' do
  set_single_approval_required
  user_submit_in_pd
  sign_in supervisor.user
  supervisor_approve_pd
  user_check_approval_status
end  

def set_single_approval_required
  sign_in admin_user
  visit('/customization-manager')
  within '#pd-approvals-required' do
    find("option[value='1']").select_option
  end
  click_on('Update')
  click_on('Logout')
end

def user_submit_in_pd
  sign_in user
  visit new_professional_development_path
  fill_in 'professional_development_title', with: 'Example Title'
  click_on('Save')
  visit professional_developments_path
  click_on('Submit for Approval')
  visit employee_professional_developments_path(employee_id: user.employee.id)
  click_on('Logout')
end

def user_check_approval_status
  sign_in user
  visit employee_professional_developments_path(employee_id: user.employee.id)
  expect(page).to have_content('Approval Status: Approved')
end

...then this.

became this.

  • 1 command line input

  • 1 screen

  • ~ 15 - 25 sec per option

And this

  • 30 clicks
  • 20 url changes
  • 5 text fields
  • ~3 - 5 min per option

Wonderful.

Questions?

Capybara Testing

By PJ Frias

Capybara Testing

  • 418