generate_component_file
Creates a component file with specified data items and saves it to a designated path, enabling efficient test scenario management in WDIO test suites.
Instructions
Generate component file with collection of data items (only if needed)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data_items | Yes | Collection of data items for the component | |
| output_path | Yes | Path where the component file should be saved | |
| scenario_title | Yes | Title of the test scenario |
Implementation Reference
- src/code-generator.js:142-172 (handler)Handler function that generates the complete content for a component file (test data file) based on scenario title and data items. This is the core implementation for creating component files.buildComponentFileContent(scenario_title, data_items = {}) { let content = ''; // Add header if (this.config.get('fileGeneration.includeMetadata')) { content += this.generateFileHeader('Test Data Component', scenario_title); } // Add JSDoc if (this.config.shouldEnforceJSDoc()) { content += `/**\n * Test data for ${scenario_title}\n */\n\n`; } // Generate data objects Object.keys(data_items).forEach(key => { const dataObject = data_items[key]; content += `export const ${key} = {\n`; Object.keys(dataObject).forEach(prop => { const value = typeof dataObject[prop] === 'string' ? `'${dataObject[prop]}'` : dataObject[prop]; content += ` ${prop}: ${value},\n`; }); content += '};\n\n'; }); // Add utility functions for data manipulation content += this.generateDataUtilityFunctions(data_items); return this.formatCode(content, 'javascript'); }