Guest User

Untitled

a guest
Oct 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import csv
  2. import os
  3. import time
  4.  
  5.  
  6. class App(object):
  7. def __init__(self):
  8. self.content = ""
  9. self.startTime = 0
  10.  
  11. # 启动App
  12. def LaunchApp(self):
  13. cmd = 'adb shell am start -W -n com.yhjs.bbus.app/.MainActivity'
  14. self.content = os.popen(cmd)
  15.  
  16. # 停止App
  17. def StopApp(self):
  18. cmd = 'adb shell am force-stop com.yhjs.bbus.app'
  19. os.popen(cmd)
  20.  
  21. # 获取启动时间
  22. def GetLaunchedTime(self):
  23. for line in self.content.readlines():
  24. if "ThisTime" in line:
  25. self.startTime = line.split(":")[1]
  26. break
  27. return self.startTime
  28.  
  29.  
  30. # 控制类
  31. class Controller(object):
  32. def __init__(self, count):
  33. self.app = App()
  34. self.counter = count
  35. self.alldata = [("timestamp", "elapsedtime")]
  36.  
  37. # 单次测试过程
  38. def testprocess(self):
  39. self.app.LaunchApp()
  40. time.sleep(5)
  41. elpasedtime = self.app.GetLaunchedTime()
  42. self.app.StopApp()
  43. time.sleep(3)
  44. currenttime = self.getCurrentTime()
  45. self.alldata.append((currenttime, elpasedtime))
  46.  
  47. # 多次执行测试过程
  48. def run(self):
  49. while self.counter > 0:
  50. self.testprocess()
  51. self.counter = self.counter - 1
  52.  
  53. # 获取当前的时间戳
  54. def getCurrentTime(self):
  55. currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  56. return currentTime
  57.  
  58. # 数据的存储
  59. def SaveDataToCSV(self):
  60. csvfile = open('coolTime.csv', 'a+', newline='')
  61. writer = csv.writer(csvfile)
  62. writer.writerows(self.alldata)
  63. csvfile.close()
  64.  
  65.  
  66. if __name__ == "__main__":
  67. controller = Controller(10)
  68. controller.run()
  69. controller.SaveDataToCSV()
Add Comment
Please, Sign In to add comment