push_page.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. @File : push_page.py
  5. @Time : 2024/11/28 16:24:19
  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
  12. class PushPage(BasePage):
  13. """
  14. 选单,下拉独立页面页面模型
  15. """
  16. def __init__(self, page:Page, locator):
  17. super().__init__(page)
  18. self.locator = locator
  19. def _pick_bill(self, bill_name:str):
  20. """
  21. 选择单据,精确匹配
  22. :param bill_name: 单据名称
  23. :return:
  24. """
  25. self.page.locator(self.locator.BILL_ARGSLOC % bill_name).click()
  26. def _select_bill_type(self, bill_type:str):
  27. """
  28. 选择单据类型,精确匹配
  29. :param bill_type: 单据类型名称,可选参数
  30. :return:
  31. """
  32. self.page.locator(self.locator.BILL_TYPE_LOC).click()
  33. self.page.locator(self.locator.SELECT_ITEM_ARGS_LOC % bill_type).click()
  34. def _select_convert_rule(self, rule_name:str):
  35. """
  36. 选择单据转换规则,精确匹配
  37. :param rule_name: 转换规则名称,可选参数
  38. :return:
  39. """
  40. self.page.locator(self.locator.CONVERT_RULE_LOC).click()
  41. self.page.locator(self.locator.SELECT_ITEM_ARGS_LOC % rule_name).click()
  42. def _select_target_org(self, org_name:str):
  43. """
  44. 选择目标组织,精确匹配
  45. :param org_name:
  46. :return:
  47. """
  48. self.page.locator(self.locator.TARGET_ORG_LOC).click()
  49. self.page.locator(self.locator.SELECT_ITEM_ARGS_LOC % org_name).click()
  50. def _click_ok_button(self):
  51. """
  52. 点击下推页面确定按钮
  53. :return:
  54. """
  55. self.page.locator(self.locator.OK_BUTTON_LOC).click()
  56. def push_draw_bill(self, bill_name:str, rule_name:str=None, bill_type:str=None, org_name:str=None):
  57. """
  58. 设置单据,单据类型,转换规则,目标组织进行下推操作
  59. **用法:**
  60. PushPage.push_draw_bill("生产订单")
  61. PushPage.push_draw_bill("生产订单", "犀牛销售订单2生产订单", "直接入库-普通生产", "制衣事业部")
  62. :param bill_name: 下游单据名称,精确匹配,必填
  63. :param rule_name: 转换规则,精确匹配,可选
  64. :param bill_type: 单据类型,精确匹配,可选
  65. :param org_name: 目标组织名,精确匹配,可选
  66. :return:
  67. """
  68. self.page.wait_for_load_state("networkidle")
  69. self._pick_bill(bill_name)
  70. # 下推时切换单据,页面会请求单据对应的转换规则,重新渲染转换规则下拉框,偶发渲染完成时点击太快报选择不上下拉选项问题,
  71. # 等待1秒,使其降低点击速度,增加稳定性
  72. self.page.wait_for_timeout(1000)
  73. if rule_name: self._select_convert_rule(rule_name)
  74. if bill_type: self._select_bill_type(bill_type)
  75. if org_name: self._select_target_org(org_name)
  76. self._click_ok_button()