程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python game testing tool automatically traverses all levels in the game

編輯:Python

Catalog

scene

Ideas

Implementation details

1. Determination and handling of jamming

2.GAutomator Call the game's internal GM Instructions

unity in :

python in :

3. Final output report

Detailed code

AutoBattleTest.py Used to implement the core logic

ExcelTool.py Used to read and write tables

Postscript

scene

There are many levels in the game ( There may be hundreds ), In theory, you should traverse each level to see if there are any exceptions before publishing to the Internet , Last time, some players got stuck when playing a certain level , If each level needs to be manually traversed, it will be very time-consuming , So consider using automation to achieve .

Ideas

The battle of the game has a time limit , here we are 5 If you can't play for minutes, you will be judged negative , The settlement panel will appear in the victory or defeat , use GA Provided find_element_wait Function to find the settlement panel , From entering the battle to finding this panel element It is the time for customs clearance , If exceeded 5 Minutes means it's stuck , The last one is output ” Customs clearance schedule “ Sort to see which levels have clearance time >5 Minutes is the problematic level .

Implementation details 1. Determination and handling of jamming

GAutomator find_element_wait Function description

Set... In the code 5 Check the settlement panel every second , exceed 60 Time is actually stuck .Page.panel_BattleRes Yes settlement panel , Here the PO Mode puts all element Are written to a Page in .

If it gets stuck Where will the game always stop , Use after jamming adb Command to restart the game and continue to test the next level until you traverse the entire level list .

2.GAutomator Call the game's internal GM Instructions

GAutomator You can put the game C# Function and register it in the python Call in , This is a GA Describe the relevant parts of the document :

So put in the game GM The instruction method is registered and called in the script , In this way, I can use the command to enter each level without being affected by the level 、 entrance 、 Front level and other restrictions

unity in :

python in :

3. Final output report

The first column is the level id, The second column is the customs clearance time ,100014 There is something wrong with this level , Because it has exceeded 5 Minutes.

Detailed code AutoBattleTest.py Used to implement the core logic from testcase.tools import *from testcase.ExcelTool import ExcelReader,ExcelWriterfrom testcase.Page import Pageclass AutoBattle: def __init__(self,level_excel_path): self.start_time=0 self.levelList=ExcelReader(level_excel_path).read_first_sheet_first_col() self.excelWriter = ExcelWriter() print(self.levelList) def start_battle(self): self.start_time=time.time() m_btnStartGame = engine.find_element(Page.btn_BeginFight) screen_shot_click(m_btnStartGame) #auto fight m_autoFight = engine.find_element(Page.btn_AutoFight) screen_shot_click(m_autoFight) def test_each_level(self): for index,level in enumerate(self.levelList): print(" checkpoint id---->"+level) engine.call_registered_handler("GoTo", "n"+level) # This call unity Inside GM Instructions self.start_battle() battleResult = find_element_wait(Page.panel_BattleRes, 65, 5) if (battleResult): screen_shot_click(battleResult) duration = str(int(time.time() - self.start_time)) # Level duration self.excelWriter.write_excel(index, 0, level) # The first column writes the level name self.excelWriter.write_excel(index, 1, duration) # The second column writes the customs clearance time else: duration = str(int(time.time() - self.start_time)) # Level duration self.excelWriter.write_excel(index, 0, level) # The first column writes the level name self.excelWriter.write_excel(index, 1, duration) # The second column writes the customs clearance time self.restart_game() self.default_login() find_element_wait(Page.btn_Battle) self.excelWriter.save_excel() def restart_game(self): # Restart the game os.system("adb shell am force-stop %s"%Page.package_name) time.sleep(2) os.system("adb shell am start -n %s/.NativeUnityPlayerActivity"%Page.package_name) def default_login(self):# You can log in after one click #m_BtnSart2 start_btn = find_element_wait(Page.btn_LogIn) screen_shot_click(start_btn)if __name__ == "__main__": ab = AutoBattle("level.xls") ab.test_each_level()ExcelTool.py Used to read and write tables import xlrdimport timeimport xlwtclass ExcelReader: def __init__(self,excel_path): self.excel_path = excel_path; def read_first_sheet_first_col(self): data = xlrd.open_workbook(self.excel_path) st = data.sheet_by_index(0) col = [str(st.cell_value(i, 0)).replace(".0","") for i in range(0, st.nrows)] return colclass ExcelWriter: def __init__(self): self.wb = xlwt.Workbook() self.sh = self.wb.add_sheet(" The level passes the time record ") self.cur_col =0 def write_excel(self,row ,col,record_str): self.sh.write(row, col, record_str) def save_excel(self): date_string = time.strftime("%Y%m%d%H%M") excel_name ="TestResult"+date_string+".xls" self.wb.save(excel_name)if __name__=="__main__": ew = ExcelWriter() ew.save_excel() Postscript

This set of scripts can check out the problems of getting stuck in the process of entry or midway or not settling , But if it is a monster's skill, it will cause the level to get stuck , And this monster was killed before it could play skills , In this case, the script has a probability that it will not be found .

That's all python Game testing tools automatically traverse the details of all levels in the game , More about python For information about game test automation traversing the level, please pay attention to other relevant articles on the software development network !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved