iOS深链接测试
我正在尝试使用iOS XCTEST测试我的应用程序的深层链接。为此,我使用了几个网络中详细列出的代码:
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()
使用此代码:
- 打开Safari(确定)
- 我的网站写在地址栏中(确定)
- 按下GO按钮(确定),
- 然后,在Safari上方,看起来很开放。使用应用横幅。 上面写着“在MyApp应用程序中打开”和打开按钮。
该横幅提到了MyApp,这是一条文字, 我尝试过:
safari.buttons["Open"].tap()
没有成功,找不到打开按钮,测试失败。
我使用了可访问性检查员并考虑到此横幅的属性,我也尝试过:
safari.buttons["MyApp, Open in the MyApp app, OPEN"].tap()
也没有成功。
我怎么能知道单击此横幅的代码并使用深层链接打开我的应用程序?
编辑:我也尝试过(没有成功):
safari.scrollViews
.otherElements
.webViews["WebView"]
.children(matching: .other)
.element
.children(matching: .other)
.element(boundBy: 1)
.buttons["Open"]
.tap()
编辑2:回答醉酒的问题,safari.debugdescription很大,但是与开放式横幅相对应的部分是:
→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%
我可以看到一个按钮“按钮,“ 0x104f323f0”, {{0.0,44.0},{375.0,45.7}},标签:'myapp,在myapp应用中打开,打开,打开'”,也许我正在用错误的路径访问它?
编辑3: 在醉酒的建议之后,检查safari.debugdescription,我终于设法检测到按钮:
safari.webViews.buttons["MyApp, Open in the FASHIONALIA app, MyApp"].tap()
现在测试检测按钮,执行点击,但我希望我的应用程序打开(如果我手动点击按钮,就会发生这种情况)。但是该应用程序没有打开,我应该在测试代码或类似的内容中以编程方式进行操作吗?我虽然是自动的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论