Post marked as solved
Post marked as solved with 1 replies, 1,435 views
I have a UI test for my app which should take a screenshot of all the relevant screens.
It works nicely for iPhone in portrait but on iPad, where I rotate the device to landscape (using XCUIDevice.shared.orientation = .landscapeLeft), the screenshots are only partially visible. The screenshot is taken in portrait even though the device is currently running in landscape, resulting in the lower section being black and the right part being cut off.
The interesting thing I've noticed: all automatic screenshots taken by Xcode while running individual test steps are created correctly but the one I create myself using the snippet below is cut-off.
Am I doing something wrong?
func takeScreenShot(_ element: XCUIElement, name: String = "Screenshot") {
let screenshot = element.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)
}
in setUp:
override func setUp() {
		let app = XCUIApplication()
	app.launch()
if UIDevice.current.userInterfaceIdiom == .pad {
XCUIDevice.shared.orientation = .landscapeLeft
}
		// ... more unrelated stuff
}
And later while running a test:
XCTContext.runActivity(named: "Image of the day is shown") { (_) in
let dismissButton = app.buttons["dismissImageOfTheDay"].firstMatch
XCTAssert(dismissButton.waitForExistence(timeout: 4.0), "The dismiss button exists")
takeScreenShot(app, name: "00_ImageOfTheDay")
dismissButton.tap()
}