Core Modules
Essential modules providing core functionality for web automation, data management, and API testing.
🌐 mainFunctions
Purpose: Core navigation and URL handling for web automation.
Key Functions
-
prepareUrl(path)- Prepare URLs using configuration to generate full or relative paths -
extractPath(page, absolute)- Extract current page URL (absolute or relative) -
visitPath(page, path)- Navigate to URL with automatic cookie consent handling -
validatePath(page, path)- Validate current page URL contains expected path -
setViewport(page, device)- Set viewport size for different devices (mobile, tablet, laptop)
Example Usage
const mainFunctions = require('@cuppet/core/src/mainFunctions');
// Navigate to a page
await mainFunctions.visitPath(page, '/about');
// Validate current path
mainFunctions.validatePath(page, '/about');
// Set mobile viewport
await mainFunctions.setViewport(page, 'mobile');
🎯 elementInteraction
Purpose: Advanced element interaction and manipulation on web pages.
Key Functions
-
clickOnElement(page, selector)- Click on element with automatic wait and retry -
fillInput(page, selector, value)- Fill input fields with text -
selectOption(page, selector, value)- Select dropdown options -
checkCheckbox(page, selector)- Check/uncheck checkboxes -
waitForElement(page, selector, timeout)- Wait for element to appear -
getElementText(page, selector)- Extract text from elements -
isElementVisible(page, selector)- Check element visibility
Example Usage
const elementInteraction = require('@cuppet/core/src/elementInteraction');
// Click button
await elementInteraction.clickOnElement(page, 'button.submit');
// Fill form
await elementInteraction.fillInput(page, 'input[name="email"]', 'test@example.com');
// Select dropdown
await elementInteraction.selectOption(page, 'select#country', 'USA');
💾 dataStorage
Purpose: Store and retrieve data across test scenarios with variable interpolation.
Key Functions
-
saveVariable(key, value)- Save variable for later use -
getVariable(key)- Retrieve saved variable -
checkForSavedVariable(string)- Replace variable placeholders in strings -
checkForMultipleVariables(string)- Replace multiple variable placeholders -
clearStorage()- Clear all stored variables
Example Usage
const storage = require('@cuppet/core/src/dataStorage');
// Save data
await storage.saveVariable('userId', '12345');
// Use saved data with %variable% syntax
const url = await storage.checkForSavedVariable('/users/%userId%/profile');
// Returns: '/users/12345/profile'
// Multiple variables
const message = await storage.checkForMultipleVariables('Hello %firstName% %lastName%');
🔧 helperFunctions
Purpose: Utility functions for data manipulation, validation, and common operations.
Key Functions
-
getPropertyValue(object, path)- Get nested property values using dot notation -
generateRandomString(length)- Generate random strings -
formatDate(date, format)- Format dates -
parseJSON(string)- Safely parse JSON with error handling -
waitFor(milliseconds)- Wait for specified time
Example Usage
const helpers = require('@cuppet/core/src/helperFunctions');
// Get nested property
const email = helpers.getPropertyValue(user, 'contact.email');
// Generate random data
const randomId = helpers.generateRandomString(10);
// Wait
await helpers.waitFor(2000); // Wait 2 seconds
🌍 apiFunctions
Purpose: RESTful API testing with comprehensive request/response handling.
Key Functions
-
sendRequest(method, url, options)- Send HTTP requests (GET, POST, PUT, DELETE, PATCH) -
setRequestBody(body)- Set request body (JSON or form data) -
setRequestHeaders(headers)- Set custom headers -
validateResponseCode(expectedCode)- Validate HTTP status code -
validateResponseBody(expectedBody)- Validate response body -
validateJsonProperty(property, value)- Validate JSON response properties -
saveResponseProperty(property, variableName)- Save response data for later use
Example Usage
const apiFunctions = require('@cuppet/core/src/apiFunctions');
// Send POST request
apiFunctions.setRequestBody({ name: 'John', email: 'john@example.com' });
await apiFunctions.sendRequest('POST', '/api/users');
// Validate response
apiFunctions.validateResponseCode(201);
apiFunctions.validateJsonProperty('status', 'success');
// Save response data
apiFunctions.saveResponseProperty('id', 'newUserId');