generate_page_file
Creates WDIO page object files by generating element selectors and predefined functions based on test scenarios, streamlining test automation setup for efficient script management.
Instructions
Generate WDIO page object file with general functions and element selectors
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| output_path | Yes | Path where the page file should be saved | |
| page_functions | No | List of page functions needed | |
| scenario_title | Yes | Title of the test scenario | |
| selectors | Yes | Selectors for each UI element |
Implementation Reference
- index.js:1023-1042 (handler)Primary execution handler for the generate_page_file tool. Destructures input arguments, invokes the buildPageFileContent helper to generate the page object code, ensures output directory exists, writes the file, and returns a success response with the generated content.async 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:239-266 (schema)Input schema definition for the generate_page_file tool, used for validation and MCP tool discovery. Defines required properties and structure for tool arguments.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:330-334 (registration)Registration of the ListTools endpoint that exposes the generate_page_file tool (via toolConfigs array) to MCP clients listing available tools.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolConfigs, }; });
- index.js:352-353 (registration)Dispatch registration in CallToolRequestSchema handler's switch statement that routes calls to the generate_page_file tool to its handler function.case 'generate_page_file': return await this.generatePageFile(args);
- index.js:1123-1142 (helper)Key helper method that constructs the complete WDIO page object JavaScript file content, including JSDoc, class definition, selector getters (via generateSelectorMethods), page methods (via generatePageMethods), and module export.buildPageFileContent(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}; `;