111 lines
4.2 KiB
JavaScript
111 lines
4.2 KiB
JavaScript
|
|
import auth from '../tools/siemens-auth.js';
|
||
|
|
|
||
|
|
console.log('=== Testing NX Open Class Documentation Access ===\n');
|
||
|
|
|
||
|
|
const browser = await auth.getBrowser();
|
||
|
|
const page = await browser.newPage();
|
||
|
|
await page.setViewport({ width: 1400, height: 900 });
|
||
|
|
await auth.loadCookies(page);
|
||
|
|
|
||
|
|
// Navigate to the hierarchy page (which we know works)
|
||
|
|
const hierarchyUrl = '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/a00006.html';
|
||
|
|
console.log('Loading hierarchy page:', hierarchyUrl);
|
||
|
|
await page.goto(hierarchyUrl, { 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));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Get the page title and content
|
||
|
|
const pageInfo = await page.evaluate(() => {
|
||
|
|
return {
|
||
|
|
title: document.title,
|
||
|
|
h1: document.querySelector('h1')?.innerText || 'No H1',
|
||
|
|
bodyText: document.body.innerText.substring(0, 1500)
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\nPage Title:', pageInfo.title);
|
||
|
|
console.log('H1:', pageInfo.h1);
|
||
|
|
console.log('\nPage content preview:');
|
||
|
|
console.log(pageInfo.bodyText);
|
||
|
|
|
||
|
|
// Find all class links on the hierarchy page
|
||
|
|
const classLinks = await page.evaluate(() => {
|
||
|
|
const links = Array.from(document.querySelectorAll('a'));
|
||
|
|
return links
|
||
|
|
.filter(a => a.href && a.href.includes('class') && a.innerText)
|
||
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href }))
|
||
|
|
.filter(l => l.text.length > 0 && l.text.length < 100)
|
||
|
|
.slice(0, 20);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\n=== Found class links:', classLinks.length);
|
||
|
|
classLinks.forEach(l => console.log(` - ${l.text}: ${l.href.split('/').pop()}`));
|
||
|
|
|
||
|
|
// Try clicking on a class link (NXOpen.Session if available)
|
||
|
|
const sessionLink = classLinks.find(l => l.text.includes('Session') || l.text.includes('NXOpen'));
|
||
|
|
if (sessionLink) {
|
||
|
|
console.log('\n=== Testing click on:', sessionLink.text);
|
||
|
|
|
||
|
|
// Click the link
|
||
|
|
await page.evaluate((href) => {
|
||
|
|
const link = document.querySelector(`a[href="${href}"]`) ||
|
||
|
|
Array.from(document.querySelectorAll('a')).find(a => a.href === href);
|
||
|
|
if (link) link.click();
|
||
|
|
}, sessionLink.href);
|
||
|
|
|
||
|
|
await new Promise(r => setTimeout(r, 5000));
|
||
|
|
|
||
|
|
// Check the new page
|
||
|
|
const classPageInfo = await page.evaluate(() => {
|
||
|
|
return {
|
||
|
|
url: window.location.href,
|
||
|
|
title: document.title,
|
||
|
|
h1: document.querySelector('h1')?.innerText || 'No H1',
|
||
|
|
hasContent: document.body.innerText.length > 500,
|
||
|
|
bodyPreview: document.body.innerText.substring(0, 1000)
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\nClass page URL:', classPageInfo.url);
|
||
|
|
console.log('Class page title:', classPageInfo.title);
|
||
|
|
console.log('Class page H1:', classPageInfo.h1);
|
||
|
|
console.log('Has substantial content:', classPageInfo.hasContent);
|
||
|
|
console.log('\nContent preview:');
|
||
|
|
console.log(classPageInfo.bodyPreview);
|
||
|
|
|
||
|
|
await page.screenshot({ path: '/tmp/class-page.png' });
|
||
|
|
console.log('\nScreenshot saved to /tmp/class-page.png');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Test direct navigation to a known class URL via the iframe
|
||
|
|
console.log('\n=== Testing direct class URL within iframe context ===');
|
||
|
|
const sessionClassUrl = '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/classNXOpen_1_1Session.html';
|
||
|
|
await page.goto(sessionClassUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
||
|
|
await new Promise(r => setTimeout(r, 3000));
|
||
|
|
|
||
|
|
const directAccessInfo = await page.evaluate(() => {
|
||
|
|
return {
|
||
|
|
url: window.location.href,
|
||
|
|
title: document.title,
|
||
|
|
bodyText: document.body.innerText.substring(0, 1500),
|
||
|
|
hasError: document.body.innerText.includes('Access Denied') || document.body.innerText.includes('Error')
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\nDirect URL access result:');
|
||
|
|
console.log('Title:', directAccessInfo.title);
|
||
|
|
console.log('Has error:', directAccessInfo.hasError);
|
||
|
|
console.log('Content:', directAccessInfo.bodyText);
|
||
|
|
|
||
|
|
await auth.closeBrowser();
|
||
|
|
console.log('\n=== Test Complete ===');
|