简体   繁体   English

iOS XCTest截图

[英]iOS XCTest take Screenshot

I'm aware of useful tools like facebook/ios-snapshot-test-case but what I'm after is the ability to store a png of the output of a unit test that interacts with a view. 我知道有用的工具,例如facebook / ios-snapshot-test-case,但我想要的是能够存储与视图进行交互的单元测试输出的png功能。

Ideally, I'd like to get it off the simulator and onto the environment running XCode, so that after I run my batch of tests, I have a folder of screenshots of what was rendered. 理想情况下,我希望将其从模拟器中放到运行XCode的环境中,这样,在运行我的一批测试之后,我将获得一个呈现截图的屏幕快照文件夹。

Does anyone know of a framework or workflow that is good for taking screenshots off the simulator? 有谁知道一个框架或工作流程很适合从模拟器中截取屏幕截图?

You can create a function that programmatically captures the UIWindow to a jpg or png. 您可以创建一个以编程方式将UIWindow捕获为jpg或png的函数。 The image can be persisted to disk. 映像可以保存到磁盘。

When your test case completes it can call this function. 测试用例完成后,可以调用此函数。

There are more third party libraries to make screen shots in app, you don't need to program it yourself. 有更多的第三方库可在应用程序中进行屏幕截图,您无需自己对其进行编程。 I needed it just once and I tried KSScreenShot. 我只需要一次,就尝试了KSScreenShot。 It wasn't perfect but for my purpose it was enought. 这不是完美的,但就我的目的而言,这是足够的。

The awesome snapshot can do this. 很棒的快照可以做到这一点。 I use it to generate the App Store screenshots. 我用它来生成App Store屏幕截图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM