In XCode (as of 14.3) there are two sorts of testing initiatives;
My understanding of them is;
Unit Testing Bundle – nice for White Field testing, can (optionally) entry Host Utility APIs.
UI Testing Bundle – nice for Black Field testing, can not entry Host Utility APIs.
I wish to use the improbable screenshot APIs of XCUIScreenshot as a part of my Unit Testing bundles, however can not appear to get it to work.
A number of issues I’ve tried:
-
outline a XCUIApplication as a part of the XCTestCase init;
app = XCUIApplication()
let screenshot = app.home windows.firstMatch.screenshot()
This clearly works effectively in UI Testing Bundle exams, however when its not a UI Check, the XCUIApplication can’t be created regardless of the scheme. This sort of is smart, as within the UI exams, it expects to handle this factor utterly.
-
use XCUIScreen to create it
let screenshot = XCUIScreen.primary.screenshot()
For the same cause this fails; I’ve tried this on gadget and in simulator, there error is:
Didn’t get screenshot: Not approved for performing UI testing
actions.
My hunch is that the screenshot functionality is admittedly being triggered “exterior the gadget”, and that is simply not potential, however have not discovered any conclusive textual content to say so.
Anybody with perception one course or the opposite?
Footnote; my workaround is to make use of a UI Testing bundle, then bake within the white field code i would like into my app, and set off it by way of command line arguments… but it surely all feels fairly hoop jumpy. I need to do that to generate App Retailer screenshots in addition to take a look at varied elements of my UI, and testing by way of pure button clicks can be, not ultimate 🙂