doronz88 / pymobiledevice3

Pure python3 implementation for working with iDevices (iPhone, etc...).
https://discord.gg/52mZGC3JXJ
GNU General Public License v3.0
1.34k stars 186 forks source link

XCUITestService can not start WebDrivierAgent #870

Open Zhangyu754178 opened 6 months ago

Zhangyu754178 commented 6 months ago

The XCUITestService has started the WebDriverAgent (WDA), but in reality, WDA is not running on the device.

dokisha commented 6 months ago

Command below is not launching WDA: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

More info: Cloned latest WDA, first wanted to confirm that WDA can be launched on device with Product => Test from Xcode => result: WDA is installed and launched on device because:

Stopped the launched WDA on device with Product => Stop (WDA is still installed on the device) then tried to re-launch it with pymobiledevice3: sudo pymobiledevice3 remote tunneld # tunnel is working

launched WDA with command: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

output:

pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO make channel dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO conn1 handshake xcode version: 36
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO conn2 handshake xcode version: 36
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO ProcessOutput: OutputReceivedEvent(pid=2352, date=None, message='2024-03-05 09:16:16.941069+0100 WebDriverAgentRunner-Runner[2352:1741526] [Default] Running tests...\n')
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO Runner started with pid:2352, waiting for testBundleReady
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO authorizing test session for pid 2352 successful True

result:

also tried to launch wda with commands: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --rsd RSD

pymobiledevice3 developer dvt launch com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

pymobiledevice3 developer dvt launch com.facebook.WebDriverAgentRunner.xctrunner --rsd RSD

xcrun devicectl device process launch --device UDID com.facebook.WebDriverAgentRunner.xctrunner

All commands above execute without errors, but WDA is not launched on the device. I think WDA process is launched but it exits with error, so will try to get it's logs if that would help.

pymobiledevice3 version: 2.44.0 -- can try installing latest version from sources mac osx version: Sonoma 14.3.1 (i386) -- can try on arch64 iphone os version: tried on devcies with os 17.3.1 and 17.3 xcode version: 15.2 -- can try on v14

I have tried most of the pymmobiledevice3 commands and they work flawlessly on many devices, so far only xcuitest command is not working.

Please advise if I'm doing something wrong in the steps, or if you need additional information regarding any step.

Thank you for your time.

HaoWShi commented 6 months ago

Mark, I have same question as you, Looking forward to the reply.

kiethen commented 6 months ago

Yeah, the same question, Please

doronz88 commented 6 months ago

I don't think iOS 17 is supported for XCUITest. Feel free to submit a PR for that

HaoWShi commented 6 months ago

Fortunately, I found a way to launch WDA on IOS by clicking on the icon after installing WDA. Refer to the following links: https://blog.csdn.net/boildoctor/article/details/123588999 https://zhuanlan.zhihu.com/p/673319266

1)deploy wda to IOS by xcode, trust the phone device 2)Build wda by xcode, and remember the output path of build. 3)do $ xcodebuild build-for-testing -scheme WebDriverAgentRunner -sdk iphoneos -configuration Release -derivedDataPath /tmp/derivedDataPath $ cd /tmp/derivedDataPath $ cd Build/Products/Release-iphoneos # path might be different Created folderPayloadand put.appinto it then compressed to zip, change extention name to.ipa. That's all. $ mkdir Payload && cp -r *.app Payload 4) delete XC** folder in WebDriverAgentRunner-Runner.app/Frameworks 5) Reconstructing Signature Information Refer the https://blog.csdn.net/boildoctor/article/details/123588999 I use the '方法2', Finally, a message indicating that the signature is being replaced is obtained. 6) use 'zip -r WDA.ipa Payload' to deploy wda, and install WDA.ipa to iphone

After the preceding steps are performed, you can directly click the wda icon on the mobile phone to start the wda.

ghb0224 commented 4 months ago

以下命令未启动 WDA: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

详细信息:克隆最新的 WDA,首先想确认 WDA 可以在设备上启动 Product => Test from Xcode => 结果:WDA 已在设备上安装并启动,因为:

  • 屏幕变暗,屏幕上显示“自动化正在运行”消息
  • 命令返回 json 响应curl http://iphone_ip:8100/status
  • 命令显示流程和值xcrun devicectl device info processes --device UDID --quiet --json-output -``executable``processIdentifier
  • 命令还显示 pid 和 bundleIdentifierpymobiledevice3 developer dvt proclist --rsd fd50:4c2d:43d5::1 60147 | grep Runner

在设备上使用 Product => Stop (WDA 仍安装在设备上) 停止启动的 WDA,然后尝试使用 pymobiledevice3 重新启动它: # 隧道正在工作sudo pymobiledevice3 remote tunneld

使用命令启动 WDA: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

输出:

pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO make channel dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO conn1 handshake xcode version: 36
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO conn2 handshake xcode version: 36
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO ProcessOutput: OutputReceivedEvent(pid=2352, date=None, message='2024-03-05 09:16:16.941069+0100 WebDriverAgentRunner-Runner[2352:1741526] [Default] Running tests...\n')
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO Runner started with pid:2352, waiting for testBundleReady
pymobiledevice3.services.dvt.testmanaged.xcuitest[6318] INFO authorizing test session for pid 2352 successful True

结果:

  • WDA 未启动,因为屏幕未变暗,并且没有消息“自动化正在运行”
  • curl to 返回错误:“无法连接到IPHONE_IP端口 8100”http://iphone_ip:8100/status
  • iPhone 设备上没有 WDA 进程(使用 DVT Proclist 和 DeviceCTL 检查)

还尝试使用命令启动 WDA: pymobiledevice3 developer dvt xcuitest com.facebook.WebDriverAgentRunner.xctrunner --rsd RSD

