from playwright.sync_api import expect from .base import BasePage class CustomerProfilePage(BasePage): def open(self): self.goto('/profile/') expect(self.page.get_by_role('heading', name='پروفایل من', exact=True)).to_be_visible() def edit_details(self): self.page.get_by_label('نام:', exact=True).fill('مریم') self.page.get_by_label('نام خانوادگی:', exact=True).fill('رضایی') self.page.get_by_label('نوع مشتری:', exact=True).select_option('PERSON') expect(self.page.locator('#profile-province-options option')).not_to_have_count(0) self.page.get_by_label('استان:', exact=True).fill('تهران') expect(self.page.get_by_label('شهر:', exact=True)).to_be_enabled() self.page.get_by_label('شهر:', exact=True).fill('تهران') def assert_validation_and_save(self): self.page.get_by_label('رمز عبور جدید:', exact=True).fill('short') self.page.get_by_role('button', name='ذخیره تغییرات', exact=True).click() expect(self.page.get_by_label('رمز عبور جدید:', exact=True)).to_be_focused() assert self.page.get_by_label('رمز عبور جدید:', exact=True).evaluate('(input) => input.validity.tooShort') self.page.get_by_label('رمز عبور جدید:', exact=True).fill('') self.page.get_by_label('شهر:', exact=True).fill('رشت') self.page.get_by_label('شهر:', exact=True).press('Tab') self.page.get_by_role('button', name='ذخیره تغییرات', exact=True).click() expect(self.page.get_by_role('alert')).to_contain_text('اطلاعات مشخص‌شده را بررسی') expect(self.page.get_by_label('نام:', exact=True)).to_have_value('مریم') expect(self.page.get_by_label('شهر:', exact=True)).to_have_attribute('aria-invalid', 'true') expect(self.page.locator('#profile-city-options option[value="تهران"]')).to_have_count(1) self.page.get_by_label('شهر:', exact=True).fill('تهران') self.page.get_by_label('شهر:', exact=True).press('Tab') self.page.get_by_role('button', name='ذخیره تغییرات', exact=True).click() expect(self.page.locator('.flash')).to_contain_text('پروفایل شما ذخیره شد.') expect(self.page.get_by_label('نام:', exact=True)).to_have_value('مریم') expect(self.page.get_by_label('شهر:', exact=True)).to_have_value('تهران')