139 lines
6.3 KiB
JavaScript
139 lines
6.3 KiB
JavaScript
const { chromium } = require('playwright');
|
|
|
|
(async () => {
|
|
console.log('🔍 Iniciando mapeamento de API para Axios...');
|
|
const browser = await chromium.launch({ headless: false }); // Usar Chrome visível para evitar bloqueio
|
|
const context = await browser.newContext({
|
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
|
|
});
|
|
const page = await context.newPage();
|
|
|
|
// Interceptar todas as requisições para descobrir os Endpoints
|
|
page.on('request', request => {
|
|
if (request.method() === 'POST' && !request.url().includes('google-analytics')) {
|
|
console.log(`\n🚀 POST Detectado: ${request.url()}`);
|
|
console.log('Headers:', JSON.stringify(request.headers(), null, 2));
|
|
console.log('Payload:', request.postData());
|
|
}
|
|
});
|
|
|
|
try {
|
|
await page.goto('https://viventerisportalcredenciado.topsaudehub.com.br/', { waitUntil: 'load', timeout: 60000 });
|
|
|
|
console.log('Esperando formulário de login...');
|
|
const userField = page.locator('#usuario, #Username').first();
|
|
await userField.waitFor({ timeout: 30000 });
|
|
|
|
console.log('Preenchendo credenciais...');
|
|
await userField.fill('0005010');
|
|
const passField = page.locator('#senha, #Password').first();
|
|
await passField.fill('Cclinic#03');
|
|
|
|
console.log('Clicando em Login...');
|
|
const loginBtn = page.locator('#login-submit, #btnLogin').first();
|
|
await loginBtn.click();
|
|
|
|
await page.waitForTimeout(5000);
|
|
|
|
console.log('Navegando pelo menu...');
|
|
await page.click('text="Tratamento Odontológico"');
|
|
await page.waitForTimeout(2000);
|
|
|
|
console.log('Abrindo busca de beneficiário...');
|
|
const searchBtn = page.locator('.fa-search, .glyphicon-search, button[title*="Pesquisar"]').first();
|
|
await searchBtn.click();
|
|
await page.waitForTimeout(2000);
|
|
|
|
console.log('Inserindo CPF...');
|
|
const cpfInput = page.locator('input[id*="cpf"], input[name*="cpf"], .cpf-mask').first();
|
|
await cpfInput.fill('005.983.051-49');
|
|
await page.click('button:has-text("Pesquisar"), #btnPesquisarBeneficiario');
|
|
|
|
console.log('Aguardando resultados da busca...');
|
|
const linkBeneficiario = page.locator('table tbody tr td a').first();
|
|
try {
|
|
await linkBeneficiario.waitFor({ state: 'visible', timeout: 15000 });
|
|
console.log('Selecionando beneficiário...');
|
|
await linkBeneficiario.click();
|
|
} catch (e) {
|
|
console.log('⚠️ Resultado da busca não apareceu ou demorou demais.');
|
|
const content = await page.content();
|
|
if (content.includes('nenhum registro encontrado') || content.includes('não encontrado')) {
|
|
console.log('❌ Beneficiário não encontrado no portal.');
|
|
} else {
|
|
console.log('Logando HTML para análise de erro...');
|
|
require('fs').writeFileSync('logs-and-data/debug-search-error.html', content);
|
|
}
|
|
throw new Error('Falha na busca de beneficiário durante o mapeamento.');
|
|
}
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('Clicando em Adicionar (+)...');
|
|
const btnMais = page.locator('.fa-plus, .btn-success, #btnNovoRegistro, button:has-text("+")').first();
|
|
await btnMais.click();
|
|
await page.waitForTimeout(5000);
|
|
|
|
console.log('Preenchendo dados da guia...');
|
|
const selectTipo = page.locator('select[id*="tipoAtendimento"]').first();
|
|
await selectTipo.waitFor({ state: 'visible', timeout: 15000 });
|
|
await selectTipo.selectOption('1');
|
|
await page.waitForTimeout(2000);
|
|
|
|
console.log('Buscando Profissional Executante...');
|
|
const btnBuscaProf = page.locator('#btnBuscaPrestadorExecutante').first();
|
|
await btnBuscaProf.click();
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('Selecionando primeiro profissional na tabela...');
|
|
const linkProf = page.locator('table tbody tr td a').first();
|
|
await linkProf.waitFor({ state: 'visible', timeout: 10000 });
|
|
await linkProf.click();
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('Verificando campo Solicitante...');
|
|
const solicitanteInput = page.locator('input[id*="solicitante"], input[name*="Solicitante"]').first();
|
|
|
|
// Tenta esperar o campo, mas loga se falhar
|
|
try {
|
|
await solicitanteInput.waitFor({ state: 'visible', timeout: 15000 });
|
|
console.log('Preenchendo Solicitante...');
|
|
await solicitanteInput.fill('Murilo');
|
|
} catch (e) {
|
|
console.log('⚠️ Campo Solicitante não apareceu. Continuando para tentar capturar outros POSTs...');
|
|
}
|
|
|
|
console.log('Avançando para procedimentos...');
|
|
const btnProx = page.locator('button:has-text("Próximo"), #btnProximo').first();
|
|
await btnProx.click();
|
|
await page.waitForTimeout(5000);
|
|
|
|
console.log('Abrindo inclusão de procedimento...');
|
|
await page.click('#adicionarProcedimeto');
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('Lançando procedimento para capturar JSON...');
|
|
await page.fill('#codProcedimento', '85100196');
|
|
await page.waitForTimeout(2000);
|
|
await page.click('.ui-menu-item-wrapper:has-text("85100196")');
|
|
await page.waitForTimeout(1000);
|
|
await page.selectOption('#cmbDente', '11');
|
|
await page.click('label[for="codFaceV"]');
|
|
|
|
console.log('Incluindo no modal (Captura JSON parcial)...');
|
|
await page.click('#btnIncluirProcedimento');
|
|
await page.waitForTimeout(3000);
|
|
|
|
console.log('FINALIZANDO GUIA (Captura do POST Final)...');
|
|
await page.click('button:has-text("Próximo")');
|
|
await page.waitForTimeout(2000);
|
|
await page.click('button:has-text("Próximo"), #btnFinalizar');
|
|
|
|
await page.waitForTimeout(10000);
|
|
console.log('\n✅ Mapeamento concluído com sucesso.');
|
|
} catch (error) {
|
|
console.error('Erro no mapeamento:', error);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
})();
|