pymobiledevice3 developer dvt launch com.facebook.WebDriverAgentRunner.xctrunner --tunnel UDID

pymobiledevice3 developer dvt launch com.facebook.WebDriverAgentRunner.xctrunner --rsd RSD

xcrun devicectl device process launch --device UDID com.facebook.WebDriverAgentRunner.xctrunner

上述所有命令执行时均未出错,但未在设备上启动 WDA。我认为WDA进程已启动,但它退出错误,因此如果有帮助,将尝试获取其日志。

pymobiledevice3 版本:2.44.0 -- 可以尝试从源代码安装最新版本 Mac OSX 版本:Sonoma 14.3.1 (i386) -- 可以在 Arch64 上试用 iPhone 操作系统版本:在 OS 17.3.1 和 17.3 的 Devcies 上试用 Xcode 版本:15.2 -- 可以在 v14 上试用

我已经尝试了大多数pymmobiledevice3命令,它们在许多设备上都能完美运行,到目前为止,只有命令不起作用。xcuitest

如果我在步骤中做错了什么,或者您是否需要有关任何步骤的其他信息,请告知。

感谢您抽出宝贵时间接受采访。

一样的问题

yehe01 commented 4 months ago

I am encountering a similar issue on iOS 17.4 using the latest WDA build. I am able to run pymobiledevice3 developer dvt launch .... It can launch the WDA runner and dim the screen. But pymobiledevice3 developer dvt xcuitest doesn't work.

ghb0224 commented 4 months ago

pymobiledevice3 developer dvt xcuitest

不起作用是什么意思,不能控制吗

yehe01 commented 4 months ago

pymobiledevice3 developer dvt xcuitest

不起作用是什么意思,不能控制吗

就是没有反应。WDA没有起来,automation那个半透明窗口也没有出现。

ghb0224 commented 4 months ago

pymobiledevice3 开发人员 dvt xcuitest

不起作用是什么意思,不能控制吗

就是没有反应。WDA没有起来,automation那个半透明窗口也没有出现。

幸运的是,我找到了一种在安装WDA后通过单击图标在IOS上启动WDA的方法。请参阅以下链接:https://blog.csdn.net/boildoctor/article/details/123588999 https://zhuanlan.zhihu.com/p/673319266

1)通过xcode将wda部署到IOS,信任手机设备 2)通过xcode构建wda,并记住构建的输出路径。 3)做 Payload.app.ipa 4)删除 WebDriverAgentRunner-Runner.app/Frameworks 中的XC*文件夹 5)重建签名信息 参考 https://blog.csdn.net/boildoctor/article/details/123588999 我使用“方法2”,最后,获取一条消息,指示签名正在被替换。 6) 使用“zip -r WDA.ipa Payload”部署 WDA,并将 WDA.ipa 安装到 iphone`$ xcodebuild build-for-testing -scheme WebDriverAgentRunner -sdk iphoneos -configuration Release -derivedDataPath /tmp/derivedDataPath $ cd /tmp/derivedDataPath $ cd Build/Products/Release-iphoneos # path might be different Created folderand putinto it then compressed to zip, change extention name to``. That's all. $ mkdir Payload && cp -r .app Payload `

完成上述步骤后,可以直接点击手机上的wda图标启动wda。

我也完成了这一步,但让PC端控制ios设备还是无法完成,我想通过pc端访问localhost:8100,但无法实现

ghb0224 commented 4 months ago

pymobiledevice3 开发人员 dvt xcuitest

不起作用是什么意思,不能控制吗

就是没有反应。WDA没有起来,automation那个半透明窗口也没有出现。

我也是一样的效果, 使用@HaoWShi 提出的方式可以实现automation running,可是如何让PC端收到信息呢

dokisha commented 4 months ago

Until pymobiledevice3 developer dvt xcuitest get implemented, you have two options:

  1. Build WDA on mac machine, manually launching it via Xcode:
  1. Build WDA on machine (all steps above), after wda is installed on iphone, launch it with xcodebuild
    wda_project = "/Users/test/WebDriverAgent/WebDriverAgent.xcodeproj"
    prebuilt_wda_path = "/Users/test/Library/Developer/Xcode/DerivedData/WebDriverAgent-gdqlwadgvhoockackiofynpqxxx"
    wda_bundle_id = "com.facebook.WebDriverAgentRunner.xctrunner"
    xcodebuild test-without-building -project #{wda_project} -scheme WebDriverAgentRunner -destination id=#{UDID} -derivedDataPath #{prebuilt_wda_path}

    you can probably also build wda with command above by adding build-for-testing to it, but haven't tried that yet.

@ghb0224

  1. After launching WDA with Xcode or with xcodebuild command, WDA is running on 8100 port on iphone device, you can't control it via localhost:8100 until you run:
    pymobiledevice3 usbmux forward --serial <UDID> 8100 8100

    then you can set webDriverAgentUrl to http://127.0.0.1:8100/

this is an example of minimal appium capabilites that work:

caps: {
  automationName: 'xcuitest',
  platformName: 'ios',
  platformVersion: '17.3',
  webDriverAgentUrl: 'http://127.0.0.1:8100',
  udid: 'IPHONE UDID',
  app: "/local/path/to/app_under_test.ipa",
  newCommandTimeout: 0
},
appium_lib: {
  server_url: "http://127.0.0.1:4723"
},
}

hope it helps

Karl0226 commented 4 months ago

Can't run XCUITest on iOS17.4

DicerZ commented 1 month ago

@HaoWShi Thanks a lot for your tip, it works the first time. But after rebooting the device, wda crashes. The ips file indicates that: "reasons":["Library not loaded: @rpath/XCTest.framework/XCTest"]