costume_test_shikigami.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.goto_page(page_shikigami_records)
  21. # 关键识别点统计
  22. images_count = [
  23. # GameUi - 式神录判定
  24. [self.I_CHECK_RECORDS, 0],
  25. # SwitchSoul - 预设/面板关键元素(不做实际切换,仅检测图标出现)
  26. [self.I_SOUL_PRESET, 0],
  27. [self.I_SOU_CHECK_IN, 0],
  28. [self.I_SOU_TEAM_PRESENT, 0],
  29. [self.I_SOU_SWITCH_1, 0],
  30. [self.I_SOU_SWITCH_2, 0],
  31. [self.I_SOU_SWITCH_3, 0],
  32. [self.I_SOU_SWITCH_4, 0],
  33. [self.I_UI_CONFIRM, 0],
  34. # SoulsTidy - 御魂页面关键元素
  35. [self.I_ST_SOULS, 0],
  36. [self.I_ST_REPLACE, 0],
  37. [self.I_ST_TIDY, 0],
  38. [self.I_ST_GREED, 0],
  39. ]
  40. logger.hr('Shikigami Costume Test Start')
  41. timer = Timer(5)
  42. timer.start()
  43. while 1:
  44. self.screenshot()
  45. logger.info('Detecting images on Shikigami Records...')
  46. for i in images_count:
  47. if self.appear(i[0]):
  48. i[1] += 1
  49. if timer.reached():
  50. logger.info('Five seconds test over')
  51. break
  52. print('--------------------------------------------------------')
  53. print('%-32s %s' % ('Image', 'Count'))
  54. for i in images_count:
  55. print('%-32s %3d times' % (i[0], i[1]))
  56. logger.info('Shikigami Costume Test Done')
  57. # 测试御魂切换功能 (1-7组,每组1-4切换)
  58. self.test_switch_soul_all_groups()
  59. # 测试御魂奉纳功能
  60. self.test_souls_tidy_donation()
  61. def set_costume(self, costume: ShikigamiType = ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT):
  62. self.config.model.global_game.costume_config.costume_shikigami_type = costume
  63. self.check_costume()
  64. logger.info('Set shikigami costume to %s' % self.config.model.global_game.costume_config.costume_shikigami_type)
  65. def test_switch_soul_all_groups(self):
  66. """
  67. 测试御魂切换功能:测试1-7组,每组1-4切换
  68. """
  69. logger.hr('Switch Soul Test - All Groups')
  70. # 进入式神录
  71. self.goto_page(page_shikigami_records)
  72. # 点击预设按钮
  73. self.click_preset()
  74. # 测试1-7组,每组1-4切换
  75. for group in range(1, 8): # 1-7组
  76. for team in range(1, 5): # 1-4队
  77. logger.info(f'Testing group {group}, team {team}')
  78. try:
  79. self.switch_soul_one(group, team)
  80. logger.info(f'Successfully switched to group {group}, team {team}')
  81. except Exception as e:
  82. logger.error(f'Failed to switch to group {group}, team {team}: {e}')
  83. # 退出式神录
  84. self.exit_shikigami_records()
  85. logger.info('Switch Soul Test - All Groups completed')
  86. def test_souls_tidy_donation(self):
  87. """
  88. 测试御魂奉纳功能
  89. """
  90. logger.hr('Souls Tidy Donation Test')
  91. # 进入式神录
  92. self.goto_page(page_shikigami_records)
  93. # 进入御魂界面
  94. souls_tidy_task = SoulsTidyTask(self.config, self.device)
  95. souls_tidy_task.goto_souls()
  96. # 检查御魂界面关键元素
  97. detection_count = 0
  98. timer = Timer(5)
  99. timer.start()
  100. while 1:
  101. self.screenshot()
  102. logger.info('Detecting souls tidy interface elements...')
  103. # 检查御魂界面元素
  104. if self.appear(self.I_ST_GREED):
  105. detection_count += 1
  106. logger.info('Detected I_ST_GREED')
  107. if self.appear(self.I_ST_TIDY):
  108. detection_count += 1
  109. logger.info('Detected I_ST_TIDY')
  110. if self.appear(self.I_ST_REPLACE):
  111. detection_count += 1
  112. logger.info('Detected I_ST_REPLACE')
  113. if self.appear(self.I_ST_BONGNA):
  114. detection_count += 1
  115. logger.info('Detected I_ST_BONGNA')
  116. if timer.reached():
  117. logger.info('Souls tidy detection test over')
  118. break
  119. logger.info(f'Detected {detection_count} souls tidy interface elements')
  120. # 退回到式神录
  121. souls_tidy_task.back_records()
  122. # 退出式神录
  123. self.goto_page(page_main)
  124. logger.info('Souls Tidy Donation Test completed')
  125. if __name__ == '__main__':
  126. from module.config.config import Config
  127. from module.device.device import Device
  128. c = Config('oas1')
  129. d = Device(c)
  130. t = ScriptTask(c, d)
  131. t.set_costume(ShikigamiType.COSTUME_SHIKIGAMI_12)
  132. # t.set_costume(ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT)
  133. t.run()