costume_test_shikigami.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from module.logger import logger
  5. from module.base.timer import Timer
  6. from tasks.GameUi.game_ui import GameUi
  7. from tasks.GameUi.page import page_shikigami_records, page_main
  8. from tasks.Component.Costume.config import ShikigamiType
  9. from tasks.Component.SwitchSoul.assets import SwitchSoulAssets
  10. from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
  11. from tasks.SoulsTidy.assets import SoulsTidyAssets
  12. from tasks.SoulsTidy.script_task import ScriptTask as SoulsTidyTask
  13. class ScriptTask(GameUi, SwitchSoul, SwitchSoulAssets, SoulsTidyAssets):
  14. """
  15. 快速回归测试:验证幕间(式神录)皮肤映射是否正确生效。
  16. 路径:主页 -> 式神录;并在式神录中检测御魂切换与御魂整理的关键识别点。
  17. """
  18. def run(self):
  19. # 定位并进入式神录
  20. self.ui_get_current_page()
  21. self.ui_goto(page_shikigami_records)
  22. # 关键识别点统计
  23. images_count = [
  24. # GameUi - 式神录判定
  25. [self.I_CHECK_RECORDS, 0],
  26. # SwitchSoul - 预设/面板关键元素(不做实际切换,仅检测图标出现)
  27. [self.I_SOUL_PRESET, 0],
  28. [self.I_SOU_CHECK_IN, 0],
  29. [self.I_SOU_TEAM_PRESENT, 0],
  30. [self.I_SOU_SWITCH_1, 0],
  31. [self.I_SOU_SWITCH_2, 0],
  32. [self.I_SOU_SWITCH_3, 0],
  33. [self.I_SOU_SWITCH_4, 0],
  34. [self.I_SOU_SWITCH_SURE, 0],
  35. # SoulsTidy - 御魂页面关键元素
  36. [self.I_ST_SOULS, 0],
  37. [self.I_ST_REPLACE, 0],
  38. [self.I_ST_TIDY, 0],
  39. [self.I_ST_GREED, 0],
  40. ]
  41. logger.hr('Shikigami Costume Test Start')
  42. timer = Timer(5)
  43. timer.start()
  44. while 1:
  45. self.screenshot()
  46. logger.info('Detecting images on Shikigami Records...')
  47. for i in images_count:
  48. if self.appear(i[0]):
  49. i[1] += 1
  50. if timer.reached():
  51. logger.info('Five seconds test over')
  52. break
  53. print('--------------------------------------------------------')
  54. print('%-32s %s' % ('Image', 'Count'))
  55. for i in images_count:
  56. print('%-32s %3d times' % (i[0], i[1]))
  57. logger.info('Shikigami Costume Test Done')
  58. # 测试御魂切换功能 (1-7组,每组1-4切换)
  59. self.test_switch_soul_all_groups()
  60. # 测试御魂奉纳功能
  61. self.test_souls_tidy_donation()
  62. def set_costume(self, costume: ShikigamiType = ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT):
  63. self.config.model.global_game.costume_config.costume_shikigami_type = costume
  64. self.check_costume()
  65. logger.info('Set shikigami costume to %s' % self.config.model.global_game.costume_config.costume_shikigami_type)
  66. def test_switch_soul_all_groups(self):
  67. """
  68. 测试御魂切换功能:测试1-7组,每组1-4切换
  69. """
  70. logger.hr('Switch Soul Test - All Groups')
  71. # 进入式神录
  72. self.ui_get_current_page()
  73. self.ui_goto(page_shikigami_records)
  74. # 点击预设按钮
  75. self.click_preset()
  76. # 测试1-7组,每组1-4切换
  77. for group in range(1, 8): # 1-7组
  78. for team in range(1, 5): # 1-4队
  79. logger.info(f'Testing group {group}, team {team}')
  80. try:
  81. self.switch_soul_one(group, team)
  82. logger.info(f'Successfully switched to group {group}, team {team}')
  83. except Exception as e:
  84. logger.error(f'Failed to switch to group {group}, team {team}: {e}')
  85. # 退出式神录
  86. self.exit_shikigami_records()
  87. logger.info('Switch Soul Test - All Groups completed')
  88. def test_souls_tidy_donation(self):
  89. """
  90. 测试御魂奉纳功能
  91. """
  92. logger.hr('Souls Tidy Donation Test')
  93. # 进入式神录
  94. self.ui_get_current_page()
  95. self.ui_goto(page_shikigami_records)
  96. # 进入御魂界面
  97. souls_tidy_task = SoulsTidyTask(self.config, self.device)
  98. souls_tidy_task.goto_souls()
  99. # 检查御魂界面关键元素
  100. detection_count = 0
  101. timer = Timer(5)
  102. timer.start()
  103. while 1:
  104. self.screenshot()
  105. logger.info('Detecting souls tidy interface elements...')
  106. # 检查御魂界面元素
  107. if self.appear(self.I_ST_GREED):
  108. detection_count += 1
  109. logger.info('Detected I_ST_GREED')
  110. if self.appear(self.I_ST_TIDY):
  111. detection_count += 1
  112. logger.info('Detected I_ST_TIDY')
  113. if self.appear(self.I_ST_REPLACE):
  114. detection_count += 1
  115. logger.info('Detected I_ST_REPLACE')
  116. if self.appear(self.I_ST_BONGNA):
  117. detection_count += 1
  118. logger.info('Detected I_ST_BONGNA')
  119. if timer.reached():
  120. logger.info('Souls tidy detection test over')
  121. break
  122. logger.info(f'Detected {detection_count} souls tidy interface elements')
  123. # 退回到式神录
  124. souls_tidy_task.back_records()
  125. # 退出式神录
  126. self.ui_get_current_page()
  127. self.ui_goto(page_main)
  128. logger.info('Souls Tidy Donation Test completed')
  129. if __name__ == '__main__':
  130. from module.config.config import Config
  131. from module.device.device import Device
  132. c = Config('oas1')
  133. d = Device(c)
  134. t = ScriptTask(c, d)
  135. t.set_costume(ShikigamiType.COSTUME_SHIKIGAMI_4)
  136. # t.set_costume(ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT)
  137. t.run()