130 lines
4.9 KiB
JavaScript
130 lines
4.9 KiB
JavaScript
import auth from '../tools/siemens-auth.js';
|
|
|
|
console.log('=== Testing NX Open - Accessing Actual Class Pages ===\n');
|
|
|
|
const browser = await auth.getBrowser();
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: 1400, height: 900 });
|
|
await auth.loadCookies(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 functions.html which we know works
|
|
const functionsUrl = baseUrl + 'functions.html';
|
|
console.log('Loading:', functionsUrl);
|
|
await page.goto(functionsUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
// Handle cookie popup
|
|
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 links to actual class pages
|
|
const classLinks = await page.evaluate(() => {
|
|
const links = Array.from(document.querySelectorAll('a'));
|
|
return links
|
|
.filter(a => a.href && (a.href.includes('classNXOpen') || a.href.includes('class_n_x_open')))
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
|
.filter(l => l.text.length > 0 && l.text.length < 80)
|
|
.slice(0, 30);
|
|
});
|
|
|
|
console.log('Class links found:', classLinks.length);
|
|
classLinks.forEach(l => console.log(` - ${l.text}: ${l.href.split('/').pop()}`));
|
|
|
|
// Find Session class link
|
|
const sessionLink = classLinks.find(l =>
|
|
l.text.includes('Session') && !l.text.includes('SessionCollection') && !l.text.includes('SessionBuilder')
|
|
);
|
|
|
|
// Or try any class link if Session not found
|
|
const targetLink = sessionLink || classLinks[0];
|
|
|
|
if (targetLink) {
|
|
console.log('\n=== Navigating to:', targetLink.text, '===');
|
|
console.log('URL:', targetLink.href);
|
|
|
|
await page.goto(targetLink.href, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const classPage = 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, 4000)
|
|
};
|
|
});
|
|
|
|
console.log('\nClass page result:');
|
|
console.log('Title:', classPage.title);
|
|
console.log('URL:', classPage.url);
|
|
console.log('Has error:', classPage.hasError);
|
|
console.log('\n--- Content ---');
|
|
console.log(classPage.bodyText);
|
|
|
|
await page.screenshot({ path: '/tmp/class-access.png' });
|
|
}
|
|
|
|
// Let's also test the class list functions_s.html to find Session directly
|
|
console.log('\n=== Testing functions_s.html (looking for Session) ===');
|
|
const functionsSUrl = baseUrl + 'functions_s.html';
|
|
await page.goto(functionsSUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const sessionContent = await page.evaluate(() => {
|
|
const text = document.body.innerText;
|
|
const sessionLines = text.split('\n').filter(l => l.includes('Session'));
|
|
return {
|
|
hasError: text.includes('Access Denied'),
|
|
sessionLines: sessionLines.slice(0, 20),
|
|
sessionLinks: Array.from(document.querySelectorAll('a'))
|
|
.filter(a => a.innerText && a.innerText.includes('Session') && a.href)
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
|
.slice(0, 10)
|
|
};
|
|
});
|
|
|
|
console.log('Has error:', sessionContent.hasError);
|
|
console.log('Session-related lines:');
|
|
sessionContent.sessionLines.forEach(l => console.log(` ${l.substring(0, 100)}`));
|
|
console.log('\nSession links:');
|
|
sessionContent.sessionLinks.forEach(l => console.log(` - ${l.text}: ${l.href.split('/').pop()}`));
|
|
|
|
// Try to click on a Session link if found
|
|
if (sessionContent.sessionLinks.length > 0) {
|
|
const sessionClassLink = sessionContent.sessionLinks.find(l =>
|
|
l.href.includes('Session') && !l.text.includes('Builder')
|
|
) || sessionContent.sessionLinks[0];
|
|
|
|
console.log('\n=== Clicking on Session link:', sessionClassLink.text, '===');
|
|
await page.goto(sessionClassLink.href, { waitUntil: 'networkidle2', timeout: 60000 });
|
|
await new Promise(r => setTimeout(r, 3000));
|
|
|
|
const sessionPage = await page.evaluate(() => {
|
|
return {
|
|
title: document.title,
|
|
hasError: document.body.innerText.includes('Access Denied'),
|
|
content: document.body.innerText.substring(0, 3000)
|
|
};
|
|
});
|
|
|
|
console.log('Title:', sessionPage.title);
|
|
console.log('Has error:', sessionPage.hasError);
|
|
console.log('\n--- Session class content ---');
|
|
console.log(sessionPage.content);
|
|
|
|
await page.screenshot({ path: '/tmp/session-page.png' });
|
|
}
|
|
|
|
await auth.closeBrowser();
|
|
console.log('\n=== Test Complete ===');
|