I want to do some screenshot-snapshot testing for my OSX application. For that obviously, I need the screenshots to be the same size every time. So how can I set the size of the main window of my application in XCUITests?
Asked
Active
Viewed 233 times
2 Answers
1
The test code can't reach into the app code. It's up to the app code to set the window size. The app can check a condition to learn that it is under test and can respond by preparing the interface as desired.

matt
- 515,959
- 87
- 875
- 1,141
-
I as a user can't reach into the internals of the app too, but I have no problem resizing the window. Other test frameworks do not reach into internals of the app as well, but they still resize the window. – Paulius Liekis Sep 14 '21 at 11:37
-
But I do appreciate your answer, I'll see if I can use command line variables or something like that to control the window size. – Paulius Liekis Sep 14 '21 at 11:37
1
I believe your best bet will be to use AppleScript.
tell application "MyApp"
set bounds of front window to {300, 30, 1200, 900}
end tell
300 is top-left-x, 30 is top-left-y, 1200 is width, and 900 is height.
Can you execute an Applescript script from a Swift Application explains how to execute AppleScript in Swift.

Mike Collins
- 4,108
- 1
- 21
- 28