import auth from '../tools/siemens-auth.js'; console.log('=== Testing NX Open Class Documentation Navigation ===\n'); const browser = await auth.getBrowser(); const page = await browser.newPage(); await page.setViewport({ width: 1400, height: 900 }); await auth.loadCookies(page); // Start from the main index page const baseUrl = 'https://docs.sw.siemens.com/documentation/external/PL20200522120320484/en-US/nx_open_python_ref/nx/1980/nx_open_python_ref/en-US/nxopen_python_ref/'; // Navigate to Class Index const classIndexUrl = baseUrl + 'classes.html'; console.log('Loading Class Index:', classIndexUrl); await page.goto(classIndexUrl, { waitUntil: 'networkidle2', timeout: 60000 }); await new Promise(r => setTimeout(r, 3000)); // Handle cookie popup if present const cookieBtn = await page.evaluateHandle(() => { const btns = Array.from(document.querySelectorAll('button')); return btns.find(b => b.innerText && b.innerText.includes('Accept All Cookies')); }); if (cookieBtn && cookieBtn.asElement()) { await cookieBtn.asElement().click(); await new Promise(r => setTimeout(r, 2000)); } const classIndexInfo = await page.evaluate(() => { return { title: document.title, url: window.location.href, bodyPreview: document.body.innerText.substring(0, 2000) }; }); console.log('Title:', classIndexInfo.title); console.log('URL:', classIndexInfo.url); console.log('\nContent preview:'); console.log(classIndexInfo.bodyPreview); // Find all class links const allClassLinks = await page.evaluate(() => { const links = Array.from(document.querySelectorAll('a')); return links .filter(a => a.href && (a.href.includes('class') || a.href.includes('struct'))) .map(a => ({ text: a.innerText.trim(), href: a.href })) .filter(l => l.text.length > 0) .slice(0, 50); }); console.log('\n=== Class links found:', allClassLinks.length); allClassLinks.slice(0, 20).forEach(l => console.log(` - ${l.text}`)); // Try clicking on the Session class if found const sessionLink = allClassLinks.find(l => l.text === 'Session' || l.text.includes('Session')); if (sessionLink) { console.log('\n=== Clicking on Session class ==='); console.log('Link:', sessionLink.href); await page.goto(sessionLink.href, { waitUntil: 'networkidle2', timeout: 60000 }); await new Promise(r => setTimeout(r, 3000)); const sessionInfo = await page.evaluate(() => { return { title: document.title, url: window.location.href, hasError: document.body.innerText.includes('Access Denied') || document.body.innerText.includes('Error'), bodyPreview: document.body.innerText.substring(0, 2000) }; }); console.log('\nSession class page:'); console.log('Title:', sessionInfo.title); console.log('URL:', sessionInfo.url); console.log('Has error:', sessionInfo.hasError); console.log('\nContent:'); console.log(sessionInfo.bodyPreview); await page.screenshot({ path: '/tmp/session-class.png' }); } else { // Try any class link if (allClassLinks.length > 0) { console.log('\n=== Clicking on first class:', allClassLinks[0].text); await page.goto(allClassLinks[0].href, { waitUntil: 'networkidle2', timeout: 60000 }); await new Promise(r => setTimeout(r, 3000)); const classInfo = await page.evaluate(() => { return { title: document.title, url: window.location.href, hasError: document.body.innerText.includes('Access Denied') || document.body.innerText.includes('Error'), bodyPreview: document.body.innerText.substring(0, 2000) }; }); console.log('Title:', classInfo.title); console.log('Has error:', classInfo.hasError); console.log('Content:', classInfo.bodyPreview); } } // Test accessing through the Doxygen wrapper URL console.log('\n=== Testing via Siemens docs portal wrapper ==='); const portalUrl = 'https://docs.sw.siemens.com/en-US/doc/209349590/PL20200522120320484.nxopen_python_ref?audience=external'; await page.goto(portalUrl, { waitUntil: 'networkidle2', timeout: 60000 }); await new Promise(r => setTimeout(r, 5000)); // Handle any cookie popup const cookieBtn2 = await page.evaluateHandle(() => { const btns = Array.from(document.querySelectorAll('button')); return btns.find(b => b.innerText && b.innerText.includes('Accept All Cookies')); }); if (cookieBtn2 && cookieBtn2.asElement()) { await cookieBtn2.asElement().click(); await new Promise(r => setTimeout(r, 2000)); } // Look for iframe const frames = page.frames(); console.log('Frames found:', frames.length); for (const frame of frames) { const frameUrl = frame.url(); if (frameUrl.includes('nxopen_python_ref')) { console.log('Found doc frame:', frameUrl); // Try to find and click on Classes menu const classesMenu = await frame.evaluateHandle(() => { const elements = Array.from(document.querySelectorAll('a, button, span')); return elements.find(e => e.innerText && e.innerText.trim() === 'Classes'); }); if (classesMenu && classesMenu.asElement()) { console.log('Found Classes menu, clicking...'); await classesMenu.asElement().click(); await new Promise(r => setTimeout(r, 2000)); // Check for dropdown const dropdown = await frame.evaluate(() => { const links = Array.from(document.querySelectorAll('a')); return links .filter(a => a.innerText && a.offsetParent !== null) .map(a => ({ text: a.innerText.trim(), href: a.href })) .filter(l => l.href.includes('class')) .slice(0, 10); }); console.log('Dropdown class links:', dropdown); } break; } } await page.screenshot({ path: '/tmp/portal-view.png' }); await auth.closeBrowser(); console.log('\n=== Test Complete ===');