Second Beta Version complete
Enhanced VZP checking
This commit is contained in:
		
							parent
							
								
									47c4afa99e
								
							
						
					
					
						commit
						1f5fcbe3c8
					
				| 
						 | 
					@ -1,10 +1,13 @@
 | 
				
			||||||
// Vars
 | 
					const isPromise = require("./ispromise")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]';
 | 
					const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]';
 | 
				
			||||||
const CELL_SELECTOR =
 | 
					const CELL_SELECTOR =
 | 
				
			||||||
    'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
 | 
					    'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
 | 
				
			||||||
const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]'
 | 
					const CELL_SELECTOR_OPEN = "a[title='Sectie samenvouwen Algemene opleidingsonderdelen']";
 | 
				
			||||||
const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]'
 | 
					const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]';
 | 
				
			||||||
const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]'
 | 
					const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]';
 | 
				
			||||||
 | 
					const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]';
 | 
				
			||||||
 | 
					const STPKT_KEUZE_CELL_SELECTOR_OPEN = 'a[title="Sectie samenvouwen Keuzeopleidingsonderdelen"]'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Extracted function to get the text content of a node.
 | 
					 * Extracted function to get the text content of a node.
 | 
				
			||||||
| 
						 | 
					@ -39,9 +42,23 @@ async function getContentFrame(page) {
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function isStartPakketAvailable(page) {
 | 
					async function isStartPakketAvailable(page) {
 | 
				
			||||||
  const contentFrame = await getContentFrame(page);
 | 
					  const contentFrame = await getContentFrame(page);
 | 
				
			||||||
  await contentFrame.waitForSelector(CELL_SELECTOR);
 | 
					  let cell
 | 
				
			||||||
  const cell = await contentFrame.$(CELL_SELECTOR);
 | 
					  let isCollapsed_main_before_function = true
 | 
				
			||||||
  const cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR)
 | 
					  try {
 | 
				
			||||||
 | 
					    await contentFrame.waitForSelector(CELL_SELECTOR, { timeout: 5000 }); // Adjust timeout as needed
 | 
				
			||||||
 | 
					    cell = await contentFrame.$(CELL_SELECTOR);
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.warn("CELL_SELECTOR not found, trying CELL_SELECTOR_OPEN");
 | 
				
			||||||
 | 
					    await contentFrame.waitForSelector(CELL_SELECTOR_OPEN, { timeout: 5000 }); // Adjust timeout as needed
 | 
				
			||||||
 | 
					    cell = await contentFrame.$(CELL_SELECTOR_OPEN);
 | 
				
			||||||
 | 
					    isCollapsed_main_before_function = false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR)
 | 
				
			||||||
 | 
					  if (!cell_keuze) {
 | 
				
			||||||
 | 
					    cell_keuze = contentFrame.$(STPKT_KEUZE_CELL_SELECTOR_OPEN)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!cell ) {
 | 
					  if (!cell ) {
 | 
				
			||||||
    throw new Error(
 | 
					    throw new Error(
 | 
				
			||||||
| 
						 | 
					@ -49,12 +66,15 @@ async function isStartPakketAvailable(page) {
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //object vars
 | 
					  //object vars
 | 
				
			||||||
  const isCollapsed_main = await isAriaExpandedFalse(cell);
 | 
					  const isCollapsed_main = isCollapsed_main_before_function ? await isAriaExpandedFalse(cell) : isCollapsed_main_before_function;
 | 
				
			||||||
  const isCollapsed_keuze = await getIsCollapsedKeuze(cell_keuze);
 | 
					  const isCollapsed_keuze = await getIsCollapsedKeuze(cell_keuze);
 | 
				
			||||||
  const isCollapsed = isCollapsed_main && isCollapsed_keuze;
 | 
					  const isCollapsed = isCollapsed_main && isCollapsed_keuze;
 | 
				
			||||||
  const studName = await getStudName(contentFrame);
 | 
					  const studName = await getStudName(contentFrame);
 | 
				
			||||||
  const studId = await getStudId(contentFrame);
 | 
					  const studId = await getStudId(contentFrame);
 | 
				
			||||||
 | 
					  const containsVZP = await hasVZP(cell)
 | 
				
			||||||
 | 
					  const containsVZP_keuze = await hasVZP(cell_keuze)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    isCollapsed: isCollapsed,
 | 
					    isCollapsed: isCollapsed,
 | 
				
			||||||
| 
						 | 
					@ -62,6 +82,8 @@ async function isStartPakketAvailable(page) {
 | 
				
			||||||
    isCollapsed_keuze: isCollapsed_keuze,
 | 
					    isCollapsed_keuze: isCollapsed_keuze,
 | 
				
			||||||
    studName: studName,
 | 
					    studName: studName,
 | 
				
			||||||
    studId: studId,
 | 
					    studId: studId,
 | 
				
			||||||
 | 
					    containsVZP: containsVZP,
 | 
				
			||||||
 | 
					    containsVZP_keuze: containsVZP_keuze,
 | 
				
			||||||
    // more properties here
 | 
					    // more properties here
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -73,7 +95,7 @@ async function isStartPakketAvailable(page) {
 | 
				
			||||||
 * @returns {Promise<boolean>} True if the `aria-expanded` attribute is 'false', false otherwise.
 | 
					 * @returns {Promise<boolean>} True if the `aria-expanded` attribute is 'false', false otherwise.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function isAriaExpandedFalse(node) {
 | 
					async function isAriaExpandedFalse(node) {
 | 
				
			||||||
  if (!node) {
 | 
					  if (isPromise(node)) {
 | 
				
			||||||
    throw new Error("Node is not defined");
 | 
					    throw new Error("Node is not defined");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return await node.evaluate(
 | 
					  return await node.evaluate(
 | 
				
			||||||
| 
						 | 
					@ -82,7 +104,7 @@ async function isAriaExpandedFalse(node) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getIsCollapsedKeuze(cell_keuze) {
 | 
					async function getIsCollapsedKeuze(cell_keuze) {
 | 
				
			||||||
  if (cell_keuze) {
 | 
					  if (!isPromise(cell_keuze)) {
 | 
				
			||||||
    return await isAriaExpandedFalse(cell_keuze);
 | 
					    return await isAriaExpandedFalse(cell_keuze);
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
| 
						 | 
					@ -105,4 +127,24 @@ async function getStudId(frame) {
 | 
				
			||||||
  return await getNodeTextContent(cell);
 | 
					  return await getNodeTextContent(cell);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Checks if the closest parent of the given node contains the 'VZP' string.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {ElementHandle} node - The node to find the closest parent of.
 | 
				
			||||||
 | 
					 * @returns {Promise<boolean>} True if the closest parent contains 'VZP', false otherwise.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					async function hasVZP(node) {
 | 
				
			||||||
 | 
					  if (isPromise(node) ){
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return await node.evaluate((element) => {
 | 
				
			||||||
 | 
					    let parent = element.closest('table');
 | 
				
			||||||
 | 
					    if (parent) {
 | 
				
			||||||
 | 
					      return parent.textContent.includes('VZP')
 | 
				
			||||||
 | 
					          ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = isStartPakketAvailable;
 | 
					module.exports = isStartPakketAvailable;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								ispromise.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								ispromise.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function isPromise(obj) {
 | 
				
			||||||
 | 
					    return obj && typeof obj.then === 'function';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = isPromise;
 | 
				
			||||||
| 
						 | 
					@ -18,8 +18,8 @@ async function iterateOverDashboardTable() {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //array to store results for Excel export
 | 
					  //array to store results for Excel export
 | 
				
			||||||
  let results = []
 | 
					  let results = [];
 | 
				
			||||||
  const filename = "DashboardResults.xlsx"
 | 
					  const filename = "DashboardResults.xlsx";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Get all open pages (tabs)
 | 
					  // Get all open pages (tabs)
 | 
				
			||||||
  const pages = await browser.pages();
 | 
					  const pages = await browser.pages();
 | 
				
			||||||
| 
						 | 
					@ -75,11 +75,23 @@ async function iterateOverDashboardTable() {
 | 
				
			||||||
    const links = await iframe.$$(
 | 
					    const links = await iframe.$$(
 | 
				
			||||||
      `${tableBodySelector} tr span[title="AA-rapport"] a`
 | 
					      `${tableBodySelector} tr span[title="AA-rapport"] a`
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					    // Get the parent row of the current link
 | 
				
			||||||
 | 
					    const parentRow = await links[i].evaluateHandle((link) =>
 | 
				
			||||||
 | 
					      link.closest("tr")
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    const rowContainsBeëindigd = await parentRow.evaluate((row) =>
 | 
				
			||||||
 | 
					      row.innerText.includes("Beëindigd")
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (rowContainsBeëindigd) {
 | 
				
			||||||
 | 
					      console.log(`Skipping link ${i + 1} as the row contains 'Beëindigd'`);
 | 
				
			||||||
 | 
					      continue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if ((i + 1) % 10 === 0) {
 | 
					    if ((i + 1) % 10 === 0) {
 | 
				
			||||||
      console.log('Simulating break, waiting 10 seconds to stay under the radar :)')
 | 
					      console.log(
 | 
				
			||||||
      await wait(10000)
 | 
					        "Simulating break, waiting 10 seconds to stay under the radar :)"
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      await wait(10000);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const [newPagePromise] = await Promise.all([
 | 
					    const [newPagePromise] = await Promise.all([
 | 
				
			||||||
| 
						 | 
					@ -99,30 +111,32 @@ async function iterateOverDashboardTable() {
 | 
				
			||||||
      const evaluationResult = await isStartPakketAvailable(newPage);
 | 
					      const evaluationResult = await isStartPakketAvailable(newPage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      //Save results for Excel
 | 
					      //Save results for Excel
 | 
				
			||||||
      result = ({
 | 
					      result = {
 | 
				
			||||||
        LinkNumber: i + 1,
 | 
					        LinkNumber: i + 1,
 | 
				
			||||||
        StudentName: evaluationResult.studName || 'N/A',
 | 
					        StudentName: evaluationResult.studName || "N/A",
 | 
				
			||||||
        StudentID: evaluationResult.studId || "N/A",
 | 
					        StudentID: evaluationResult.studId || "N/A",
 | 
				
			||||||
        IsCollapsed: evaluationResult.isCollapsed ? "Yes" : "No",
 | 
					        IsCollapsed: evaluationResult.isCollapsed ? "Yes" : "No",
 | 
				
			||||||
        IsCollapsedKeuze: evaluationResult.isCollapsed_keuze ? "Yes" : "No",
 | 
					        IsCollapsedKeuze: evaluationResult.isCollapsed_keuze ? "Yes" : "No",
 | 
				
			||||||
        IsCollapsedMain: evaluationResult.isCollapsed_main ? "Yes" : "No",
 | 
					        IsCollapsedMain: evaluationResult.isCollapsed_main ? "Yes" : "No",
 | 
				
			||||||
      })
 | 
					        ContainsVZP: evaluationResult.containsVZP ? "Yes" : "No",
 | 
				
			||||||
 | 
					        ContainsVZPKeuze: evaluationResult.containsVZP_keuze ? "Yes" : "No"
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
      console.log(`Link ${i + 1} processed successfully.`);
 | 
					      console.log(`Link ${i + 1} processed successfully.`);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    } catch (error) {
 | 
					    } catch (error) {
 | 
				
			||||||
      console.error(`Error processing link ${i + 1}:`, error.message);
 | 
					      console.error(`Error processing link ${i + 1}:`, error.message);
 | 
				
			||||||
      // Save error for Excel
 | 
					      // Save error for Excel
 | 
				
			||||||
      result = ({
 | 
					      result = {
 | 
				
			||||||
        LinkNumber: i + 1,
 | 
					        LinkNumber: i + 1,
 | 
				
			||||||
        StudentName: "Error",
 | 
					        StudentName: "Error",
 | 
				
			||||||
        StudentID: "Error",
 | 
					        StudentID: "Error",
 | 
				
			||||||
        IsCollapsed: "Error",
 | 
					        IsCollapsed: "Error",
 | 
				
			||||||
        IsCollapsedKeuze: "Error",
 | 
					        IsCollapsedKeuze: "Error",
 | 
				
			||||||
        IsCollapsedMain: "Error",
 | 
					        IsCollapsedMain: "Error",
 | 
				
			||||||
 | 
					        ContainsVZP: "Error",
 | 
				
			||||||
 | 
					        ContainsVZPKeuze: "Error",
 | 
				
			||||||
        ErrorStr: error.message,
 | 
					        ErrorStr: error.message,
 | 
				
			||||||
      });
 | 
					      };
 | 
				
			||||||
    }
 | 
					    } finally {
 | 
				
			||||||
    finally {
 | 
					 | 
				
			||||||
      await newPage.close();
 | 
					      await newPage.close();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    results.push(result);
 | 
					    results.push(result);
 | 
				
			||||||
| 
						 | 
					@ -132,8 +146,6 @@ async function iterateOverDashboardTable() {
 | 
				
			||||||
  console.log("All links processed.");
 | 
					  console.log("All links processed.");
 | 
				
			||||||
  saveResultsToExcel(results, "DashboardResults.xlsx");
 | 
					  saveResultsToExcel(results, "DashboardResults.xlsx");
 | 
				
			||||||
  console.log("Results saved successfully to DashboardResults.xlsx");
 | 
					  console.log("Results saved successfully to DashboardResults.xlsx");
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports = iterateOverDashboardTable();
 | 
					module.exports = iterateOverDashboardTable();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user