The Agile Way

The Agile Way

Share this post

The Agile Way
The Agile Way
16 Refactoring: Move to Helper
Selenium Training Workbook

16 Refactoring: Move to Helper

Make extracted function available to all other test scripts

Zhimin Zhan's avatar
Zhimin Zhan
Dec 12, 2022
∙ Paid
1

Share this post

The Agile Way
The Agile Way
16 Refactoring: Move to Helper
Share

Learning Objectives

  • Review

    • Extract Function Refactoring

  • Move to Helper Refactoring

Tasks

In the previous session, we extracted the three user-sign-in steps into a function `sign_in`.

  def sign_in(login, password)
    driver.find_element(:id, "username").send_keys(login)
    driver.find_element(:name, "password").send_keys(password)
    driver.find_element(:name, "commit").click
  end

We continue to extract the sign-off step.

After that, rerun the test script `login_spec.rb`, and it shall still work.

Now, you might wonder, how to use the `sign_in` function in other test scripts? The answer: move the function to a shared test helper. All functions declared in this shared test helper are available to all test scripts.

While we can move the functional by hand, it is recommended.

Use “Move to helper” functional test refactoring.

Task 1. Extract the sign-off step to a function

Select the sign-off test step, and select men `Refactor` → `Extract to Function …`

In the “Extract Function” dialog, enter the function name “sign_off”.

Keep reading with a 7-day free trial

Subscribe to The Agile Way to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zhimin Zhan
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share