generate_page_file
Creates WDIO page object files with element selectors and functions to structure automated test scenarios for web applications.
Instructions
Generate WDIO page object file with general functions and element selectors
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scenario_title | Yes | Title of the test scenario | |
| selectors | Yes | Selectors for each UI element | |
| page_functions | No | List of page functions needed | |
| output_path | Yes | Path where the page file should be saved |
Implementation Reference
- index.js:238-267 (registration)Tool registration configuration including name, description, and input schema validation for generate_page_file{ name: 'generate_page_file', description: 'Generate WDIO page object file with general functions and element selectors', inputSchema: { type: 'object', properties: { scenario_title: { type: 'string', description: 'Title of the test scenario', minLength: 1, }, selectors: { type: 'object', description: 'Selectors for each UI element', }, page_functions: { type: 'array', items: { type: 'string' }, description: 'List of page functions needed', }, output_path: { type: 'string', description: 'Path where the page file should be saved', minLength: 1, }, }, required: ['scenario_title', 'selectors', 'output_path'], additionalProperties: false, }, },
- index.js:1023-1043 (handler)Main handler function for the generate_page_file tool: destructures args, calls buildPageFileContent to generate code, ensures directory exists, writes file to output_path, returns confirmation with generated contentasync generatePageFile(args) { const { scenario_title, selectors, page_functions = [], output_path } = args; try { const pageContent = this.buildPageFileContent(scenario_title, selectors, page_functions); await fs.ensureDir(path.dirname(output_path)); await fs.writeFile(output_path, pageContent); return { content: [ { type: 'text', text: `Page file generated successfully at: ${output_path}\n\nContent:\n${pageContent}`, }, ], }; } catch (error) { throw new Error(`Failed to generate page file: ${error.message}`); } }
- index.js:1123-1143 (helper)Helper function that generates the complete page object JavaScript code: creates class name, generates selector getter methods and page action methods, formats as string with JSDocbuildPageFileContent(scenario_title, selectors, page_functions) { const className = this.toPascalCase(scenario_title.replace(/[^a-zA-Z0-9]/g, '')) + 'Page'; const selectorMethods = this.generateSelectorMethods(selectors); const pageMethods = this.generatePageMethods(page_functions); return `/** * Page Object Model for ${scenario_title} * Contains selectors and page-specific functions */ class ${className} { // Element selectors ${selectorMethods} // Page functions ${pageMethods} } module.exports = ${className}; `; }
- index.js:1739-1744 (helper)Helper that generates getter methods for page selectors from selectors objectreturn Object.keys(selectors).map(key => { return ` get ${this.toCamelCase(key)}() { return $('${selectors[key]}'); }`; }).join('\n\n'); }
- index.js:1746-1753 (helper)Helper that generates async page action methods from list of page_functionsgeneratePageMethods(page_functions) { return page_functions.map(func => { const methodName = this.toCamelCase(func); return ` async ${methodName}() { ${this.generatePageMethodImplementation(func, methodName)} }`; }).join('\n\n'); }