Files
SERVtomaste/temp/test-find-session.js

171 lines
5.9 KiB
JavaScript

import auth from '../tools/siemens-auth.js';
console.log('=== Finding NXOpen.Session Class Page ===\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 hierarchy.html and look for Session
console.log('Loading hierarchy.html...');
await page.goto(baseUrl + 'hierarchy.html', { 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 Session links in hierarchy
const hierarchyLinks = await page.evaluate(() => {
const links = Array.from(document.querySelectorAll('a'));
return links
.filter(a => a.innerText && a.innerText.trim() === 'Session')
.map(a => ({ text: a.innerText.trim(), href: a.href, file: a.href.split('/').pop() }));
});
console.log('Session links in hierarchy:', hierarchyLinks);
// Try each Session link to find the NXOpen.Session class
for (const link of hierarchyLinks.slice(0, 3)) {
console.log(`\n=== Trying: ${link.file} ===`);
await page.goto(link.href, { waitUntil: 'networkidle2', timeout: 60000 });
await new Promise(r => setTimeout(r, 3000));
const pageContent = await page.evaluate(() => {
return {
title: document.title,
hasError: document.body.innerText.includes('Access Denied'),
firstLines: document.body.innerText.substring(0, 500)
};
});
console.log('Title:', pageContent.title);
console.log('Has error:', pageContent.hasError);
console.log('Content preview:', pageContent.firstLines);
if (!pageContent.hasError && pageContent.title.includes('Session')) {
// Found a working Session page!
console.log('\n=== FOUND WORKING SESSION PAGE! ===');
// Get full content
const fullContent = await page.evaluate(() => {
return {
title: document.title,
content: document.body.innerText.substring(0, 5000)
};
});
console.log(fullContent.content);
await page.screenshot({ path: '/tmp/nxopen-session.png' });
break;
}
}
// Also try directly searching in class index page for Session (NXOpen)
console.log('\n=== Looking for Session (NXOpen) specifically ===');
await page.goto(baseUrl + 'classes.html', { waitUntil: 'networkidle2', timeout: 60000 });
await new Promise(r => setTimeout(r, 3000));
// Get all text and find Session (NXOpen)
const classIndexSearch = await page.evaluate(() => {
const text = document.body.innerText;
// Look for Session followed by (NXOpen) or Session(NXOpen)
const sessionIdx = text.indexOf('Session (NXOpen)');
if (sessionIdx > -1) {
// Get surrounding context
return {
found: true,
context: text.substring(Math.max(0, sessionIdx - 100), sessionIdx + 200)
};
}
return { found: false };
});
console.log('Session (NXOpen) in class index:', classIndexSearch);
// Find the link for Session class under NXOpen namespace
const sessionNXOpenLink = await page.evaluate(() => {
// Get all links
const links = Array.from(document.querySelectorAll('a'));
// Find links that have "Session" text
const sessionLinks = links
.filter(a => a.innerText && a.innerText.trim() === 'Session')
.map(a => {
// Get parent context to identify namespace
let parentText = a.parentElement?.innerText || '';
return {
text: a.innerText.trim(),
href: a.href,
file: a.href.split('/').pop(),
parentContext: parentText.substring(0, 100)
};
});
return sessionLinks;
});
console.log('\nSession links with context:', sessionNXOpenLink);
// Try the NXOpen namespace directly to find Session class
console.log('\n=== Trying NXOpen namespace from annotated.html ===');
await page.goto(baseUrl + 'annotated.html', { waitUntil: 'networkidle2', timeout: 60000 });
await new Promise(r => setTimeout(r, 3000));
// Expand NXOpen namespace and look for Session
const annotatedSessionLinks = await page.evaluate(() => {
const links = Array.from(document.querySelectorAll('a.el'));
return links
.filter(a => a.innerText && a.innerText.includes('Session'))
.map(a => ({ text: a.innerText.trim(), href: a.href.split('/').pop() }))
.filter(l => !l.text.includes('.') || l.text.startsWith('NXOpen.Session'))
.slice(0, 20);
});
console.log('Session links from annotated:', annotatedSessionLinks);
// Try the pattern a***.html to find Session directly
// Let's try a55186 (common pattern for main classes)
const testUrls = [
'a55186.html', // Possible Session
'a55188.html',
'a55190.html',
'a55180.html'
];
for (const testUrl of testUrls) {
console.log(`\nTrying ${testUrl}...`);
await page.goto(baseUrl + testUrl, { waitUntil: 'networkidle2', timeout: 30000 });
await new Promise(r => setTimeout(r, 2000));
const testResult = await page.evaluate(() => {
return {
title: document.title,
hasError: document.body.innerText.includes('Access Denied'),
isSession: document.title.includes('Session') && document.title.includes('NXOpen')
};
});
console.log(`${testUrl}: ${testResult.title} (error: ${testResult.hasError})`);
if (!testResult.hasError && testResult.isSession) {
console.log('\n=== FOUND NXOPEN.SESSION! ===');
const content = await page.evaluate(() => document.body.innerText.substring(0, 4000));
console.log(content);
await page.screenshot({ path: '/tmp/nxopen-session-found.png' });
break;
}
}
await auth.closeBrowser();
console.log('\n=== Test Complete ===');