Home > Back-end >  How to set window size in XCUITest?
How to set window size in XCUITest?

Time:09-17

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?

CodePudding user response:

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.

CodePudding user response:

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.

  • Related