fix(core): Fix concurrency and download handling in HandelsRegister class and adjust test cases
This commit is contained in:
@ -113,13 +113,13 @@ export class HandelsRegister {
|
||||
return businessRecords;
|
||||
};
|
||||
|
||||
private clickFindButton = async (pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page) => {
|
||||
private clickFindButton = async (pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page, resultsLimitArg: number = 100) => {
|
||||
try {
|
||||
// Wait for the button with the text "Find" to appear
|
||||
await pageArg.waitForSelector('span.ui-button-text.ui-c', { timeout: 5000 });
|
||||
|
||||
// adjust to 100 results per page
|
||||
await pageArg.select('#form\\:ergebnisseProSeite_input', '100');
|
||||
await pageArg.select('#form\\:ergebnisseProSeite_input', `${resultsLimitArg}`);
|
||||
|
||||
// Locate and click the button using its text
|
||||
await pageArg.evaluate(() => {
|
||||
@ -183,14 +183,24 @@ export class HandelsRegister {
|
||||
}
|
||||
}, typeArg);
|
||||
|
||||
// Wait a bit for the download to complete (you might want to implement
|
||||
// a more robust file-exists check or a wait-for-download library)
|
||||
await pageArg.waitForTimeout(10000);
|
||||
|
||||
await plugins.smartfile.fs.waitForFileToBeReady(this.uniqueDowloadFolder);
|
||||
|
||||
const files = await plugins.smartfile.fs.fileTreeToObject(this.uniqueDowloadFolder, '**/*');
|
||||
await plugins.smartfile.fs.ensureEmptyDir(this.uniqueDowloadFolder);
|
||||
const file = files[0];
|
||||
|
||||
return files [0];
|
||||
// lets clear the folder for the next download
|
||||
await plugins.smartfile.fs.ensureEmptyDir(this.uniqueDowloadFolder);
|
||||
switch (typeArg) {
|
||||
case 'AD':
|
||||
await file.rename(`ad.pdf`);
|
||||
break;
|
||||
case 'SI':
|
||||
await file.rename(`si.xml`);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +226,7 @@ export class HandelsRegister {
|
||||
/**
|
||||
* Search for a company by name and return basic info
|
||||
*/
|
||||
public async searchCompany(companyNameArg: string) {
|
||||
public async searchCompany(companyNameArg: string, resultsLimitArg: number = 100) {
|
||||
return this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||
const page = await this.getNewPage();
|
||||
await this.navigateToPage(page, 'Normal search');
|
||||
@ -261,7 +271,7 @@ export class HandelsRegister {
|
||||
console.error('Failed to find or click the radio button:', error);
|
||||
}
|
||||
|
||||
await this.clickFindButton(page);
|
||||
await this.clickFindButton(page, resultsLimitArg);
|
||||
|
||||
const businessRecords = await this.waitForResults(page);
|
||||
|
||||
@ -336,4 +346,13 @@ export class HandelsRegister {
|
||||
};
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
/**
|
||||
* get specific company by full name
|
||||
*/
|
||||
public async getSpecificCompanyByName(companyNameArg: string) {
|
||||
const businessRecords = await this.searchCompany(companyNameArg, 1);
|
||||
const result = this.getSpecificCompany(businessRecords[0].germanParsedRegistration);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user