STF openstf+tidevice 开源,不依赖 Mac 也能跑 iOS 设备,同时支持一机多控

EasilyTest · February 05, 2021 · Last by jamin replied at March 20, 2023 · 13124 hits
本帖已被设为精华帖!

简介

近期 阿里的内部的一个小组用来做 iOS 自动化用的工具 tidevice ,终于开源了出来。所以就尝试着整合一下这个神奇的资源到 stf 上来
所以这篇文章主要就是来推广一下思路,烦请大家多多指点,可能是全网首发吧。

项目已经开源地址 https://github.com/EasilyTest/stf,请先点个 Star ⭐ ,然后回来在看。

它有什么功能呢?

截图
App 安装,启动,停止,查看
启动 WebDriverAgent
性能采集(类似 PerfDog)不过这块暂时只有 API 可以用。
功能还在不停的扩展中

这么一看,??这不是可以完全替代 xcodebuild 来启动 WebDriverAgent 了吗?那还要什么 Mac,我大 Linux 不香吗?
看过 stf 的 ios 启动方案的人都知道,最大的难点在于如何不依赖 xcode 启动 WebDriverAgent,如果解决了这个问题,那么就没 Mac 什么事情了,甚至可以直接把整个项目 docker 化,来一键部署。

那么问题来了如何实现?简单展示一下(这里会有一个小坑,test 的应用 id 是 com.apple.test......),利用 SubpPocess 模块,来执行 tidevice 操作,或者 execSync 来替换原先的 idevice -l。

  wdaPro = new SubpPocess("tidevice",["-u",options.serial,
          "xctest", "-B","com.apple.test.WebDriverAgentRunner-Runner"])
  wdaPro.start()
  return new Promise((resolve,reject)=>{
    wdaPro.on("exit",(code,signal)=>{
      wdaPro = null;
      bRestart = true
      //plugin.restartWda();
      return resolve()
    });
    wdaPro.on("stream-line",line=>{
      bRestart = false
      log.info("tidevice开始构建")
      log.info(line)
      if (line.indexOf("WebDriverAgent start successfully")!=-1){
        log.info("WDA启动成功")
        wda.launchApp('com.apple.Preferences')
        wda.initSession()
        wda.emit("started");
        bRestart=true
        bRestartCnt = 0
        if(checkTimer===null){
          batteryTimer = setInterval(plugin.getBatteryInfo,300000)
          checkTimer = setInterval(plugin.checkWdaStatus,3000)
        }
        return resolve()
      }

iDevice.prototype.read = function() {
    var stdout = execSync('tidevice list --json',{});
    var out = JSON.parse(stdout.toString());
    var tem = [];
    if(out!=[]){
    for (var i in out) {
        tem.push(out[i].udid.toString())
    }
        ref = tem;
        this.update(ref,'device');
    }else{
      this.update([],'device');
    }
    ref = simtcl.GetBootedSim()
    if(ref){
      this.update(ref,'emulator');
    }
  };

这样就完成了 xcodebuild 到 tidevice 的调用,根据原逻辑直接几行搞定,tidevice 启动 wda 的速度比原来的 xcodebuild 提高了 50 倍以上,实现了 wda 秒启。
直接运行 stf local --public-ip XXX.XXX.XXX.XXX,即可启动,不再需要--wda-path 参数。
同时我们可以对项目进行改造,网上的资料你经常能看到一级多控,多设备显示,但是就是没人开源没人分享,给思路不给代码,我实现了下大致效果图如下

页面核心内容在 stf/res/app/batch-control-panes 目录下,主要还是利用了 localStorage 的特性来存储和修改需要的参数,利用 stf 自带的 standalone 模式做出不同的小页面来展示在页面上。

至此,基于 stf 的一机多控 + 全平台通用已基本实现框架,不同端需要的依赖需要自行编译安装,这里稍微麻烦一些,后续会写个 shell 出来一键操作
,stf 代码也会逐步完善。如果你需要更好的功能或者有更好的思路欢迎 pr

传送门

tidevice 的帖子 https://testerhome.com/topics/27758
stf-ios 的帖子 https://testerhome.com/topics/19548

PS: QQ 群 962526549,如果有问题或者不想提 issue 的可以进群来交流心得

共收到 20 条回复 时间 点赞

特别赞!请教下,如果不在 mac 下,怎么去配置 webdriveragent,而且打包 webdriveragent 对 xcode 的版本有时候也有要求啊。这个如果离开 mac,怎么解决啊

黑山老妖 回复

根据 tidevice 的描述,你需要提前安装 webdriveragent,它提供了一个 ipa 包改一下签名就可以用它安装类似以下形式,
$ tidevice install example.ipa
$ tidevice install https://example.org/example.ipa
也就是说如果你有自己已经打好的包,可以直接通过 tidevice 或者 ideviceinstall 来安装

EasilyTest 回复

感谢回复!stf-ios 有一个逻辑是,当运行 wda 报错时,会重新 build 一个 wda,你的方案是重新安装一次 wda 并启动嘛

运行报错:

黑山老妖 回复

不重新安装,但是会重启执行 tidevice 模拟一遍 xcodebuild 执行

阿三 回复

用 cnpm 吧,依赖没全

你好,和 android 对比起来,操作效率如何

Wei Chuang 回复

ios 实际上和 android 对比起来帧数还是略低一些,所以还是会有部分的卡顿。
这个需要通过视频流来处理

EasilyTest 回复

依赖安装全了,运行 stf local --public-ip XXX.XXX.XXX.XXX 报错

恒温 将本帖设为了精华贴 06 Apr 14:01

这个在 Linux 上怎么 docker 一键部署?我现在想在 Linux(Ubuntu 16.04.5 ) 上实现 ios 的 stf,这些依赖是在宿主机上安装吗?原本这上面部署了 openstf 可以实现 Android 的 stf,这个要怎么兼容 ios 的?

npm install 提示 ng-context-menu 找不到,浏览器访问了下 404。

bower ng-context-menu#~1.0.5                                                 ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/AdiDahan/ng-context-menu.git", exit code of #128 remote: Repository not found. fatal: repository 'https://github.com/AdiDahan/ng-context-menu.git/' not found
迪文 回复

已修复,参考 https://github.com/DeviceFarmer/stf/issues/219

ln -s /usr/local/libsodium/bin/* /usr/local/bin/ libsodium 安装后只有 lib include 目录 没有 bin 目录 老哥

大佬,请教个问题。我这 wda 启动起来了,但是点击进投屏页面, minicap server 连接不上

牛啊,先收藏

18Floor has deleted

Linux 安装不了,很多依赖安装不上

有大佬在 Linux 下成功部署楼主的这套 stf 控制 iOS 吗?

楼主,部署了你的这个 stf,
stf 启动时启动 ios-provider,但没启动成功,进程中并没有看到 ios-provider 进程,可能哪里有问题呢?

stf 启动 ios-provider 的日志:

2023-03-20T12:54:46.398Z INF/util:procutil 8404 [*] Forking "/root/stf/lib/cli ios-provider --name ubuntu-18-04 --min-port 6100 --max-port 6900 --connect-sub tcp://127.0.0.1:7114 --connect-push tcp://127.0.0.1:7116 --group-timeout 900 --public-ip 192.168.2.120 --storage-url http://localhost:7100/ --wda-path /root/stf/WebDriverAgent/ --wda-port 8100 --wda-mjpeg-port 9100 --vnc-initial-size 600x800 --mute-master never --allow-remote"

stf 启动的相关进程:

root       8404  0.0  0.4 884816 39120 pts/1    Sl+  12:54   0:00 node /root/.nvm/versions/node/v8.9.0/bin/stf local --public-ip 192.168.2.120 --allow-remote
root       8416  0.0  0.5 983988 41356 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli triproxy app001 --bind-pub tcp://127.0.0.1:7111 --bind-dealer tcp://127.0.0.1
root       8417  0.0  0.5 984008 41460 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli triproxy dev001 --bind-pub tcp://127.0.0.1:7114 --bind-dealer tcp://127.0.0.1
root       8422  0.0  0.6 989996 52044 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli processor proc001 --connect-app-dealer tcp://127.0.0.1:7112 --connect-dev-dea
root       8429  0.0  0.6 991200 53664 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli processor proc002 --connect-app-dealer tcp://127.0.0.1:7112 --connect-dev-dea
root       8434  0.0  0.6 991220 54456 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli reaper reaper001 --connect-push tcp://127.0.0.1:7116 --connect-sub tcp://127.
root       8440  0.0  0.5 1000064 47044 pts/1   Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli provider --name ubuntu-18-04 --min-port 7400 --max-port 7700 --connect-sub tc
root       8453  0.1  0.5 906772 48748 pts/1    Sl+  12:54   0:01 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli auth-mock --port 7120 --secret kute kittykat --app-url http://192.168.2.120:7
root       8465  0.1  0.6 927156 53116 pts/1    Sl+  12:54   0:01 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli app --port 7105 --secret kute kittykat --auth-url http://192.168.2.120:7100/a
root       8473  0.2  0.9 1073124 77360 pts/1   Sl+  12:54   0:02 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli api --port 7106 --secret kute kittykat --connect-push tcp://127.0.0.1:7113 --
root       8481  0.5  0.7 1001700 61088 pts/1   Sl+  12:54   0:05 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli groups-engine --connect-push tcp://127.0.0.1:7113 --connect-sub tcp://127.0.0
root       8482  0.1  0.6 1029456 56836 pts/1   Sl+  12:54   0:01 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli websocket --port 7110 --secret kute kittykat --storage-url http://localhost:7
root       8495  0.1  0.5 904036 46456 pts/1    Sl+  12:54   0:01 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli storage-temp --port 7102
root       8496  0.0  0.5 901332 42316 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli storage-plugin-image --port 7103 --storage-url http://localhost:7100/
root       8509  0.1  0.5 903448 44644 pts/1    Sl+  12:54   0:01 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli storage-plugin-apk --port 7104 --storage-url http://localhost:7100/
root       8519  0.0  0.5 887240 44156 pts/1    Sl+  12:54   0:00 /root/.nvm/versions/node/v8.9.0/bin/node /root/stf/lib/cli poorxy --port 7100 --app-url http://localhost:7105/ --auth-url http://localho

大佬的这个 stf 在 Linux 下能成功启动 ios-provider 吗?
我看 stf-ios 的作者说 CentOS 下能安装,但不能启动 ios-provider ...

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up