Challenge: Multiple Devices | raywenderlich.com


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?

Screen Shot 2020-06-25 at 7.52.35 PM

I’m at the same point where you are stopping.

Screen Shot 2020-06-26 at 9.04.12 AM

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)
}
1 Like

Thank you Jessy! It works.

1 Like