Exemple #1
0
def watch(conf, package, interval, serialno, human_readable, syscpu,
          output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    # app = airtest.connect(serialno, device=airtest.ANDROID, monitor=False)
    airtest.connect('android://' + serialno)
    m = airtest.Monitor('android://' + serialno, package)

    outfd = None
    if output_file:
        outfd = open(output_file, 'w')

    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s' * len(items)
    if syscpu:
        format += '%-12s' * 2
        items += ['SYSAVGCPU', 'SYSALLCPU']

    print format % tuple(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))

        #cpu = app.dev.cpuinfo(package)
        values.append(str(m.cpu()))

        mem = m.memory()  #app.dev.meminfo(package)
        for item in mem_items:
            v = int(mem.get(item, 0)) * 1024

            if human_readable:
                v = humanize.naturalsize(int(v))
            values.append(str(v))

        if syscpu:
            syscpus = m.sys_cpu(True)
            cpustr = '|'.join([str(round(v, 2)) for v in syscpus])
            sysavg = sum(syscpus) / len(syscpus)
            values += [str(round(sysavg, 2)), cpustr]

        print format % tuple(values)
        if outfd:
            outfd.write((format + '\n') % tuple(values))
            outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
Exemple #2
0
    def airConnect(self):
        device = self.cbDevice.currentText()
        phoneno = self.cbPhoneno.currentText()
        try:
            self.app = airtest.connect(str(phoneno),
                                       device=str(device),
                                       monitor=False)
            self.app.globalSet(image_match_method='template', threshold=0.7)
        except Exception as e:
            print 'CONNECT FAILED: %s' % (str(e))
        else:
            self.cbDestdir.clear()
            self.cbDestdir.addItem('image-%d_%d' %
                                   (self.app.width, self.app.height))
            self.cbDestdir.addItem('image-' + str(device))
            self.cbDestdir.addItem('image')

            suffix = '-%dx%d.png' % (self.app.width, self.app.height)
            tmpname = tempfile.mktemp(prefix='', suffix=suffix, dir='')
            print tmpname
            self.leCrop1.setText(tmpname)
        # self.textBrowser.clear()
        # code = "app=airtest.connect(\""+str(phoneno)+"\",device=\""+str(device)+"\")"
        # self.textBrowser.append(code)
        self.airRefresh()
        self.textBrowser.setFocus()
Exemple #3
0
def connect():
    global app
    device = flask.request.args.get('device')
    devno = flask.request.args.get('devno')
    try:
        app = airtest.connect(devno, device=device, monitor=False)
    except Exception, e:
        return flask.jsonify(dict(success=False, message=str(e)))
Exemple #4
0
def connect():
    global app
    device = flask.request.args.get('device')
    devno = flask.request.args.get('devno')
    try:
        app = airtest.connect(devno, device=device, monitor=False)
    except Exception, e:
        return flask.jsonify(dict(success=False, message=str(e)))
Exemple #5
0
def test_android_getsysinfo():
    devs = airtest.getDevices()
    if not devs:
        pytest.skip('not devices detected')
    if devs:
        phoneNo, phoneType = devs[0]
    print phoneNo
    app = airtest.connect(phoneNo, device='android')
    print app.dev.getdevinfo()
Exemple #6
0
def test_android_getsysinfo():
    devs = airtest.getDevices()
    if not devs:
        pytest.skip('not devices detected')
    if devs:
        phoneNo, phoneType = devs[0]
    print phoneNo
    app = airtest.connect(phoneNo, device='android')
    print app.dev.getdevinfo()
Exemple #7
0
def test_connect_monitor():
    ap = airtest.connect('test-connect', appname='hello', device='dummy', monitor=False, logfile='log/1')
    ap.dev._getCpu = False
    time.sleep(2.0)
    assert ap.dev._getCpu == False
    ap.globalSet(enable_monitor=False)

    ap = airtest.connect('test-connect', appname='hello', device='dummy', monitor=True, logfile='log/2')
    ap.dev._getCpu = False
    time.sleep(2.0)
    assert ap.dev._getCpu == True
    ap.globalSet(enable_monitor=False)

    ap = airtest.connect('test-connect', appname='hello', device='dummy', logfile='log/3')
    ap.dev._getCpu = False
    time.sleep(2.0)
    assert ap.dev._getCpu == True
    ap.globalSet(enable_monitor=False)
