XCUITest : "Error loading video" when test is run from command line but works fine when run from Xcode

I have a test for an app that picks a video form the Photos app.

func selectVideo(name: String) {
    app.scrollViews.otherElements.images[name].tap()
    sleep(3)
}

This test works fine when I run it from Xcode. App opens Photos, clicks on the video app.scrollViews.otherElements.images[name].tap() , and video is added.

But when I run it from the command line using command:

test \ -project "My App.xcodeproj" \ -scheme MyAppUITests \ -destination 'platform=iOS Simulator,name=iPhone 14'

When app.scrollViews.otherElements.images[name].tap() is done, I get the error in the screenshot.

I verified both Xcode and command line build is using the same Simulator by checkin it's id. I am using the same scheme and config too.

What could be the issue here?

XCUITest : "Error loading video" when test is run from command line but works fine when run from Xcode
 
 
Q