87 lines
3.1 KiB
JavaScript
87 lines
3.1 KiB
JavaScript
|
|
import auth from '../tools/siemens-auth.js';
|
||
|
|
|
||
|
|
console.log('=== Accessing NXOpen.Session Class (a03318.html) ===\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 NXOpen.Session class page
|
||
|
|
const sessionUrl = baseUrl + 'a03318.html';
|
||
|
|
console.log('Loading:', sessionUrl);
|
||
|
|
await page.goto(sessionUrl, { 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));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Get page content
|
||
|
|
const sessionContent = await page.evaluate(() => {
|
||
|
|
return {
|
||
|
|
title: document.title,
|
||
|
|
url: window.location.href,
|
||
|
|
hasError: document.body.innerText.includes('Access Denied'),
|
||
|
|
fullText: document.body.innerText
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('Title:', sessionContent.title);
|
||
|
|
console.log('URL:', sessionContent.url);
|
||
|
|
console.log('Has error:', sessionContent.hasError);
|
||
|
|
|
||
|
|
if (!sessionContent.hasError) {
|
||
|
|
console.log('\n=== SUCCESS! NXOpen.Session class documentation ===\n');
|
||
|
|
console.log(sessionContent.fullText.substring(0, 8000));
|
||
|
|
await page.screenshot({ path: '/tmp/nxopen-session-success.png' });
|
||
|
|
|
||
|
|
// Also test another important class - Part
|
||
|
|
console.log('\n\n=== Now testing NXOpen.Part class ===');
|
||
|
|
|
||
|
|
// First find Part class page ID
|
||
|
|
await page.goto(baseUrl + 'classes.html', { waitUntil: 'networkidle2', timeout: 60000 });
|
||
|
|
await new Promise(r => setTimeout(r, 2000));
|
||
|
|
|
||
|
|
const partLink = await page.evaluate(() => {
|
||
|
|
const links = Array.from(document.querySelectorAll('a'));
|
||
|
|
const partLinks = links
|
||
|
|
.filter(a => a.innerText && a.innerText.trim() === 'Part')
|
||
|
|
.map(a => ({ text: a.innerText.trim(), href: a.href, parent: a.parentElement?.innerText?.substring(0, 50) || '' }));
|
||
|
|
return partLinks.find(l => l.parent.includes('NXOpen')) || partLinks[0];
|
||
|
|
});
|
||
|
|
|
||
|
|
if (partLink) {
|
||
|
|
console.log('Found Part link:', partLink);
|
||
|
|
await page.goto(partLink.href, { waitUntil: 'networkidle2', timeout: 60000 });
|
||
|
|
await new Promise(r => setTimeout(r, 3000));
|
||
|
|
|
||
|
|
const partContent = await page.evaluate(() => {
|
||
|
|
return {
|
||
|
|
title: document.title,
|
||
|
|
hasError: document.body.innerText.includes('Access Denied'),
|
||
|
|
content: document.body.innerText.substring(0, 3000)
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('Part class title:', partContent.title);
|
||
|
|
console.log('Has error:', partContent.hasError);
|
||
|
|
console.log('\nPart class content preview:');
|
||
|
|
console.log(partContent.content);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
console.log('\n=== ERROR: Could not access Session class ===');
|
||
|
|
console.log(sessionContent.fullText);
|
||
|
|
}
|
||
|
|
|
||
|
|
await auth.closeBrowser();
|
||
|
|
console.log('\n=== Test Complete ===');
|