ocrWaitForTextDisplayed
Esperar a que un texto específico se muestre en la pantalla.
Uso
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
});
Salida
Registros
[0-0] 2024-05-26T04:32:52.005Z INFO webdriver: COMMAND ocrWaitForTextDisplayed(<object>)
......................
# ocrWaitForTextDisplayed uses ocrGetElementPositionByText under the hood, that is why you see the command ocrGetElementPositionByText in the logs
[0-0] 2024-05-26T04:32:52.735Z INFO @wdio/ocr-service:ocrGetElementPositionByText: Multiple matches were found based on the word "specFileRetries". The match "specFileRetries" with score "100%" will be used.
Opciones
text
- Tipo:
string - Obligatorio: sí
El texto que deseas buscar para hacer clic.
Ejemplo
await browser.ocrWaitForTextDisplayed({ text: "specFileRetries" });
timeout
- Tipo:
number - Obligatorio: no
- Valor predeterminado: 18000 (18 segundos)
Tiempo en milisegundos. Ten en cuenta que el proceso OCR puede llevar algún tiempo, así que no lo configures demasiado bajo.
Ejemplo
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries"
timeout: 25000 // esperar durante 25 segundos
});
timeoutMsg
- Tipo:
string - Obligatorio: no
- Valor predeterminado:
Could not find the text "{selector}" within the requested time.
Reemplaza el mensaje de error predeterminado.
Ejemplo
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries"
timeoutMsg: "My new timeout message."
});
contrast
- Tipo:
number - Obligatorio: no
- Valor predeterminado:
0.25
Cuanto mayor sea el contraste, más oscura será la imagen y viceversa. Esto puede ayudar a encontrar texto en una imagen. Acepta valores entre -1 y 1.
Ejemplo
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
contrast: 0.5,
});
haystack
- Tipo:
number - Obligatorio:
WebdriverIO.Element | ChainablePromiseElement | Rectangle
Esta es el área de búsqueda en la pantalla donde el OCR debe buscar texto. Puede ser un elemento o un rectángulo que contenga x, y, width y height
Ejemplo
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
haystack: $("elementSelector"),
});
// O
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
haystack: await $("elementSelector"),
});
// O
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
haystack: {
x: 10,
y: 50,
width: 300,
height: 75,
},
});
language
- Tipo:
string - Obligatorio: No
- Valor predeterminado:
eng
El idioma que Tesseract reconocerá. Más información se puede encontrar aquí y los idiomas compatibles se pueden encontrar aquí.
Ejemplo
import { SUPPORTED_OCR_LANGUAGES } from "@wdio/ocr-service";
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
// Usar holandés como idioma
language: SUPPORTED_OCR_LANGUAGES.DUTCH,
});
fuzzyFindOptions
Puedes alterar la lógica difusa para encontrar texto con las siguientes opciones. Esto puede ayudar a encontrar una mejor coincidencia