Fragments
What are Fragments?
Fragments are reusable blocks of test steps that you can use across multiple test cases.
They help you avoid duplication and make your tests easier to maintain.
Why Use Fragments
Use Fragments when:
The same steps are repeated across tests (e.g., login, navigation)
You want to standardize common flows
You want to update logic in one place instead of many
💡 Update a Fragment once → all dependent tests benefit automatically.
Create a Fragment
Extract from an Existing Test Case
You can convert existing steps into a reusable Fragment directly from a test case.
Steps:
Select the steps you want to reuse
Click the more options
button next to the Preview buttonClick Extract
Enter a name in the Extract as Fragment modal
Click Create
Replace Source Steps
When enabled → the selected steps are replaced with a Fragment call
If disabled → the Fragment is created, but the original steps remain
💡 This is the fastest way to refactor duplicate logic into reusable components.
Create from Scratch
Open the TestFirst Editor
Open the library from the left toolbar, then switch to the Fragment tab (next to the Test Case tab)
Right-click → New Fragment, or click the more options icon
in the toolbar → New FragmentEnter a fragment name and double-click to open it
Add steps using Gherkin or the Recorder
Save the Fragment
Use a Fragment in a Test Case
Once created, Fragments can be reused in test cases.
Example
Running a Fragment
Fragments can be run independently or within the context of a calling test case, depending on their setup and dependencies.
To run a Fragment independently:
Open the Fragment in the editor.
Run the Fragment directly.
To run a Fragment with a calling test case:
Open the Fragment in the editor.
Use the Run with dropdown.
Select a test case that uses the Fragment.
Run the test.
💡 Use Run with when the Fragment depends on setup, variables, browser sessions, or other context provided by the calling test case.
🌟Prefer opening the browser in the main test case so the Fragment can reuse the session.
Open a browser inside the Fragment only when a separate session or user is required.
Example: User 1 submits a form in Browser 1, and User 2 verifies it in Browser 2.
When to Use Fragments
Fragments are ideal for:
Login / authentication flows
Repeated navigation steps
Setup or precondition steps
Complex reusable sequences
Best Practices
Keep Fragments small and focused
Use clear, descriptive names (e.g.,
Login Flow,Create User)Avoid putting too many unrelated steps in one Fragment
Reuse instead of duplicating logic
Things to Keep in Mind
Changes to a Fragment affect all test cases using it
Fragments should represent reusable behaviour, not full test cases
Keep them stable to avoid breaking multiple tests
Last updated

