1. Preface
    1. About MarathonITE
    2. Supported Platforms
      1. Java/Swing™
      2. Java/FX™
      3. Web Applications
    3. What's New in MarathonITE 5.0
    4. Change Log a.k.a Version History
    5. System Requirements
    6. Copyright Notice
  2. Getting Started
    1. Introduction to Test Automation
      1. Unattended Testing
      2. Semi Automated Testing
      3. Exploratory Testing
    2. MarathonITE Projects
    3. Your First Project
      1. Java/Swing™ Test Project
        1. Application Under Test - SwingSet3
        2. Creating a Project
        3. Recording a Test
        4. Anatomy of a Test Script
        5. Running Tests
        6. Looking at Results
      2. Java/FX™ Test Project
        1. Application Under Test - Ensemble
        2. Creating a Project
        3. Recording a Test
        4. Anatomy of a Test Script
        5. Running Tests
        6. Looking at Results
      3. Web Application Test Project
        1. Application Under Test - DuckDuckGo Search
        2. Creating a Project
        3. Recording a Test
        4. Anatomy of a Test Script
        5. Running Tests
        6. Looking at Results
    4. MarathonITE Sample Projects
  3. User Guide
    1. Installation and Startup
    2. MarathonITE User Interface
      2. Editors
      3. Output Views
    3. Creating Marathonite Test Projects
    4. Recording Tests
    5. Managing Checklists
    6. Exploratory Tests
    7. Semi Automated Tests
    8. Executing Tests
      1. Executing a Test from Editor
        1. Debugging Scripts
        2. Using Script Console
      2. Executing Tests from Test Runner
      3. Executing Tests in Batch Mode
    9. Organizing Tests
      1. Organizing Tests in Folder Heirarchy
      2. Organizing Tests as Features and Stories
      3. Organizing Tests in Suites
      4. Linking Tests to TMS and Issue Manager
    10. Modularizing Test Scripts
      1. Module Methods
      2. Extract Method Refactoring
      3. Using Data Loops
      4. Convert to Data Loop Refactoring
    11. Data Driven Tests
      1. Convert to DDT Refactoring
  4. Advanced Scripting
    1. Ruby Programming Language
    2. Marathon and Ruby
    3. Selenium/WebDriver Bindings
      1. Java/Swing™ Components
      2. Java/FX™ Controls

3.10.2.Extract Method Refactoring

Refactoring is a technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Extract Method is an important refactoring. Extracting a method improves readability of your test script and improves reusability.

MarathonITE supports extract method refactoring. Using this option you can create module methods.

Performing an Extract Method Refactoring

We will use the following script to demonstrate the use of extract method refactoring.

Orginal Script

You can select the code you want to extract into a module method and click on the Extract Module menu item in the tool bar.

Extract Module Toolbar Button - Marathonite

MarathonITE displays Extract a Module Function dialog.

Extract Module Dialog - Marathonite

The option Extract allows you to extract the method and place it in the same test script. When you use the Extract to Module option, you can place it into an external module file and the method can be reused in other scripts.

Identifying the Parameters

The window displays the selected code in the upper pane. The lower pane displays the costants and variables that are used in the selected line of code. Click on the checkbox to select the variables that are to be extracted as method parameters. You can change the paramter name by modifying the Extract with name column of the table.

Extract code into a method

Click on the Extract button.
MarathonITE displays a Method Details dialog.

Extract Method Details - Marathonite

Enter a name for the method and optionally enter the description. Click on OK to perform the refactoring.

Test Script

Extract a Module Method

When you click on the Extract to Module, MarathonITE opens the Module Method Details dialog.

Extract Module Method Details - Marathonite

Enter the module method name. Optionally add a description to the method. From the module directory dropdown select a module folder. In the module file field - either select an existing file or enter a new file name.

Click OK. MarathonITE extracts the method into the given file and places it in the Modules folder. The existing script is refactored to use the extracted method.

While recording, you can use insert script command to reuse a module method.

Suggest Edit
Close Menu