The practice of Python automation for stress testing

Source: Internet
Author: User
Tags appium

Test app: Start time, CPU, traffic, power, memory, FPS, over rendering

Configuration of the Environment 1. Android SDK 2. Python 3.pyCharm 1.                               Android SDK Download URL: http://www.androiddevtools.cn/index.html environment variable: android_home:d:\appium\android SDK\ANDROID-SDK                                          Path:d:\appium\android Sdk\android-sdk\platform-tools D:\Appium\Android sdk\android-sdk\tools Add environment variable, link the real machine, input adb devices have output, determine the Android Sdk add success 2.python:https://www.py Thon.org/downloads/3.pycharm Direct download install get app package name and activity name: adb shell "Logcat | grep start "Then launch app to find cmp=" com.zgjky.app/.activity.welcomepage.welcome_activity "

Start time: Cold start: Program (process) first start hot start: Program (process) pushed to background
# Encoding:utf-8
Import CSV
Import OS
Import time
#APP类

Class App (object):
def __init__ (self):
Self.content = ""
Self.starttime = 0

def launchapp (self):
#启动APP
cmd = "adb shell am start-w-N com.zgjky.app/.activity.welcomepage.welcome_activity"
self.content= Os.popen (CMD)

def stopapp (self):
#停止APP
cmd = "adb shell am force-stop com.zgjky.app"
Os.popen (CMD)

#获取启动时间
def getlaunchedtime (self):
For line in Self.content.readlines ():
If "Thistime" in line:
Self.starttime = Line.split (":") [1]
Break
Return Self.starttime

#控制类
Class Controller (object):
def __init__ (Self,count):
Self.app = App ()
Self.counter = Count
Self.alldata = [("Timestamp", "Elpasedtime")]

#单次测试过程
def testprocess (self):
SELF.APP.LAUNCHAPP ()
Time.sleep (5)
Elpasedtime = Self.app.GetLaunchedTime ()
SELF.APP.STOPAPP ()
Time.sleep (3)
CurrentTime = Self.getcurrenttime ()
Self.alldata.append ((currenttime,elpasedtime))

#多次测试过程
def run (self):
While Self.counter > 0:
Self.testprocess ()
Self.counter = Self.counter-1

#获取当前时间戳
def getcurrenttime (self):
CurrentTime = Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())
Return currenttime

#数据的存贮
def savedatatocsv (self):
CSVFile = File ("Starttime.csv", "WB")
writer = Csv.writer (csvfile)
Writer.writerows (Self.alldata)
Csvfile.close ()

if __name__ = = "__main__":
Controller = Controller (11)
Controller.run ()
Controller. Savedatatocsv ()
Problem: When executing the program, the app starts once, then does not then parse: CSV file, run error in python3.6 causes

The practice of Python automation for stress testing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.