Files
SERVtomaste/temp/test-classes4.js

167 lines
5.7 KiB
JavaScript

import auth from '../tools/siemens-auth.js';
console.log('=== Testing NX Open Class List Navigation ===\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 annotated.html (Class List)
const annotatedUrl = baseUrl + 'annotated.html';
console.log('Loading:', annotatedUrl);
await page.goto(annotatedUrl, { 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));
}
// Try to expand the tree view by clicking on detail level indicators
console.log('\n=== Expanding tree view ===');
// Look for expand arrows or [+] buttons
const expandButtons = await page.evaluate(() => {
// Look for various expand mechanisms
const results = {
arrows: [],
plusSigns: [],
togglers: []
};
// Doxygen typically uses arrow images or [+] text
const imgs = Array.from(document.querySelectorAll('img'));
imgs.forEach(img => {
if (img.alt && (img.alt.includes('arrow') || img.alt.includes('expand'))) {
results.arrows.push({ src: img.src, alt: img.alt });
}
});
// Look for tree toggle elements
const spans = Array.from(document.querySelectorAll('span'));
spans.forEach(s => {
if (s.className && (s.className.includes('arrow') || s.className.includes('toggle'))) {
results.togglers.push(s.className);
}
});
// Look for any clickable elements near NXOpen
const allElements = Array.from(document.querySelectorAll('*'));
const nxopenElements = allElements.filter(e =>
e.innerText && e.innerText.includes('NXOpen') && e.innerText.length < 50
);
return {
...results,
nxopenElements: nxopenElements.map(e => ({
tag: e.tagName,
text: e.innerText.trim(),
className: e.className
})),
html: document.body.innerHTML.substring(0, 5000)
};
});
console.log('Expand buttons found:', expandButtons.arrows.length, 'arrows,', expandButtons.togglers.length, 'togglers');
console.log('NXOpen elements:', expandButtons.nxopenElements);
// Try clicking on the NXOpen row to expand it
const clickResult = await page.evaluate(() => {
// Look for expandable row
const rows = Array.from(document.querySelectorAll('tr'));
for (const row of rows) {
if (row.innerText && row.innerText.includes('NXOpen')) {
// Find the arrow/expand control in this row
const arrow = row.querySelector('span.arrow') || row.querySelector('img') || row.querySelector('[onclick]');
if (arrow) {
arrow.click();
return 'Clicked arrow in NXOpen row';
}
// Try clicking the row itself
row.click();
return 'Clicked NXOpen row';
}
}
// Try the detail level links
const links = Array.from(document.querySelectorAll('a'));
const detailLink = links.find(a => a.innerText && a.innerText.includes('3'));
if (detailLink) {
detailLink.click();
return 'Clicked detail level 3';
}
return 'No expandable element found';
});
console.log('Click result:', clickResult);
await new Promise(r => setTimeout(r, 2000));
// Get current state
const pageContent = await page.evaluate(() => {
return {
title: document.title,
text: document.body.innerText.substring(0, 4000),
allLinks: Array.from(document.querySelectorAll('a'))
.filter(a => a.href && a.href.includes('.html'))
.map(a => ({ text: a.innerText.trim().substring(0, 50), href: a.href.split('/').pop() }))
.slice(0, 50)
};
});
console.log('\n=== Page content after click ===');
console.log(pageContent.text);
console.log('\n=== Links found ===');
pageContent.allLinks.forEach(l => console.log(` - ${l.text}: ${l.href}`));
// Try the search functionality
console.log('\n=== Testing search functionality ===');
const searchUrl = baseUrl + 'search.html';
await page.goto(searchUrl, { waitUntil: 'networkidle2', timeout: 60000 });
await new Promise(r => setTimeout(r, 2000));
const searchPage = await page.evaluate(() => {
return {
title: document.title,
hasError: document.body.innerText.includes('Access Denied'),
hasSearchBox: !!document.querySelector('input[type="search"]') || !!document.querySelector('#MSearchBox'),
content: document.body.innerText.substring(0, 1000)
};
});
console.log('Search page title:', searchPage.title);
console.log('Has error:', searchPage.hasError);
console.log('Has search box:', searchPage.hasSearchBox);
console.log('Content:', searchPage.content);
// Try to access functions list
console.log('\n=== Testing functions list ===');
const functionsUrl = baseUrl + 'functions.html';
await page.goto(functionsUrl, { waitUntil: 'networkidle2', timeout: 60000 });
await new Promise(r => setTimeout(r, 2000));
const functionsPage = await page.evaluate(() => {
return {
title: document.title,
hasError: document.body.innerText.includes('Access Denied'),
content: document.body.innerText.substring(0, 2000)
};
});
console.log('Functions page title:', functionsPage.title);
console.log('Has error:', functionsPage.hasError);
console.log('Content preview:', functionsPage.content.substring(0, 500));
await page.screenshot({ path: '/tmp/functions-page.png' });
await auth.closeBrowser();
console.log('\n=== Test Complete ===');