Patterns
Patterns in Aptori provide a powerful, global way to manage dynamic values for your automated tests. By leveraging regular expressions for both field names and field values, Patterns allow tests to seamlessly match or populate data in any field that matches a defined pattern.
Overview
A pattern describes the allowable values for a field using two regular expressions. A field pattern matches the field name and a value pattern matches the contents of the field.
- Patterns are defined at the organization level, making them accessible to all users within that organization.
- Patterns are defined in a named group that may contain regular expressions for multiple fields, allowing you to group related test data (e.g., different user attributes).
- Patterns are used for automatic matching of sensitive data.
- Patterns are used for automatic generation of field values in your API requests or forms.
By centralizing test data and using regular expressions for matching, Patterns drastically reduces the need for repetitive test data definitions in each test configuration (Sift).
Key Features
-
Regex-Based Field Pattern
A field’s name is matched with a simple or advanced regex (e.g.,phoneNumber
,.*Email$
), allowing Aptori to automatically detect fields that match that pattern. -
Multiple Types of Value Patterns
Each value pattern may be one of three types:- String: Holds a static or templated text value.
- Regex: Generates randomized strings based on a regex pattern.
- Number: Produces numeric values (e.g., random within a range or a static number).
-
Dynamic Data Generation
For Regex type, Aptori will generate new data at runtime, ensuring fresh test data for each test run. -
Global Scope & Accessibility
Once created by an organization owner, any user can reference or automatically apply Patterns in a Sift configuration. -
Consistency & Scalability
Changes to a Pattern in one place are reflected everywhere it’s used, simplifying maintenance and allowing your tests to scale more easily.
How It Works
-
Create a Patterns group
The organization owner creates or updates a Patterns group with one or more fields. -
Define the Field Pattern and Value Pattern
- Field Pattern: Can be a plain text name (e.g.,
phoneNumber
) or a regex pattern (e.g.,^phoneNumber$
or^phone.*
). - Value Pattern: For String and Number type, specify an exact value to use for the field in a request. For Regex type, specify a regular expression (e.g.,
\d{10}
for a 10-digit number) to match a value in a response or produce a dynamic value in each request containing a field that matches the field pattern.
- Field Pattern: Can be a plain text name (e.g.,
-
Aptori Matches Fields Automatically
When a Sift creates a request, any input field whose key matches the field pattern is assigned a dynamically generated value that adheres to the value pattern.
Setup & Configuration
-
Navigate to “Patterns” Access the Patterns section in Aptori using the left navigation in section Manage.
-
Create or Edit a Patterns group
- Click Add + or edit an existing one.
- Provide a name for the Patterns (e.g.,
UserDetails
).
-
Add Pattern
Each entry includes a Field Pattern, Type, and Value Pattern. Field Pattern is a regular expression to match a field name. Type describes how Value Pattern is applied to generate a value, and may be either String, Number, or Regex. Example:- Field Pattern (
phoneNumber
): The regex pattern to match input fields. - Type (
Regex
): Indicates that Value Pattern be interpreted as a regex to match or produce values. - Value Pattern (
\d{10}
): The pattern to match or generate a 10-digit number.
- Field Pattern (
-
Save Your Patterns
Once saved, the patterns become available across the organization. -
Select the Patterns to Use in a Configuration
- To use Patterns to generate field values in requests, navigate to the Configurations section in Aptori. Create a new configuration or edit an existing one. Within the configuration, go to the Optional settings and choose the Patterns to be used as Global Generators.
- To use Patterns to match sensitive data exposure, navigate to the Configurations section in Aptori. Create a new configuration or edit an existing one. Within the configuration, go to the Analyzers > Excessive Data Exposure Analyzers section and choose the Data Exposure analyzer. Select the Patterns to be matched by the analyzer.
Best Practices
-
Use Precise Regexes
- Make sure your Field Patterns clearly indicate the field(s) they should match (e.g.,
^phoneNumber$
rather than a broad pattern).
- Make sure your Field Patterns clearly indicate the field(s) they should match (e.g.,
-
Organize Patterns by Function
- Keep related patterns (e.g., “User Data,” “Payment Info”) together in the same Patterns group for easier maintenance and use.
-
Test Your Patterns
- Use a regex tester to confirm you’re matching the exact fields (neither missing nor overly capturing fields).
-
Avoid Overly Broad Names
- Be mindful not to create a Field Pattern like
.*
which would inadvertently match and generate values for all fields.
- Be mindful not to create a Field Pattern like