I'm trying to test deep linking of my app using iOS XCTests. To do so I've used the code detailed in several webs:
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safari.launch()
safari.textFields["Address"].tap()
safari.textFields["Address"].typeText("https://web-to-test-deep-link")
safari.keyboards.buttons["Go"].tap()
With this code:
- Safari opens (ok)
- My website is written in the address bar (ok)
- The Go button is pressed (ok)
- Then, above Safari it appears the Open with app banner. This banner mentions MyApp, a text saying "Open in the MyApp app" and the OPEN button".
Then I've tried to add the code to click on this button so my app is open, but I can't do it. I've tried:
safari.buttons["Open"].tap()
without success, the open button is not found and the test fails.
I've used the Accessibility inspector and taking into account the attributes of this banner I've tried this:
safari.buttons["MyApp, Open in the MyApp app, OPEN"].tap()
without success too.
How could I know the code to click on this banner and open my app with the deep link?
EDIT: I've tried this too (without success):
safari.scrollViews
.otherElements
.webViews["WebView"]
.children(matching: .other)
.element
.children(matching: .other)
.element(boundBy: 1)
.buttons["Open"]
.tap()
EDIT 2: Answering drunkencheetah question, safari.debugDescription is very large, but the part corresponding to the Open banner is this:
→Application, 0x104f175b0, pid: 8168, label: 'Safari'
Window (Main), 0x104f117e0, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f28010, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f11c90, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f11b40, {{0.0, 0.0}, {375.0, 812.0}}, identifier: 'SafariWindow?View=Narrow&BarsKeptMinimized=false&UUID=.....&SupportsTabBar=false&UsingLoweredBar=true&UsingUnifiedBar=false'
Other, 0x104f28120, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f10190, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f102a0, {{0.0, 0.0}, {375.0, 44.0}}
Other, 0x104f31b70, {{0.0, 0.0}, {375.0, 44.0}}
Other, 0x104f31c80, {{0.0, 0.0}, {375.0, 44.0}}
Other, 0x104f31d90, {{0.0, 0.0}, {375.0, 44.0}}
Other, 0x104f31ea0, {{0.0, 43.7}, {375.0, 0.3}}
ScrollView, 0x104f31fb0, {{0.0, 0.0}, {375.0, 812.0}}
Other, 0x104f320c0, {{0.0, 0.0}, {375.0, 812.0}}, identifier: 'TabDocument?IsLoadedUsingDesktopUserAgent=false&InReaderMode=false&UUID=.....&IsPrivate=false&IsPageLoaded=true&WebViewProcessID=8169'
WebView, 0x104f321d0, {{0.0, 0.0}, {375.0, 812.0}}, identifier: 'WebView'
WebView, 0x104f322e0, {{0.0, 0.0}, {375.0, 812.0}}
Button, 0x104f323f0, {{0.0, 44.0}, {375.0, 45.7}}, label: 'MyApp, Open in the MyApp app, OPEN'
Other, 0x104f32500, {{342.0, 89.7}, {30.0, 589.3}}, label: 'Vertical scroll bar, 15 pages', value: 0%
Other, 0x104f32610, {{0.0, 646.0}, {375.0, 30.0}}, label: 'Horizontal scroll bar, 1 page', value: 0%
Other, 0x104f32720, {{31.3, 779.0}, {312.3, 30.0}}, label: 'Horizontal scroll bar, 1 page', value: 0%
I can see there is a button "Button, 0x104f323f0, {{0.0, 44.0}, {375.0, 45.7}}, label: 'MyApp, Open in the MyApp app, OPEN'", maybe I'm accessing it with a wrong path?
EDIT 3: After drunkencheetah suggestion of check safari.debugDescription I've finally managed to detect the button with this:
safari.webViews.buttons["MyApp, Open in the FASHIONALIA app, MyApp"].tap()
Now the test detect the button, perform the tap but I expected my app to open (as it happens if I manually tap the button). But the app is not opened, should I do it programmatically in my test code or something like that? I though it would be automatic.