Script(Javascript) Support Overview
ReAPI introduces the N+0.1 testing solution, an innovative approach that optimizes collaboration between QA teams and developers. In this model, N represents any number of QA engineers, while 0.1 signifies a very small fraction of a developer’s time. Developers focus solely on writing modular, standalone functions that can be easily integrated into the no-code editor, empowering QA teams to design and execute tests independently.
Key Benefits of the N+0.1 Model
- Cost Efficiency: Maximizes productivity by minimizing developer involvement.
- Scalability: QA teams can scale test coverage effortlessly without depending on developers.
- Maintainability: Modular functions ensure reusability and consistency across tests.
- Seamless Collaboration: Developers create reusable test logic while QA teams focus on designing effective test cases without writing code.
ReAPI’s scripting capabilities seamlessly integrate with the no-code editor, allowing QA teams to leverage advanced, reusable, and scalable test logic without writing code. Developers can extend the platform’s functionality while testers continue working within the intuitive no-code environment.
Why Extend with Scripts?
QA teams often rely on standard assertions such as isString
and isNumber
, which cover basic validations but fall short when handling complex business logic. Over time, this results in fragmented, hard-to-maintain tests and inconsistent quality across projects.
Example Challenge:
In an e-commerce API, standard assertions may check data types but cannot verify:
- Order totals match line item calculations.
- Discounts and tax calculations comply with business rules.
- Shipping costs are accurately determined.
With ReAPI’s scripting capabilities, developers can create custom assertions that encapsulate such complex logic into reusable test components, which QA testers can easily select and apply in the no-code UI.
async function validateOrder(order) {
const calculatedTotal = order.items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const expectedTotal = calculatedTotal + order.tax + order.shipping - order.discount;
$addAssertionResult({
passed: Math.abs(expectedTotal - order.total) < 0.01,
message: expectedTotal === order.total
? "Order total is valid"
: `Expected ${expectedTotal}, but got ${order.total}`
});
}
Benefits of this approach:
- Improves test accuracy by validating business-specific logic.
- Reduces maintenance by centralizing logic.
- QA teams can directly use the new assertion via the no-code UI.
When to Use Scripts
Scenario | Example | Script Type |
---|---|---|
Complex Validations | Validate order calculations | Custom Assertion |
Dynamic Data | Generate unique email addresses | Value Function |
Request Modifications | Add authentication headers dynamically | API Hook |
Shared Utilities | Centralize date formatting logic | Global Script |
Third-party Integration | Use external validation libraries (e.g., IBAN check) | External Script |
Core Script Capabilities
ReAPI offers several script types to extend and customize test behavior, all of which are seamlessly integrated into the no-code editor.
1. Custom Assertions
Allow developers to create specialized validation rules that QA teams can apply in the no-code assertion builder without writing any code.
Use Cases:
- Checking if a string follows UUID format.
- Ensuring a geographic coordinate is valid.
Example:
async function isUUID(value) {
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
$addAssertionResult({ passed: uuidPattern.test(value), message: "UUID validation result" });
}
2. Value Functions
Enable dynamic data generation and transformations, allowing QA to select and use them via the no-code editor.
Use Cases:
- Generating test data like fake email addresses.
- Transforming timestamps into human-readable date strings.
Example:
async function formatTimestamp(timestamp) {
return new Date(timestamp).toISOString().split('T')[0];
}
3. API Hooks
Hooks provide control over request and response processing, allowing custom pre- and post-processing logic.
Use Cases:
- Adding security tokens before requests.
- Encrypting/decrypting request payloads.
Example:
async function beforeRequest($context, $request) {
$request.headers["Authorization"] = `Bearer ${$context.variables.token}`;
}
4. Global Scripts
Reusable utility functions that can be accessed across all test cases and scripts. These functions help standardize operations and reduce code duplication.
Use Cases:
- Managing shared authentication tokens.
- Common data transformations.
Example:
class $$DateUtils {
static format(date, timezone) {
return new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format(new Date(date));
}
}
5. External Scripts
With external scripts, developers can build custom utilities, assertions, value functions, and API hooks using their preferred local IDE and AI tools.
Key Benefits:
- Develop scripts in a familiar environment (e.g., VS Code).
- Utilize AI coding assistants like GitHub Copilot.
- Maintain and version control scripts in a private repository.
Example Workflow:
- Write utility functions locally.
- Test the script in your IDE.
- Deploy to your own server or publish to an NPM registry.
- Register the script in ReAPI for seamless use.
Conclusion
ReAPI’s scripting capabilities unlock the full potential of test automation by combining the flexibility of scripting with the ease of no-code workflows.