index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const fs = require('fs');
  2. const path = require('path');
  3. const readline = require('readline');
  4. const CollaborativeActions = require('./actions');
  5. const DebuggerSync = require('./debugger-sync');
  6. const { users, testDocument } = require('../config/users');
  7. class CollaborationTestOrchestrator {
  8. constructor() {
  9. this.userSessions = [];
  10. this.testResults = [];
  11. this.debuggerSync = new DebuggerSync();
  12. if(!fs.existsSync('screenshots')) {
  13. fs.mkdirSync('screenshots');
  14. }
  15. }
  16. async runCollaborationTest() {
  17. try {
  18. await this.initializeUsers();
  19. await this.setupDebuggerSync();
  20. await this.executeTestScenario();
  21. this.generateReport();
  22. await this.waitIndefinitely();
  23. } catch(error) {
  24. }
  25. }
  26. async initializeUsers() {
  27. const sessionPromises = users.map(async (user, index) => {
  28. const session = new CollaborativeActions(user, false, index); // Pass userIndex for positioning
  29. await session.initialize();
  30. return session;
  31. });
  32. this.userSessions = await Promise.all(sessionPromises);
  33. // Login all users simultaneously
  34. const loginPromises = this.userSessions.map(session => session.login());
  35. await Promise.all(loginPromises);
  36. // Open documents for all users simultaneously
  37. const documentPromises = this.userSessions.map(session =>
  38. session.openDocument(testDocument.url)
  39. );
  40. await Promise.all(documentPromises);
  41. }
  42. async setupDebuggerSync() {
  43. console.log('');
  44. const registrationPromises = this.userSessions.map(session =>
  45. session.registerDebuggerSync(this.debuggerSync)
  46. );
  47. await Promise.all(registrationPromises);
  48. await this.debuggerSync.enableSync();
  49. console.log('');
  50. console.log('');
  51. }
  52. async executeTestScenario() {
  53. console.log('');
  54. await this.waitForUserInput();
  55. const actionPromises = this.userSessions.map(session => session.executeUserActions());
  56. await Promise.all(actionPromises);
  57. }
  58. async takeAllScreenshots(suffix) {
  59. const screenshotPromises = this.userSessions.map(session =>
  60. session.takeScreenshot(suffix)
  61. );
  62. await Promise.all(screenshotPromises);
  63. }
  64. generateReport() {
  65. const report = {
  66. timestamp: new Date().toISOString(),
  67. testDocument: testDocument,
  68. users: users.map(user => ({
  69. id: user.id,
  70. name: user.name,
  71. role: user.role
  72. })),
  73. scenarios: [
  74. 'Authentication test'
  75. ],
  76. status: 'completed',
  77. duration: 'approximately 30 seconds'
  78. };
  79. fs.writeFileSync('test-report.json', JSON.stringify(report, null, 2));
  80. }
  81. async cleanup() {
  82. // Очищаем синхронизатор отладчика
  83. if (this.debuggerSync) {
  84. await this.debuggerSync.cleanup();
  85. }
  86. const cleanupPromises = this.userSessions.map(session => session.cleanup());
  87. await Promise.all(cleanupPromises);
  88. }
  89. async waitIndefinitely() {
  90. // Keep the process alive without closing browsers
  91. return new Promise(() => {
  92. // This promise never resolves, keeping browsers open
  93. });
  94. }
  95. async waitForUserInput() {
  96. const rl = readline.createInterface({
  97. input: process.stdin,
  98. output: process.stdout
  99. });
  100. return new Promise((resolve) => {
  101. rl.question('', () => {
  102. rl.close();
  103. resolve();
  104. });
  105. });
  106. }
  107. }
  108. if(require.main === module) {
  109. const orchestrator = new CollaborationTestOrchestrator();
  110. orchestrator.runCollaborationTest()
  111. .then(() => {
  112. process.exit(0);
  113. })
  114. .catch((error) => {
  115. process.exit(1);
  116. });
  117. }
  118. module.exports = CollaborationTestOrchestrator;