import io
from PIL import Image
from typing import Any, Optional, Union, override
from askui import VisionAgent
from askui.reporting import Reporter
import allure
# Define the allure reporter
class AllureReporter(Reporter):
@override
def add_message(
self,
role: str,
content: Union[str, dict[str, Any], list[Any]],
image: Optional[Image.Image | list[Image.Image]] = None,
) -> None:
with allure.step(f"{role}: {str(content)}"):
if image:
images = image if isinstance(image, list) else [image]
for img in images:
img_bytes = io.BytesIO()
img.save(img_bytes, format='PNG')
allure.attach(
img_bytes.getvalue(),
name="screenshot",
attachment_type=allure.attachment_type.PNG,
)
@override
def generate(self) -> None:
pass
# Configure your reporter
with VisionAgent(reporters=[AllureReporter()]) as agent:
agent.click("button")
# Your automation steps here