Они также изменяют свой класс (
Код: Выделить всё
toast-infoКод: Выделить всё
[i][/i]
Nota Lesión Activa: Lesiones 364
[i][/i]
Error
Paciente no encontrado
Иногда мой тест не удается с тайм -аутом при попытке получить заголовок тоста:
Код: Выделить всё
Get text content(
page.locator('#toast-container .toast').first().locator('.toast-title')
)
— 30.0s
waiting for locator('#toast-container .toast').first().locator('.toast-title')
Timeout 30000ms exceeded.
Я создал две функции: одна (ботрон), которая нажимает кнопку и проверяет тосты, а другая (capturaerror), которые извлекает тост и тост.
Код: Выделить всё
async function boton(page, Accion, indice = 0) {
await page.getByRole('button', { name: Accion }).nth(indice).click({ timeout: 1000 });
const toasts = page.locator('#toast-container .toast, #toast-container .toast-error, #toast-container .toast-warning');
const count = await toasts.count();
const mensajes = [];
for (let i = 0; i < count; i++) {
const toast = toasts.nth(i);
const clase = await toast.getAttribute('class') || '';
const mensaje = await toast.locator('.toast-message').textContent().catch(() => '');
if (clase.includes('toast-error')) {
if (mensaje && mensaje.trim() !== '') {
mensajes.push(`${i + 1}.- ${mensaje.trim()}`);
}
} else if (clase.includes('toast-warning')) {
const msj = await Capturaerror(page);
if (msj && msj.length > 0) {
throw new Error(`${msj.join('\n')}`);
}
}
}
if (mensajes.length > 0) {
throw new Error(mensajes.join("\n"));
}
}
async function Capturaerror(page) {
const toasts = await page.locator('#toast-container .toast').all();
const mensajes = [];
let index = 1;
for (const toast of toasts) {
const titulo = await toast.locator('.toast-title').textContent().catch(() => '');
const mensaje = await toast.locator('.toast-message').textContent().catch(() => '');
if (titulo || mensaje) {
mensajes.push(`${index}.- ${titulo.trim()}: ${mensaje.trim()}`);
index++;
}
}
return mensajes;
}
, чтобы всегда захватывать видимый текст каждого тоста, независимо от того, имеет ли он заголовок, сообщение или оба. />
Что на самом деле происходит < /strong> < /h3>
Если тост не содержит. />
Я хочу одно общее решение, которое безопасно фиксирует заголовок и /или сообщение, или целый текст тоста, без тайм -аутов.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ut-waiting
Мобильная версия