XCUIApplication replacements for UIATarget captureScreenWithName()

淺唱寂寞╮ 提交于 2019-12-11 06:38:40

问题


We are trying to migrate from UIAutomation to XCUITests and did use the captureScreenWithName() API to programmatically generate screen shots. What is the replacement in the XCUITests ? (I know that automatically screenshots are taken in case of error, but we have a special test which runs forever in a loop and evaluates QA click,tap commands via network similar to the appium-xcuitest-driver https://github.com/appium/appium-xcuitest-driver) Do I need to rip out private headers (XCAXClient_iOS.h) like the appium guys did in order to get a screenshot API?

Edit I used the actual code line for the accepted solution from https://github.com/fastlane/fastlane/blob/master/snapshot/lib/assets/SnapshotHelper.swift and its just this for IOS

 XCUIDevice.sharedDevice().orientation = .Unknown

or in objC

[XCUIDevice sharedDevice].orientation =UIInterfaceOrientationUnknown;

I use a process on the host to lookup in the "Logs/Test/Attachments" directory all Screenshot_*.png files before the call , and find the new shot then after the call as the new file added in this directory.


回答1:


Gestures (taps, swipes, scrolls...) cause screenshots, and screenshots are also often taken while locating elements or during assessing expectations.

Fastlane's snapshot tool uses a rotation to an unknown orientation to trigger a screenshot event (which has no effect on the app): https://github.com/fastlane/fastlane/tree/master/snapshot - you can use this if you want to be in control of some screenshots.



来源:https://stackoverflow.com/questions/39300947/xcuiapplication-replacements-for-uiatarget-capturescreenwithname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!