How to use the airtest.base function in airtest

To help you get started, we’ve selected a few airtest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NetEase / airtest / airtest / trash / android.py View on Github external
def wait(self, imgfile, seconds=20):
        '''
        Wait until some picture exists
        @return position when imgfile shows
        '''
        interval = 1
        max_retry = int(seconds/interval)
        pt = base.wait_until(self.find, args=(imgfile,), interval=interval, max_retry=max_retry)
        if not pt:
            raise RuntimeError('wait fails')
        self._last_point = pt
        return pt
github NetEase / airtest / airtest / trash / android.py View on Github external
def getCpu(serialno, package):
    '''
    @param package(string): android package name
    @return float: the cpu usage
    '''
    command = 'adb -s %s shell dumpsys cpuinfo' % serialno
    cpu_info = base.check_output(command).splitlines()
    try:
        xym_cpu = filter(lambda x: package in x, cpu_info)[0].split()[0]
        cpu = float(xym_cpu[:-1])
        log.info("cpu_info:%s" % cpu)
        return cpu
    except IndexError:
        log.error("cpu_info error")
        return 0
github NetEase / airtest / airtest / devsuit.py View on Github external
def _saveScreen(self, filename, random_name=True, tempdir=True):
        # use last snapshot file
        if self._snapshot_file and self._keep_capture:
            return self._snapshot_file

        if random_name:
            filename = base.random_name(filename)
        if tempdir:
            filename = os.path.join(self._tmpdir, filename)

        parent_dir = os.path.dirname(filename) or '.'
        if not os.path.exists(parent_dir):
            base.makedirs(parent_dir)

        # FIXME(ssx): don't save as file, better store in memory
        self.dev.snapshot(filename)

        if tempdir:
            self.log(proto.TAG_SNAPSHOT, dict(filename=filename))
        self._snapshot_file = filename
        return filename
github NetEase / airtest / test / test_base.py View on Github external
def test_exec_cmd():
    if platform.system() == 'Linux':
        base.exec_cmd('echo', 'hello')
github NetEase / airtest / airtest / devsuit.py View on Github external
def _saveScreen(self, filename, random_name=True, tempdir=True):
        # use last snapshot file
        if self._snapshot_file and self._keep_capture:
            return self._snapshot_file

        if random_name:
            filename = base.random_name(filename)
        if tempdir:
            filename = os.path.join(self._tmpdir, filename)

        parent_dir = os.path.dirname(filename) or '.'
        if not os.path.exists(parent_dir):
            base.makedirs(parent_dir)

        # FIXME(ssx): don't save as file, better store in memory
        self.dev.snapshot(filename)

        if tempdir:
            self.log(proto.TAG_SNAPSHOT, dict(filename=filename))
        self._snapshot_file = filename
        return filename
github NetEaseGame / ATX / atx / jsonlog.py View on Github external
def writeline(self, d, *args):
        '''
        @param d (dict or string): content needed write to file
        @param args(array): only when d is string, support writeline('hello %s', 'world')
        '''
        with Lock(self._lock) as _:
            base.makedirs(base.dirname(self._filename))
            with open(self._filename, 'a') as file:
                if isinstance(d, dict):
                    d.update({'timestamp': int(time.time())})
                    outline = json.dumps(d)
                else:
                    outline = str(d) % args
                file.write(outline.rstrip() + '\n')