Exemple #8
0
def watch(conf, package, interval, serialno, human_readable, output_file):
    if not package:
        apk = _get_apk(conf, cache=True)
        package, _ = androaxml.parse_apk(apk)

    app = airtest.connect(phoneno=serialno, device=airtest.ANDROID, monitor=False)

    # print app.dev.getdevinfo()
    outfd = None
    if output_file:
        outfd = open(output_file, 'w')

    mem_items = ['PSS', 'RSS', 'VSS']
    items = ['TIME', 'CPU'] + mem_items
    format = '%-12s'*len(items)
    print format % tuple(items)
    while True:
        time_start = time.time()
        values = []
        values.append(time.strftime('%H:%M:%S'))
        
        cpu = app.dev.getCpu(package)
        values.append(str(cpu))

        mem = app.dev.getMem(package)
        for item in mem_items:
            v = int(mem.get(item))*1024
            if human_readable:
                v = humanize.naturalsize(int(v))
            values.append(str(v))

        print format % tuple(values)
        if outfd:
            outfd.write((format + '\n') % tuple(values))
            outfd.flush()

        sleep = interval - (time.time() - time_start)
        if sleep > 0:
            time.sleep(sleep)
Exemple #9
0
    def airConnect(self):
        device = self.cbDevice.currentText()
        phoneno = self.cbPhoneno.currentText()
        try:
            self.app = airtest.connect(str(phoneno), device=str(device), monitor=False)
            self.app.globalSet(image_match_method='template', threshold=0.7)
        except Exception as e:
            print 'CONNECT FAILED: %s' %(str(e))
        else:
            self.cbDestdir.clear()
            self.cbDestdir.addItem('image-%d_%d'%(self.app.width, self.app.height))
            self.cbDestdir.addItem('image-'+str(device))
            self.cbDestdir.addItem('image')

            suffix = '-%dx%d.png'%(self.app.width, self.app.height)
            tmpname = tempfile.mktemp(prefix='', suffix=suffix, dir='')
            print tmpname
            self.leCrop1.setText(tmpname)
        # self.textBrowser.clear()
        # code = "app=airtest.connect(\""+str(phoneno)+"\",device=\""+str(device)+"\")"
        # self.textBrowser.append(code)
        self.airRefresh()
        self.textBrowser.setFocus()
Exemple #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
nija test example
'''

import sys
import os
import airtest
import time

serialno = os.getenv('AIRTEST_PHONENO') or '10.242.62.143:5555'
appname  = os.getenv('AIRTEST_APPNAME') or 'com.netease.rz'
device = os.getenv('DEVICE') or 'android'

app = airtest.connect(serialno, appname=appname, device=device)

try:
    while True:
        app.sleep(10)
        app.takeSnapshot('%d.png' % int(time.time()))
except KeyboardInterrupt:
    print 'Exit'

Exemple #11
0
def snapshot(phoneno, platform, out):
    try:
        app = airtest.connect(phoneno=phoneno, device=platform)
        app.takeSnapshot(out)
    except Exception, e:
        click.echo(e)
Exemple #12
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
nija test example
'''

import sys
import os
import airtest

serialno = os.getenv('AIRTEST_PHONENO')
appname = os.getenv('AIRTEST_APPNAME')
device = os.getenv('DEVICE') or 'android'

app = airtest.connect(serialno, appname=appname, device=device)
print 'connected'

app.stop()
app.sleep(4)
app.start()

app.sleep(5)  # wait for start loading
app.click('youke.png')  # 游客入口
app.sleep(15)  # wait for loading

# 领取奖励
if app.clickIfExists('reward.png'):
    app.click(app.center())
app.sleep(5)

# 关闭公告板
Exemple #13
0
def snapshot(phoneno, platform, out):
    try:
        app = airtest.connect(phoneno, device=platform)
        app.takeSnapshot(out)
    except Exception, e:
        click.echo(e)
Exemple #14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#coding: utf-8

import sys
reload(sys)
sys.setdefaultencoding('utf8')

import airtest
import os
import cv2
import time

app = airtest.connect('shit', device='dummy')
screenFile = 'testdata/dummy/default.png'
app.globalSet(image_dirs=['testdata/dummy', '.'])
app.globalSet(image_match_method='template')
app.globalSet(threshold=0.8)

ICON = 'testdata/dummy/add.png'

def setup_function(f):
    app.dev._snapshot = screenFile
    app.dev._text = ''
    app.dev._click = None

def test_locate_image():
    # ap = airtest.connect('test-connect', appname='hello', device='dummy', monitor=False, logfile='log/1')
    app.dev._snapshot = 'testdata/dummy/h15_bg.png'
    print 'get method=', app.globalGet('image_match_method')