|  | 
|  | 1 | +"""BIAB Page object for automating interactions with the Multi-Agent Planner UI.""" | 
|  | 2 | + | 
|  | 3 | +from playwright.sync_api import expect | 
|  | 4 | +from base.base import BasePage | 
|  | 5 | + | 
|  | 6 | + | 
|  | 7 | +class BIABPage(BasePage): | 
|  | 8 | +    """Page object model for BIAB/Multi-Agent Planner workflow automation.""" | 
|  | 9 | + | 
|  | 10 | +    WELCOME_PAGE_TITLE = "//span[normalize-space()='Multi-Agent Planner']" | 
|  | 11 | +    NEW_TASK_PROMPT = "//textarea[@placeholder='Tell us what needs planning, building, or connecting—we'll handle the rest.']" | 
|  | 12 | +    SEND_BUTTON = "//div[@role='toolbar']" | 
|  | 13 | +    CREATING_PLAN = "//span[normalize-space()='Creating a plan']" | 
|  | 14 | +    TASK_LIST = "//span[contains(text(),'1.')]" | 
|  | 15 | +    NEW_TASK = "//span[normalize-space()='New task']" | 
|  | 16 | +    MOBILE_PLAN = ( | 
|  | 17 | +        "//span[normalize-space()='Ask about roaming plans prior to heading overseas.']" | 
|  | 18 | +    ) | 
|  | 19 | +    MOBILE_TASK1 = "//span[contains(text(),'1.')]" | 
|  | 20 | +    MOBILE_TASK2 = "//span[contains(text(),'2.')]" | 
|  | 21 | +    MOBILE_APPROVE_TASK1 = "i[title='Approve']" | 
|  | 22 | +    ADDITIONAL_INFO = "//textarea[@placeholder='Add more info to this task...']" | 
|  | 23 | +    ADDITIONAL_INFO_SEND_BUTTON = ( | 
|  | 24 | +        "//div[@class='plan-chat-input-wrapper']//div//div//div//div[@role='toolbar']" | 
|  | 25 | +    ) | 
|  | 26 | +    STAGES = "//button[@aria-label='Approve']" | 
|  | 27 | +    RAI_PROMPT_VALIDATION = "//span[normalize-space()='Failed to create plan']" | 
|  | 28 | +    COMPLETED_TASK = "//span[@class='fui-Text ___13vod6f fk6fouc fy9rknc fwrc4pm figsok6 fpgzoln f1w7gpdv f6juhto f1gl81tg f2jf649']" | 
|  | 29 | + | 
|  | 30 | +    def __init__(self, page): | 
|  | 31 | +        """Initialize the BIABPage with a Playwright page instance.""" | 
|  | 32 | +        super().__init__(page) | 
|  | 33 | +        self.page = page | 
|  | 34 | + | 
|  | 35 | +    def click_my_task(self): | 
|  | 36 | +        """Click on the 'My Task' item in the UI.""" | 
|  | 37 | +        self.page.locator(self.TASK_LIST).click() | 
|  | 38 | +        self.page.wait_for_timeout(10000) | 
|  | 39 | + | 
|  | 40 | +    def enter_aditional_info(self, text): | 
|  | 41 | +        """Enter additional info and click the send button.""" | 
|  | 42 | +        additional_info = self.page.locator(self.ADDITIONAL_INFO) | 
|  | 43 | + | 
|  | 44 | +        if additional_info.is_enabled(): | 
|  | 45 | +            additional_info.fill(text) | 
|  | 46 | +            self.page.wait_for_timeout(5000) | 
|  | 47 | +            self.page.locator(self.ADDITIONAL_INFO_SEND_BUTTON).click() | 
|  | 48 | +            self.page.wait_for_timeout(5000) | 
|  | 49 | + | 
|  | 50 | +    def click_send_button(self): | 
|  | 51 | +        """Click the send button and wait for 'Creating a plan' to disappear.""" | 
|  | 52 | +        self.page.locator(self.SEND_BUTTON).click() | 
|  | 53 | +        expect(self.page.locator("span", has_text="Creating a plan")).to_be_visible() | 
|  | 54 | +        self.page.locator("span", has_text="Creating a plan").wait_for( | 
|  | 55 | +            state="hidden", timeout=30000 | 
|  | 56 | +        ) | 
|  | 57 | +        self.page.wait_for_timeout(2000) | 
|  | 58 | + | 
|  | 59 | +    def validate_rai_validation_message(self): | 
|  | 60 | +        """Validate RAI prompt error message visibility.""" | 
|  | 61 | +        self.page.locator(self.SEND_BUTTON).click() | 
|  | 62 | +        self.page.wait_for_timeout(1000) | 
|  | 63 | +        expect(self.page.locator(self.RAI_PROMPT_VALIDATION)).to_be_visible( | 
|  | 64 | +            timeout=10000 | 
|  | 65 | +        ) | 
|  | 66 | +        self.page.wait_for_timeout(3000) | 
|  | 67 | + | 
|  | 68 | +    def click_aditional_send_button(self): | 
|  | 69 | +        """Click the additional info send button.""" | 
|  | 70 | +        self.page.locator(self.ADDITIONAL_INFO_SEND_BUTTON).click() | 
|  | 71 | +        self.page.wait_for_timeout(5000) | 
|  | 72 | + | 
|  | 73 | +    def click_new_task(self): | 
|  | 74 | +        """Click the 'New Task' button.""" | 
|  | 75 | +        self.page.locator(self.NEW_TASK).click() | 
|  | 76 | +        self.page.wait_for_timeout(5000) | 
|  | 77 | + | 
|  | 78 | +    def click_mobile_plan(self): | 
|  | 79 | +        """Click on a specific mobile plan in the task list.""" | 
|  | 80 | +        self.page.locator(self.MOBILE_PLAN).click() | 
|  | 81 | +        self.page.wait_for_timeout(3000) | 
|  | 82 | + | 
|  | 83 | +    def validate_home_page(self): | 
|  | 84 | +        """Validate that the home page title is visible.""" | 
|  | 85 | +        expect(self.page.locator(self.WELCOME_PAGE_TITLE)).to_be_visible() | 
|  | 86 | + | 
|  | 87 | +    def enter_a_question(self, text): | 
|  | 88 | +        """Enter a question in the prompt textbox.""" | 
|  | 89 | +        self.page.get_by_role("textbox", name="Tell us what needs planning,").fill(text) | 
|  | 90 | +        self.page.wait_for_timeout(4000) | 
|  | 91 | + | 
|  | 92 | +    def processing_different_stage(self): | 
|  | 93 | +        """Process and approve each stage sequentially if present.""" | 
|  | 94 | +        self.page.wait_for_timeout(3000) | 
|  | 95 | +        total_count = self.page.locator(self.STAGES).count() | 
|  | 96 | +        if self.page.locator(self.STAGES).count() >= 1: | 
|  | 97 | +            for _ in range(self.page.locator(self.STAGES).count()): | 
|  | 98 | +                approve_stages = self.page.locator(self.STAGES).nth(0) | 
|  | 99 | +                approve_stages.click() | 
|  | 100 | +                self.page.wait_for_timeout(2000) | 
|  | 101 | +                self.page.locator( | 
|  | 102 | +                    "//span[normalize-space()='Step approved successfully']" | 
|  | 103 | +                ).wait_for(state="visible", timeout=30000) | 
|  | 104 | + | 
|  | 105 | +                plan_id = BasePage.get_first_plan_id(self) | 
|  | 106 | +                BasePage.approve_plan_by_id(self, plan_id) | 
|  | 107 | +                self.page.wait_for_timeout(7000) | 
|  | 108 | + | 
|  | 109 | +        expect(self.page.locator(self.COMPLETED_TASK)).to_contain_text(f"{total_count} of {total_count} completed") | 
|  | 110 | + | 
0 commit comments