import re from allure import step from playwright.sync_api import expect from src.ui_elements.base_ui_element import BaseUIElement class DropDownUIElement(BaseUIElement): @step('Select {option} option from {0}') def select_option(self, option): self._element.click() choice = self.page.locator('{}//*[text()="{}"]'.format(self.locator, option)) choice.click() expect(self._element).to_have_text(option) @step('Search and select {option} option from {0}') def search_select_option(self, option): self._element.click() search_field = self.page.locator('{}//input'.format(self.locator)) search_field.fill(option) choice = self.page.locator('{}//*[text()="{}"]'.format(self.locator, option)) choice.hover() self.page.keyboard.press('Enter') expect(self._element).to_have_text(option) def __str__(self): return f"DropDown {self.name}"