| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const fs = require('fs');
- const path = require('path');
- const readline = require('readline');
- const CollaborativeActions = require('./actions');
- const DebuggerSync = require('./debugger-sync');
- const { users, testDocument } = require('../config/users');
- class CollaborationTestOrchestrator {
- constructor() {
- this.userSessions = [];
- this.testResults = [];
- this.debuggerSync = new DebuggerSync();
- if(!fs.existsSync('screenshots')) {
- fs.mkdirSync('screenshots');
- }
- }
- async runCollaborationTest() {
- try {
- await this.initializeUsers();
- await this.setupDebuggerSync();
- await this.executeTestScenario();
- this.generateReport();
- await this.waitIndefinitely();
- } catch(error) {
- }
- }
- async initializeUsers() {
- const sessionPromises = users.map(async (user, index) => {
- const session = new CollaborativeActions(user, false, index); // Pass userIndex for positioning
- await session.initialize();
- return session;
- });
- this.userSessions = await Promise.all(sessionPromises);
- // Login all users simultaneously
- const loginPromises = this.userSessions.map(session => session.login());
- await Promise.all(loginPromises);
- // Open documents for all users simultaneously
- const documentPromises = this.userSessions.map(session =>
- session.openDocument(testDocument.url)
- );
- await Promise.all(documentPromises);
- }
- async setupDebuggerSync() {
- console.log('');
-
- const registrationPromises = this.userSessions.map(session =>
- session.registerDebuggerSync(this.debuggerSync)
- );
- await Promise.all(registrationPromises);
- await this.debuggerSync.enableSync();
-
- console.log('');
- console.log('');
- }
- async executeTestScenario() {
- console.log('');
- await this.waitForUserInput();
- const actionPromises = this.userSessions.map(session => session.executeUserActions());
- await Promise.all(actionPromises);
- }
- async takeAllScreenshots(suffix) {
- const screenshotPromises = this.userSessions.map(session =>
- session.takeScreenshot(suffix)
- );
- await Promise.all(screenshotPromises);
- }
- generateReport() {
- const report = {
- timestamp: new Date().toISOString(),
- testDocument: testDocument,
- users: users.map(user => ({
- id: user.id,
- name: user.name,
- role: user.role
- })),
- scenarios: [
- 'Authentication test'
- ],
- status: 'completed',
- duration: 'approximately 30 seconds'
- };
- fs.writeFileSync('test-report.json', JSON.stringify(report, null, 2));
- }
- async cleanup() {
- // Очищаем синхронизатор отладчика
- if (this.debuggerSync) {
- await this.debuggerSync.cleanup();
- }
-
- const cleanupPromises = this.userSessions.map(session => session.cleanup());
- await Promise.all(cleanupPromises);
- }
- async waitIndefinitely() {
- // Keep the process alive without closing browsers
- return new Promise(() => {
- // This promise never resolves, keeping browsers open
- });
- }
- async waitForUserInput() {
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- return new Promise((resolve) => {
- rl.question('', () => {
- rl.close();
- resolve();
- });
- });
- }
- }
- if(require.main === module) {
- const orchestrator = new CollaborationTestOrchestrator();
- orchestrator.runCollaborationTest()
- .then(() => {
- process.exit(0);
- })
- .catch((error) => {
- process.exit(1);
- });
- }
- module.exports = CollaborationTestOrchestrator;
|