switch_account.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from adbutils import device
  2. from module.config.config import Config
  3. from module.device.device import Device
  4. from tasks.Component.SwitchAccount.assets import SwitchAccountAssets
  5. from tasks.Component.SwitchAccount.exit_game import ExitGame
  6. from tasks.Component.SwitchAccount.login_account import LoginAccount
  7. from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
  8. from tasks.GameUi.game_ui import GameUi
  9. from tasks.GameUi.page import page_main, page_login
  10. from tasks.base_task import BaseTask
  11. from tasks.Restart.login import LoginHandler
  12. from module.logger import logger
  13. class SwitchAccount(LoginAccount, ExitGame, GameUi, SwitchAccountAssets):
  14. def __init__(self, config: Config, device: Device, to: AccountInfo, frm: AccountInfo = None):
  15. """
  16. @param config:
  17. @type config:
  18. @param device:
  19. @type device:
  20. @param to: 要登录的账号信息
  21. @type to:
  22. @param frm: 上一个账号信息 ,避免关键字from
  23. @type frm:
  24. """
  25. super().__init__(config, device)
  26. self.to_account_info = to
  27. self.from_account_info = frm
  28. def switchAccount(self):
  29. logger.info("start switchAccount %s-%s", self.to_account_info.character, self.to_account_info.svr)
  30. # 判断所处界面
  31. curPage = self.ui_get_current_page()
  32. if curPage != page_login and curPage != page_main:
  33. self.ui_goto(page_main)
  34. curPage = self.ui_get_current_page()
  35. if curPage == page_main:
  36. self.exitGame()
  37. # 处于登录界面
  38. if not self.login(self.to_account_info):
  39. return False
  40. logger.info("%s login suc", self.to_account_info.character)
  41. # 处理位于登录界面各种奇葩弹窗
  42. login_handler = LoginHandler(config=self.config, device=self.device)
  43. login_handler.set_specific_usr(self.to_account_info.svr)
  44. login_handler.app_handle_login()
  45. return True
  46. if __name__ == '__main__':
  47. config = Config('oas1')
  48. device=Device()
  49. toAccount=AccountInfo(account="email0@163.com", account_alias="emailO#emailo", apple_or_android=True, character="粘贴", svr="立秋夕烛")
  50. sa=SwitchAccount(config,device,toAccount)
  51. sa.switchAccount()