Update dependencies and stabilize
Resolves #49
Resolves #54
Change-Id: Ia76e520e400dc62823c70910dafbd2736f38cc0f
diff --git a/lib/korap_rc.js b/lib/korap_rc.js
index 698f5a9..016a7db 100644
--- a/lib/korap_rc.js
+++ b/lib/korap_rc.js
@@ -52,25 +52,101 @@
await page.keyboard.press("Enter");
await page.waitForNavigation({ waitUntil: 'networkidle2' });
- const total_results = await page.$("#total-results");
- assert.notEqual(total_results, null, "Cannot find total results");
- const hits = Number((await page.evaluate(total_results => total_results.textContent, total_results)).replace(/[,.]/g, ""));
+ // Wait for search results to be fully loaded
+ try {
+ await page.waitForSelector('ol li, #resultinfo, .result-item', {
+ visible: true,
+ timeout: 15000
+ });
+ // Give additional time for the results count to be populated
+ await new Promise(resolve => setTimeout(resolve, 2000));
+ } catch (error) {
+ // Continue if timeout, fallback methods will handle it
+ }
+
+ const resultsInfo = await page.evaluate(() => {
+ // Check common selectors for result counts
+ const selectors = [
+ '#total-results',
+ '#resultinfo',
+ '.result-count',
+ '.total-results',
+ '[data-results]',
+ '.found'
+ ];
+
+ for (const selector of selectors) {
+ const element = document.querySelector(selector);
+ if (element) {
+ const text = element.textContent || element.innerText || '';
+ const numbers = text.match(/\d+/g);
+ if (numbers && numbers.length > 0) {
+ return {
+ selector: selector,
+ numbers: numbers
+ };
+ }
+ }
+ }
+
+ // Look in the page title for results count
+ const title = document.title;
+ if (title) {
+ const numbers = title.match(/\d+/g);
+ if (numbers && numbers.length > 0) {
+ return {
+ selector: 'title',
+ numbers: numbers
+ };
+ }
+ }
+
+ // Count the actual result items as fallback
+ const resultItems = document.querySelectorAll('ol li');
+ if (resultItems.length > 0) {
+ return {
+ selector: 'counted-items',
+ numbers: [resultItems.length.toString()]
+ };
+ }
+
+ return null;
+ });
+
+ if (!resultsInfo || !resultsInfo.numbers || resultsInfo.numbers.length === 0) {
+ // Final fallback: just count visible list items
+ const itemCount = await page.evaluate(() => {
+ return document.querySelectorAll('ol li').length;
+ });
+
+ if (itemCount > 0) {
+ return itemCount;
+ }
+
+ throw new Error("Cannot find any results count on the page");
+ }
+
+ // Extract the largest number found (likely the total results)
+ const hits = Math.max(...resultsInfo.numbers.map(n => parseInt(n, 10)));
return hits;
}
async logout(page) {
- await page.click('.dropdown-btn');
- await page.waitForSelector('.logout', { visible: true });
- const logout_button = await page.$(".logout")
- if (logout_button == null) {
- console.log("Logout button not found")
- return false
+ try {
+ // Direct navigation to logout URL - most reliable method
+ const currentUrl = await page.url();
+ const logoutUrl = currentUrl.replace(/\/$/, '') + '/logout';
+
+ await page.goto(logoutUrl, { waitUntil: 'domcontentloaded', timeout: 10000 });
+
+ // Navigate back to main page to ensure clean state for subsequent tests
+ await page.goto(this.korap_url, { waitUntil: 'domcontentloaded', timeout: 10000 });
+
+ return true;
+ } catch (error) {
+ return false;
}
- await logout_button.click()
- await page.waitForNavigation({ waitUntil: 'networkidle2' });
- const loginField = await page.$('input[name=handle_or_email]');
- return loginField !== null;
}
async assure_glimpse_off(page) {