This is a companion discussion topic for the original entry at https://www.raywenderlich.com/8458722-testing-in-ios/lessons/21
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/8458722-testing-in-ios/lessons/21
Iâm following your work on this challenge, and when I run this on my simulator, I my test fails because portrait mode cannot be detected.
EX: My Debugger
" Printing description of isPortrait:
(Bool) isPortrait = <variable not available>
(lldb)"
Thanks!
Sounds strange! Where are you printing the description?
Iâm at the same point where you are stopping.
The only idea I have is that youâre using a different code optimization level than I was. But I changed that a few times and I still couldnât reproduce the problem.
Due to indentation difference, I know that youâre not using the exact final project from the materials. I recommend comparing your version with that one, using Git. If you need help with that, upload it and Iâll have a look!
Hi Jessy
Thank you for this episode of the tutorial.
It looks like the code for checking the UI interaction for iPad doesnât seem to be working in Portrait orientation. It throws the error below.
Failed to get matching snapshot: No matches found for Elements matching predicate ââMasterâ IN identifiersâ from input {(
NavigationBar, identifier: âDogYears.CalculatorViewâ
)}
I used the code below which worked for me.
let masterNavBar: XCUIElement
switch (isPortrait, isiPad) {
case (true, true):
masterNavBar = app.navigationBars["DogYears.CalculatorView"]
masterNavBar.buttons["Master"].tap()
XCTAssert(app.navigationBars["Menu"].exists)
case (false, true):
break
case (_, false):
masterNavBar = app.navigationBars["Master"]
masterNavBar.buttons["Menu"].tap()
XCTAssert(app.navigationBars["Menu"].exists)
XCTAssertFalse(masterNavBar.exists)
}
Please let me know if this is the correct way to do it or should we change the identifier for the navigation bar to âMasterâ for all devices. If yes then where should we do that? Thanks.
Hi Shruti,
I honestly donât know what changed, and at what point, since I created this material.
Having another look at it now, I think the simplest solution might be:
func test_navigationBackToMenu() throws {
let isiPad = UIDevice.current.userInterfaceIdiom == .pad
if !(isiPad && XCUIDevice.shared.orientation.isLandscape) {
app.navigationBars.children(matching: .button).firstMatch.tap()
}
XCTAssert(app.navigationBars["Menu"].exists)
}
Thank you Jessy! It works.