projects_getLoadTestScripts
Retrieve load test scripts from a specific project in LoadRunner Cloud to analyze performance testing configurations and workflows.
Instructions
Retrieve scripts for a load test in a project from LoadRunner Cloud.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | The ID of the project. | |
| loadTestId | Yes | The ID of the load test. |
Implementation Reference
- The handler function that makes an authenticated GET request to the LoadRunner Cloud API to retrieve scripts for the specified load test in the project.const executeFunction = async ({ projectId, loadTestId }) => { const baseUrl = process.env.LRC_BASE_URL; const tenantId = process.env.LRC_TENANT_ID; const token = await getAuthToken(); try { // Construct the URL with query parameters const url = new URL(`${baseUrl}/projects/${projectId}/load-tests/${loadTestId}/scripts`); url.searchParams.append('TENANTID', tenantId); // Set up headers for the request const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }; // Perform the fetch request const response = await fetch(url.toString(), { method: 'GET', headers }); // Check if the response was successful if (!response.ok) { const text = await response.text(); try { const errorData = JSON.parse(text); throw new Error(JSON.stringify(errorData)); } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON error response:', text); throw new Error(text); } } // Parse and return the response data const text = await response.text(); try { const data = JSON.parse(text); return data; } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON success response:', text); return { error: 'Received non-JSON response from API', raw: text }; } } catch (error) { console.error('Error retrieving load test scripts:', error); return { error: 'An error occurred while retrieving load test scripts.' }; } };
- The tool schema defining the name, description, and input parameters (projectId and loadTestId as required strings).function: { name: 'projects_getLoadTestScripts', description: 'Retrieve scripts for a load test in a project from LoadRunner Cloud.', parameters: { type: 'object', properties: { projectId: { type: 'string', description: 'The ID of the project.' }, loadTestId: { type: 'string', description: 'The ID of the load test.' } }, required: ['projectId', 'loadTestId'] } }
- tools/paths.js:1-11 (registration)The toolPaths array includes the path to this tool's definition file, enabling its dynamic discovery and registration.export const toolPaths = [ 'loadrunner-cloud/load-runner-cloud-api/projects-get-projects.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-active-test-runs.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-transactions.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-summary.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-http-responses.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-recent.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-tests.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-test-scripts.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-test-runs.js' ];
- lib/tools.js:7-16 (registration)The discoverTools function dynamically imports the apiTool object from each file in toolPaths, registering all tools including projects_getLoadTestScripts.export async function discoverTools() { const toolPromises = toolPaths.map(async (file) => { const module = await import(`../tools/${file}`); return { ...module.apiTool, path: file, }; }); return Promise.all(toolPromises); }
- Uses getAuthToken helper (imported from auth-get-token.js) to obtain authentication token for API requests.const executeFunction = async ({ projectId, loadTestId }) => { const baseUrl = process.env.LRC_BASE_URL; const tenantId = process.env.LRC_TENANT_ID; const token = await getAuthToken(); try { // Construct the URL with query parameters const url = new URL(`${baseUrl}/projects/${projectId}/load-tests/${loadTestId}/scripts`); url.searchParams.append('TENANTID', tenantId); // Set up headers for the request const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }; // Perform the fetch request const response = await fetch(url.toString(), { method: 'GET', headers }); // Check if the response was successful if (!response.ok) { const text = await response.text(); try { const errorData = JSON.parse(text); throw new Error(JSON.stringify(errorData)); } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON error response:', text); throw new Error(text); } } // Parse and return the response data const text = await response.text(); try { const data = JSON.parse(text); return data; } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON success response:', text); return { error: 'Received non-JSON response from API', raw: text }; }