Mahdi Naser Moghadasi commited on
Commit
7ce2c5a
·
1 Parent(s): 697e972

Fix Task 5 - ensure code is actually written in editor

Browse files

- Wait longer for editor to be ready (500ms)
- Click editor to focus before typing
- Trigger focus/click events for Monaco editor
- Type code character by character to ensure it's written
- Verify code was actually typed with multiple checks (Monaco textarea, CodeMirror, Monaco view-lines)
- Retry typing if verification fails
- Better logging to show code preview and length

Files changed (1) hide show
  1. scripts/create-tutorial-video.js +110 -16
scripts/create-tutorial-video.js CHANGED
@@ -608,42 +608,136 @@ async function createTutorialVideo() {
608
  // ============================================
609
  console.log('📋 Task 5: Writing code in editor...');
610
 
 
 
 
611
  const editorSelector = '#tour-code-editor, .monaco-editor, .cm-editor';
612
  const editor = page.locator(editorSelector).first();
613
 
614
- if (await editor.isVisible({ timeout: 2000 }).catch(() => false)) {
615
- const editorBox = await editor.boundingBox().catch(() => null);
 
616
  if (editorBox) {
 
617
  await moveHandToTarget(page, editorBox.x + editorBox.width / 2, editorBox.y + editorBox.height / 2);
618
  await page.mouse.click(editorBox.x + editorBox.width / 2, editorBox.y + editorBox.height / 2);
619
- await page.waitForTimeout(30);
620
  }
621
  }
622
 
623
- await page.evaluate(() => {
624
- const monacoEditor = document.querySelector('.monaco-editor textarea, .monaco-editor .inputarea');
625
- if (monacoEditor) {
626
- monacoEditor.focus();
627
- return true;
 
 
 
 
 
 
628
  }
 
 
629
  const cmEditor = document.querySelector('.cm-editor, .cm-content');
630
  if (cmEditor) {
631
  cmEditor.focus();
632
- return true;
 
633
  }
634
- return false;
 
635
  });
636
 
637
- await page.waitForTimeout(15);
 
 
 
 
 
 
638
 
 
 
 
639
  await page.keyboard.press('Control+A');
640
- await page.waitForTimeout(15);
641
  await page.keyboard.press('Delete');
642
- await page.waitForTimeout(30);
 
 
 
 
 
 
 
643
 
644
- await page.keyboard.type(CONFIG.sampleCode, { delay: CONFIG.delays.typing });
645
- await page.waitForTimeout(50);
646
- console.log('✅ Code written in editor');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
647
 
648
  // ============================================
649
  // TASK 6: Hit the Run button
 
608
  // ============================================
609
  console.log('📋 Task 5: Writing code in editor...');
610
 
611
+ // Wait for editor to be ready
612
+ await page.waitForTimeout(500);
613
+
614
  const editorSelector = '#tour-code-editor, .monaco-editor, .cm-editor';
615
  const editor = page.locator(editorSelector).first();
616
 
617
+ let editorBox = null;
618
+ if (await editor.isVisible({ timeout: 3000 }).catch(() => false)) {
619
+ editorBox = await editor.boundingBox().catch(() => null);
620
  if (editorBox) {
621
+ // Move mouse to editor and click to focus
622
  await moveHandToTarget(page, editorBox.x + editorBox.width / 2, editorBox.y + editorBox.height / 2);
623
  await page.mouse.click(editorBox.x + editorBox.width / 2, editorBox.y + editorBox.height / 2);
624
+ await page.waitForTimeout(200);
625
  }
626
  }
627
 
628
+ // Focus editor using page.evaluate with better handling
629
+ const editorFocused = await page.evaluate(() => {
630
+ // Try Monaco editor textarea
631
+ const monacoTextarea = document.querySelector('.monaco-editor textarea, .monaco-editor .inputarea');
632
+ if (monacoTextarea) {
633
+ monacoTextarea.focus();
634
+ monacoTextarea.click();
635
+ // Trigger focus event to ensure Monaco knows it's focused
636
+ monacoTextarea.dispatchEvent(new Event('focus', { bubbles: true }));
637
+ monacoTextarea.dispatchEvent(new Event('click', { bubbles: true }));
638
+ return { type: 'monaco', element: monacoTextarea };
639
  }
640
+
641
+ // Try CodeMirror
642
  const cmEditor = document.querySelector('.cm-editor, .cm-content');
643
  if (cmEditor) {
644
  cmEditor.focus();
645
+ cmEditor.click();
646
+ return { type: 'codemirror', element: cmEditor };
647
  }
648
+
649
+ return null;
650
  });
651
 
652
+ if (!editorFocused) {
653
+ console.log('⚠️ Editor not found, trying Tab to focus...');
654
+ await page.keyboard.press('Tab');
655
+ await page.waitForTimeout(200);
656
+ } else {
657
+ console.log(`✅ Editor focused (${editorFocused.type})`);
658
+ }
659
 
660
+ await page.waitForTimeout(200);
661
+
662
+ // Clear existing code - select all and delete
663
  await page.keyboard.press('Control+A');
664
+ await page.waitForTimeout(100);
665
  await page.keyboard.press('Delete');
666
+ await page.waitForTimeout(100);
667
+
668
+ // Type code character by character to ensure it's written
669
+ console.log('⌨️ Typing code...');
670
+ for (const char of CONFIG.sampleCode) {
671
+ await page.keyboard.type(char, { delay: CONFIG.delays.typing });
672
+ }
673
+ await page.waitForTimeout(200);
674
 
675
+ // Verify code was actually typed
676
+ const codeTyped = await page.evaluate(() => {
677
+ // Check Monaco editor
678
+ const monacoTextarea = document.querySelector('.monaco-editor textarea, .monaco-editor .inputarea');
679
+ if (monacoTextarea) {
680
+ const value = monacoTextarea.value || '';
681
+ return { typed: value.length > 10, length: value.length, preview: value.substring(0, 50) };
682
+ }
683
+
684
+ // Check CodeMirror
685
+ const cmEditor = document.querySelector('.cm-editor, .cm-content');
686
+ if (cmEditor) {
687
+ const text = cmEditor.textContent || '';
688
+ return { typed: text.length > 10, length: text.length, preview: text.substring(0, 50) };
689
+ }
690
+
691
+ // Check Monaco view-lines (rendered content)
692
+ const monacoLines = document.querySelector('.monaco-editor .view-lines');
693
+ if (monacoLines) {
694
+ const text = monacoLines.textContent || '';
695
+ return { typed: text.length > 10, length: text.length, preview: text.substring(0, 50) };
696
+ }
697
+
698
+ return { typed: false, length: 0, preview: '' };
699
+ });
700
+
701
+ if (codeTyped.typed) {
702
+ console.log(`✅ Code written in editor (${codeTyped.length} chars): ${codeTyped.preview}...`);
703
+ } else {
704
+ console.log(`⚠️ Code may not have been written (length: ${codeTyped.length}), trying again...`);
705
+
706
+ // Retry: Clear and type again
707
+ await page.keyboard.press('Control+A');
708
+ await page.waitForTimeout(100);
709
+ await page.keyboard.press('Delete');
710
+ await page.waitForTimeout(200);
711
+
712
+ // Type again with slightly slower delay
713
+ for (const char of CONFIG.sampleCode) {
714
+ await page.keyboard.type(char, { delay: CONFIG.delays.typing * 2 });
715
+ }
716
+ await page.waitForTimeout(300);
717
+
718
+ // Verify again
719
+ const retryCheck = await page.evaluate(() => {
720
+ const monacoTextarea = document.querySelector('.monaco-editor textarea, .monaco-editor .inputarea');
721
+ if (monacoTextarea) {
722
+ return (monacoTextarea.value || '').length > 10;
723
+ }
724
+ const cmEditor = document.querySelector('.cm-editor, .cm-content');
725
+ if (cmEditor) {
726
+ return (cmEditor.textContent || '').length > 10;
727
+ }
728
+ const monacoLines = document.querySelector('.monaco-editor .view-lines');
729
+ if (monacoLines) {
730
+ return (monacoLines.textContent || '').length > 10;
731
+ }
732
+ return false;
733
+ });
734
+
735
+ if (retryCheck) {
736
+ console.log('✅ Code written in editor (after retry)');
737
+ } else {
738
+ console.log('⚠️ Code still not written, but continuing...');
739
+ }
740
+ }
741
 
742
  // ============================================
743
  // TASK 6: Hit the Run button