from PIL import Image from io import BytesIO import allure from src.ui_elements.base_ui_element import BaseUIElement class ButtonUIElement(BaseUIElement): @allure.step("Clicking on {0}") def click(self): self.log.info(f"Clicking on {self.locator[1]}") self.wait() self._element.click() @property @allure.step("Getting text of {0}") def text(self): self.log.info(f"Getting text of {self.locator[1]}") text = self._element.text if not text: text = self._element.get_attribute("innerText") return text.strip() @property @allure.step("Getting image of {0}") def image(self): self.log.info(f"Getting image of a {self.locator[1]}") return Image.open(BytesIO(self._element.screenshot_as_png)) def __str__(self): return f"Button {self.name}"