npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bat-automator

v2.1.5

Published

bat-automator

Downloads

29

Readme

bat-automator 设备操控库

  • 支持 Android、iOS 设备

原理

  • 使用 scrcpy 来做 android 设备录屏以绕开 adb screenrecord 在部分机型不可用问题:brew install scrcpy
  • 用 adb 来操控 android 设备:brew install android-platform-tools
  • 用 tidevice 来操控 iOS 设备:pip3.9 install -U tidevice
    • 用 tidevice 的 relay 做端口映射,有一个 60s 左右的启动耗时,所以换成用 iProxy 做端口映射
  • 用 ios-minicap 做 iOS 录屏(自动安装)
    • 废弃
  • 用 ffmpeg 做视频分帧:ffmpeg 的安装
  • 统一 node18

支持能力

能力列表

  • 启停 APP
  • 模拟划屏
  • 元素点击、输入
  • 设备录屏
  • 设备截屏

能力示例

示例均针对 Android 设备

启停 APP
const automator = require('bat-automator');

// 设备号
let deviceId = 'abc';

// APP 包名
let baiduPackageName = 'com.baidu.searchbox';
let baiduMainActivity = 'com.baidu.searchbox.MainActivity';

const main = async () => {
    // 获取设备句柄
    let device = await automator.launch(deviceId);

    // 停止 APP
    await device.closeApp(baiduPackageName);

    // 各类操作
    // ...

    // 启动 APP
    await device.launchApp(baiduPackageName, baiduMainActivity);
};
模拟划屏
const automator = require('bat-automator');

// 设备号
let deviceId = 'abc';

const main = async () => {
    // 获取设备句柄
    let device = await automator.launch(deviceId);

    // 模拟手指从 (0, 0) 划到 (1, 1)
    await device。swipe(0, 0, 1, 1);
};
元素点击
const automator = require('bat-automator');

// 设备号
let deviceId = 'abc';

const main = async () => {
    // 获取设备句柄
    let device = await automator.launch(deviceId);

    // 获取元素
    let element = await device.$x('//node[@text="我的"]');

    // 元素点击
    await element.tap();
};
元素输入
const automator = require('bat-automator');

// 设备号
let deviceId = 'abc';

const main = async () => {
    // 获取设备句柄
    let device = await automator.launch(deviceId);

    // 获取元素
    let element = await device.$x('//node[@text="搜索"]');

    // 元素输入
    await element.input("龙霸天好吃吗");
};
设备录屏
const automator = require('bat-automator');

// 设备号
let deviceId = 'abc';

// 录屏存储路径
let videoPath = '/Users/data/video.mp4';

const main = async () => {
    // 获取设备句柄
    let device = await automator.launch(deviceId);

    // 启动录屏
    let video = await device.record(videoPath);

    // 各类操作
    // ...

    // 结束录屏
    await video.kill();
};