127 lines
4.8 KiB
JavaScript
127 lines
4.8 KiB
JavaScript
import auth from '../tools/siemens-auth.js';
|
|
|
|
console.log('=== Testing NX Open Class Documentation - Finding Session Class ===\n');
|
|
|
|
const browser = await auth.getBrowser();
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: 1400, height: 900 });
|
|
await auth.loadCookies(page);
|
|
|
|
// Navigate to S section of class index
|
|
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/';
|
|
|
|
// First get the classes.html and look for actual clickable class links
|
|
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));
|
|
}
|
|
|
|
// Find actual class links (not letter index links)
|
|
const classLinks = await page.evaluate(() => {
|
|
const links = Array.from(document.querySelectorAll('a'));
|
|
return links
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
|
.filter(l => l.href.includes('class') && l.href.endsWith('.html') && !l.href.includes('classes.html'))
|
|
.slice(0, 100);
|
|
});
|
|
|
|
console.log('Found actual class links:', classLinks.length);
|
|
classLinks.slice(0, 20).forEach(l => console.log(` - ${l.text}: ${l.href.split('/').pop()}`));
|
|
|
|
// Try to find Session class link
|
|
const sessionLink = classLinks.find(l => l.text.includes('Session') && !l.text.includes('SessionBuilder'));
|
|
console.log('\nSession link found:', sessionLink);
|
|
|
|
if (sessionLink) {
|
|
console.log('\n=== Navigating to Session class ===');
|
|
await page.goto(sessionLink.href, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const sessionPage = await page.evaluate(() => {
|
|
return {
|
|
title: document.title,
|
|
url: window.location.href,
|
|
hasError: document.body.innerText.includes('Access Denied') ||
|
|
document.body.innerText.includes('<Error>') ||
|
|
document.body.innerText.includes('AccessDenied'),
|
|
bodyText: document.body.innerText.substring(0, 3000)
|
|
};
|
|
});
|
|
|
|
console.log('Session page title:', sessionPage.title);
|
|
console.log('URL:', sessionPage.url);
|
|
console.log('Has error:', sessionPage.hasError);
|
|
console.log('\n--- Content ---');
|
|
console.log(sessionPage.bodyText);
|
|
|
|
await page.screenshot({ path: '/tmp/session-class.png' });
|
|
}
|
|
|
|
// If no session link directly, navigate to the NXOpen namespace and look there
|
|
if (!sessionLink || classLinks.length === 0) {
|
|
console.log('\n=== Trying NXOpen namespace page ===');
|
|
const nxopenUrl = baseUrl + 'namespaceNXOpen.html';
|
|
await page.goto(nxopenUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const nxopenPage = await page.evaluate(() => {
|
|
return {
|
|
title: document.title,
|
|
hasError: document.body.innerText.includes('Access Denied'),
|
|
bodyText: document.body.innerText.substring(0, 3000)
|
|
};
|
|
});
|
|
|
|
console.log('NXOpen namespace page:');
|
|
console.log('Title:', nxopenPage.title);
|
|
console.log('Has error:', nxopenPage.hasError);
|
|
console.log(nxopenPage.bodyText);
|
|
|
|
// Look for Session class link
|
|
const sessionInNs = await page.evaluate(() => {
|
|
const links = Array.from(document.querySelectorAll('a'));
|
|
return links
|
|
.filter(a => a.innerText.includes('Session'))
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
|
.slice(0, 10);
|
|
});
|
|
|
|
console.log('\nSession links in NXOpen namespace:', sessionInNs);
|
|
}
|
|
|
|
// Try the annotated page
|
|
console.log('\n=== Testing annotated.html ===');
|
|
const annotatedUrl = baseUrl + 'annotated.html';
|
|
await page.goto(annotatedUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const annotatedPage = await page.evaluate(() => {
|
|
return {
|
|
title: document.title,
|
|
hasError: document.body.innerText.includes('Access Denied'),
|
|
bodyText: document.body.innerText.substring(0, 2000),
|
|
links: Array.from(document.querySelectorAll('a'))
|
|
.filter(a => a.href.includes('class') && a.innerText.includes('Session'))
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
|
};
|
|
});
|
|
|
|
console.log('Annotated page title:', annotatedPage.title);
|
|
console.log('Has error:', annotatedPage.hasError);
|
|
console.log('Session links:', annotatedPage.links);
|
|
console.log('\nContent preview:');
|
|
console.log(annotatedPage.bodyText);
|
|
|
|
await auth.closeBrowser();
|
|
console.log('\n=== Test Complete ===');
|