# -*- coding: utf-8 -*- ''' iphone and ipad ''' import os import time from PIL import Image # from airtest import patch from airtest import image from airtest import base from appium import webdriver log = base.getLogger('ios') #@patch.record() class IosDevice(object): def __init__(self): self._imgdir = None self._last_point = None self.url = 'http://127.0.0.1:4723/wd/hub' log.debug("IosDevice start connecting...it may take a minute") self.driver = self._connect() self.width, self.height = self._getShape() self._getShapeReal() log.debug('IosDevice connected: width:{width}, height:{height}'.format( width=self.width, height=self.height))
# -*- coding: utf-8 -*- ''' basic operation for a game(like a user does) ''' import os import re import subprocess from airtest import base from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.viewclient import adbclient DEBUG = os.getenv("AIRDEBUG")=="true" log = base.getLogger('android') __dir__ = os.path.dirname(os.path.abspath(__file__)) def getMem(serialno, package): ''' @description details view: http://my.oschina.net/goskyblue/blog/296798 @param package(string): android package name @return dict: {'VSS', 'RSS', 'PSS'} (unit KB) ''' command = 'adb -s %s shell ps' %(serialno) output = base.check_output(command) ret = {} for line in str(output).splitlines(): if line and line.split()[-1] == package:
import os import platform import time import json from PIL import Image from airtest import base from airtest import jsonlog from airtest import image as imt # from airtest.image import auto as image import airtest log = base.getLogger('devsuit') def rotate_point((x, y), (w, h), d): ''' @param (x,y): input point @param (w,h): width and height @param d(string): one of UP,DOWN,LEFT,RIGHT @return (x, y): rotated point ''' if d == 'UP': return x, y if d == 'DOWN': return w-x, y-y if d == 'RIGHT': return y, w-x if d == 'LEFT':
# -*- coding: utf-8 -*- ''' This is only for test airtest itself ''' import os import shutil import airtest from airtest import base # from com.dtmilano.android.viewclient import ViewClient # from com.dtmilano.android.viewclient import adbclient DEBUG = os.getenv("DEBUG")=="true" log = base.getLogger('dummy') class Device(object): def __init__(self, phoneno=None): self._snapshot = './default.png' self._text = '' self._click = None self._getCpu = False pass def snapshot(self, filename): ''' save screen snapshot ''' log.debug('DUMMY take snapshot %s' %(filename)) shutil.copyfile(self._snapshot, filename)
''' import os import time from airtest import image from airtest import patch from airtest import base from airtest import jsonlog from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.viewclient import adbclient DEBUG = os.getenv("DEBUG")=="true" log = base.getLogger('android') def getMem(serialno, package): ''' @param package(string): android package name @return float: the memory, unit MB ''' command = 'adb -s %s shell dumpsys meminfo' % serialno mem_info = base.check_output(command).splitlines() try: xym_mem = filter(lambda x: package in x, mem_info)[0].split()[0] mem = float(xym_mem) / 1024 log.info("mem_info:%s" % mem) return mem except IndexError: log.error("mem_info error")
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import json import time import threading from functools import partial from airtest import base from airtest import jsonlog log = base.getLogger('patch') def attachmethod(target): if isinstance(target, type): def decorator(func): setattr(target, func.__name__, func) else: def decorator(func): setattr(target, func.__name__, partial(func, target)) return decorator def fuckit(fn): def decorator(*args, **kwargs): try: return fn(*args, **kwargs) except Exception as e: args = list(args).extend([k+'='+v for k, v in kwargs.items()]) print 'function(%s(%s)) panic(%s). fuckit' %(fn.__name__, ' ,'.join(args), e)
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' iphone and ipad ''' import os import time from PIL import Image # from airtest import patch from airtest import image from airtest import base from appium import webdriver log = base.getLogger('ios') #@patch.record() class IosDevice(object): def __init__(self): self._imgdir = None self._last_point = None self.url = 'http://127.0.0.1:4723/wd/hub' log.debug("IosDevice start connecting...it may take a minute") self.driver = self._connect() self.width, self.height = self._getShape() self._getShapeReal() log.debug('IosDevice connected: width:{width}, height:{height}'.format(
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' This is only for test airtest itself ''' import os import shutil import airtest from airtest import base # from com.dtmilano.android.viewclient import ViewClient # from com.dtmilano.android.viewclient import adbclient DEBUG = os.getenv("DEBUG") == "true" log = base.getLogger('dummy') class Device(object): def __init__(self, phoneno=None): self._snapshot = './default.png' self._text = '' self._click = None self._getCpu = False pass def snapshot(self, filename): ''' save screen snapshot ''' log.debug('DUMMY take snapshot %s' % (filename)) shutil.copyfile(self._snapshot, filename)