Skip to main content
Glama

Automation Script Generator MCP Server

integration.test.js•9.06 kB
/** * Integration Tests * End-to-end testing of the complete workflow */ import { jest } from '@jest/globals'; import { AutomationScriptGenerator } from '../index.js'; import fs from 'fs-extra'; import path from 'path'; describe('Integration Tests', () => { let generator; let testDir; beforeEach(async () => { generator = new AutomationScriptGenerator(); testDir = path.join(process.cwd(), 'integration-test'); await fs.ensureDir(testDir); }); afterEach(async () => { if (await fs.pathExists(testDir)) { await fs.remove(testDir); } }); describe('Complete Workflow', () => { test('should process a complete test scenario', async () => { const args = { scenario_title: 'User Registration Process', tags: ['@registration', '@smoke'], gherkin_syntax: `Feature: User Registration Scenario: Successful user registration Given I am on the registration page When I enter valid user details And I click the register button Then I should see success message`, selectors: { firstNameInput: '#firstName', lastNameInput: '#lastName', emailInput: '#email', registerButton: '[data-testid="register-btn"]', successMessage: '.success-message' }, data_items: { validUser: { firstName: 'John', lastName: 'Doe', email: 'john.doe@example.com' } }, output_directory: testDir }; const result = await generator.processTestScenario(args); // Verify response structure expect(result).toHaveProperty('content'); expect(result.content[0]).toHaveProperty('text'); expect(result.content[0].text).toMatch(/Successfully processed/); // Verify files were created const featuresDir = path.join(testDir, 'features'); const stepsDir = path.join(testDir, 'step-definitions'); const pagesDir = path.join(testDir, 'pageobjects'); expect(await fs.pathExists(featuresDir)).toBe(true); expect(await fs.pathExists(stepsDir)).toBe(true); expect(await fs.pathExists(pagesDir)).toBe(true); // Verify feature file content const featureFiles = await fs.readdir(featuresDir); expect(featureFiles.length).toBeGreaterThan(0); const featureContent = await fs.readFile( path.join(featuresDir, featureFiles[0]), 'utf8' ); expect(featureContent).toContain('Feature: User Registration'); expect(featureContent).toContain('@registration'); expect(featureContent).toContain('Given I am on the registration page'); // Verify step file content const stepFiles = await fs.readdir(stepsDir); expect(stepFiles.length).toBeGreaterThan(0); const stepContent = await fs.readFile( path.join(stepsDir, stepFiles[0]), 'utf8' ); expect(stepContent).toContain('Given('); expect(stepContent).toContain('When('); expect(stepContent).toContain('Then('); expect(stepContent).toContain('browser.url'); // Verify page object content const pageFiles = await fs.readdir(pagesDir); expect(pageFiles.length).toBeGreaterThan(0); const pageContent = await fs.readFile( path.join(pagesDir, pageFiles[0]), 'utf8' ); expect(pageContent).toContain('class'); expect(pageContent).toContain('#firstName'); expect(pageContent).toContain('[data-testid="register-btn"]'); }); test('should update existing files when similar content found', async () => { // Create existing login feature const featuresDir = path.join(testDir, 'features'); await fs.ensureDir(featuresDir); await fs.writeFile(path.join(featuresDir, 'login.feature'), ` Feature: User Authentication @login Scenario: Basic login Given I am on the login page When I enter credentials Then I should be logged in `); // Process similar scenario const args = { scenario_title: 'User Login with Remember Me', tags: ['@login', '@enhancement'], gherkin_syntax: `Scenario: Login with remember me option Given I am on the login page When I enter valid credentials And I check remember me option Then I should be logged in And I should stay logged in next visit`, selectors: { usernameInput: '#username', passwordInput: '#password', rememberMeCheckbox: '#remember', loginButton: '.login-btn' }, output_directory: testDir }; await generator.processTestScenario(args); // Verify existing file was updated const featureContent = await fs.readFile( path.join(featuresDir, 'login.feature'), 'utf8' ); expect(featureContent).toContain('Basic login'); expect(featureContent).toContain('remember me option'); expect(featureContent).toContain('@enhancement'); }); test('should handle repository analysis', async () => { // Create sample repository structure await fs.ensureDir(path.join(testDir, 'features')); await fs.ensureDir(path.join(testDir, 'utils')); await fs.writeFile(path.join(testDir, 'features', 'sample.feature'), ` Feature: Sample Scenario: Test scenario Given I test something `); await fs.writeFile(path.join(testDir, 'utils', 'helpers.js'), ` export function waitForElement(selector) { return browser.waitUntil(() => $(selector).isDisplayed()); } export const testData = { user: { name: 'test' } }; `); const result = await generator.analyzeRepositoryPatterns({ repo_path: testDir, pattern_types: ['features', 'utils'] }); expect(result).toHaveProperty('content'); const analysis = JSON.parse(result.content[0].text); expect(analysis).toHaveProperty('patterns'); expect(analysis).toHaveProperty('utils'); expect(analysis).toHaveProperty('conventions'); expect(analysis.patterns.features).toHaveLength(1); expect(analysis.utils).toHaveProperty('helpers'); }); }); describe('Error Recovery', () => { test('should handle invalid output directory', async () => { const args = { scenario_title: 'Test Scenario', gherkin_syntax: 'Given test step', selectors: { button: '#btn' }, output_directory: '/invalid/readonly/path' }; // Should not throw but handle gracefully await expect(generator.processTestScenario(args)).rejects.toThrow(); }); test('should handle malformed Gherkin syntax', async () => { const args = { scenario_title: 'Test Scenario', gherkin_syntax: 'Invalid gherkin without proper structure', selectors: { button: '#btn' }, output_directory: testDir }; const result = await generator.processTestScenario(args); expect(result).toHaveProperty('content'); // Should complete but with basic implementation }); }); describe('Performance', () => { test('should handle large repository analysis efficiently', async () => { // Create multiple files const numFiles = 20; await fs.ensureDir(path.join(testDir, 'features')); for (let i = 0; i < numFiles; i++) { await fs.writeFile( path.join(testDir, 'features', `feature-${i}.feature`), `Feature: Test Feature ${i}\n Scenario: Test ${i}\n Given step ${i}` ); } const startTime = Date.now(); const result = await generator.analyzeRepositoryPatterns({ repo_path: testDir, pattern_types: ['features'] }); const endTime = Date.now(); expect(endTime - startTime).toBeLessThan(5000); // Should complete in under 5 seconds expect(result).toHaveProperty('content'); const analysis = JSON.parse(result.content[0].text); expect(analysis.patterns.features).toHaveLength(numFiles); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/raymondsambur/automation-script-generator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server