Created
October 13, 2016 14:05
-
-
Save direvius/e38f8cec40e5b61b36753ef4edd5373b to your computer and use it in GitHub Desktop.
Yandex.Tank script for mobile app testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
import logging | |
import time | |
import urllib | |
from uiautomator import Device, Adb | |
logging.basicConfig() | |
logger = logging.getLogger(__name__) | |
class LoadTest(object): | |
def __init__(self, gun): | |
self.gun = gun | |
self.device = Device() | |
self.adb = Adb() | |
self.apk = "/tmp/test.apk" | |
def setup(self, param): | |
logger.info("Download apk...") | |
urllib.urlretrieve(param, self.apk) | |
logger.info("Waking up device...") | |
self.device.wakeup() | |
self.device.press.home() | |
logger.info("Uninstall the app if any...") | |
self.adb.cmd("uninstall", "org.example.myplugin").wait() | |
logger.info("Install the apk...") | |
self.adb.cmd("install", "-rt", self.apk).wait() | |
logger.info("Start the activity...") | |
self.adb.cmd( | |
"shell", "am", "start", "-n", | |
"org.example.myplugin/org.example.myplugin.ui.activity.SplashActivity").wait( | |
) | |
self.device.wait.idle() | |
self.device.press.home() | |
def hotstart(self, missile): | |
self.device.press.home() | |
with self.gun.measure("startup"): | |
logger.info("Start the activity...") | |
self.adb.cmd( | |
"shell", "am", "start", "-n", | |
"org.example.myplugin/org.example.myplugin.ui.activity.SplashActivity").wait( | |
) | |
while not self.device(resourceId="org.example.myplugin:id/location").exists: | |
time.sleep(0.1) | |
def coldstart(self, missile): | |
logger.info("Uninstall the app if any...") | |
self.adb.cmd("uninstall", "org.example.myplugin").wait() | |
logger.info("Install the apk...") | |
self.adb.cmd("install", "-rt", self.apk).wait() | |
with self.gun.measure("coldstart"): | |
logger.info("Start the activity...") | |
self.adb.cmd( | |
"shell", "am", "start", "-n", | |
"org.example.myplugin/org.example.myplugin.ui.activity.SplashActivity") | |
while not self.device(resourceId="org.example.myplugin:id/location").exists: | |
time.sleep(0.1) | |
def teardown(self): | |
self.adb.cmd("uninstall", "org.example.myplugin").wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment