home_page.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. @File : home_page.py
  5. @Time : 2024/11/06 22:51:00
  6. @Author : dulip3ng
  7. @Version : 1.0
  8. @Desc : None
  9. '''
  10. from pages.base_page import BasePage
  11. from playwright.sync_api import Page, expect
  12. class HomePage(BasePage):
  13. def __init__(self, page:Page, locator):
  14. super().__init__(page)
  15. self.locator = locator
  16. def change_org(self, org_num:str):
  17. """
  18. 切换组织
  19. :param org_num:组织代码
  20. :return: None
  21. """
  22. self.page.locator(self.locator.ORGANIZATION_LOC).click()
  23. self.page.locator(self.locator.ORG_ITEM_ARGS_LOC % org_num).nth(0).click()
  24. def search_bill(self, bill_name:str, order:int=1):
  25. """
  26. 查询并打开单据
  27. :param bill_name:单据名称
  28. :param order: 重名单据的情况下打开第几个
  29. :return: None
  30. """
  31. self.page.locator(self.locator.SEARCH_IMG_LOC).click()
  32. locator = self.page.locator(self.locator.SEARCH_LOC)
  33. locator.clear()
  34. locator.fill(bill_name)
  35. locator.press_sequentially(" ")
  36. locator.press("Backspace")
  37. self.page.locator(self.locator.BILL_LIST_ARGS_LOC % (bill_name, order)).click()
  38. expect(self.page.locator(self.locator.BILL_OPEN_ARGS_LOC % bill_name)).to_be_attached()
  39. self.page.wait_for_load_state("networkidle")
  40. def close_bill_by_name(self, bill_name:str):
  41. """
  42. 点击单据页签的"x"图标关闭单据,模糊匹配
  43. :TODO: 加入关闭单据提示
  44. :param bill_name:单据名称
  45. :return: None
  46. """
  47. self.page.locator(self.locator.BILL_CLOSE_ARGS_LOC % bill_name).click()
  48. def close_all_opening_bills(self):
  49. """
  50. 关闭所有已打开单据页签
  51. :TODO: 加入关闭单据提示
  52. :return: None
  53. """
  54. self.page.locator(self.locator.ALL_OPEN_FORM_BTN_LOC).click()
  55. self.page.locator(self.locator.CLOSE_ALL_BILLS_ITEM_LOC).click()
  56. def is_bill_opening(self, bill_name:str):
  57. """
  58. 判断单据是否是打开状态, 默认等待5秒
  59. :param bill_name:单据名称
  60. :return:打开True,未打开False
  61. """
  62. try:
  63. loctor = self.page.locator(self.locator.IS_BILL_OPENING_ARGS_LOC % bill_name)
  64. expect(loctor).to_be_attached()
  65. return True
  66. except AssertionError:
  67. return False
  68. def change_bill_tab(self, bill_name:str):
  69. """
  70. 在已打开单据间切换
  71. :param bill_name:单据名称
  72. :return: None
  73. """
  74. self.page.locator(self.locator.BILL_TAB_ARGS_LOC % bill_name).click()
  75. expect(self.page.locator(self.locator.BILL_OPEN_ARGS_LOC % bill_name)).to_be_attached()