test-autotest-nav-selector-fix.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { TestGenerator } from './src/tools/autotest/test-generator.js';
  2. function assert(condition, message) {
  3. if (!condition) throw new Error(message);
  4. }
  5. console.log('\n── AutoTest Navigation Selector Fix ──');
  6. const generator = new TestGenerator(null);
  7. const fixed = generator._fixNavigation(
  8. [{
  9. id: 'WF_001',
  10. page: '/Dashboard',
  11. steps: [
  12. { action: 'navigate', selector: 'https://example.test/app' },
  13. { action: 'click', selector: 'text=sidebarMessages', description: 'Navigate to messages' },
  14. { action: 'assert_visible', selector: 'vlid:sendBtn' },
  15. ],
  16. }],
  17. {
  18. homePage: '/Dashboard',
  19. pages: [
  20. { path: '/Dashboard', route: '/', navPath: [] },
  21. { path: '/MessageManage', route: '/messages', navPath: ['text=sidebarMessages'] },
  22. ],
  23. },
  24. 'https://example.test/app'
  25. );
  26. assert(fixed[0].steps[1].selector === 'vlid:sidebarMessages', 'nav click should use vlid: selector for id-like nav entries');
  27. const fixedLabelNav = generator._fixNavigation(
  28. [{
  29. id: 'WF_002',
  30. page: '/CourseList',
  31. steps: [
  32. { action: 'navigate', selector: 'https://example.test/app' },
  33. { action: 'assert_visible', selector: 'vlid:addButton' },
  34. ],
  35. }],
  36. {
  37. homePage: '/Dashboard',
  38. pages: [
  39. { path: '/Dashboard', route: '/', navPath: [] },
  40. { path: '/CourseList', route: '/courses', navPath: ['text=课程管理'] },
  41. ],
  42. },
  43. 'https://example.test/app',
  44. [
  45. { instanceId: 'navItem', text: '课程管理', position: 'sidebar' },
  46. ]
  47. );
  48. assert(
  49. fixedLabelNav[0].steps[1].selector === 'vlid:navItem[text="课程管理"]',
  50. 'label-based navPath should upgrade to vlid + text filter when nav discovery provides a component id'
  51. );
  52. console.log('PASS test-autotest-nav-selector-fix.js');