gpt4 book ai didi

iOS Webview UI 测试

转载 作者:行者123 更新时间:2023-11-28 23:56:42 24 4
gpt4 key购买 nike

在基于 ionic 框架的 iOS 应用程序的 UI 测试期间无法访问 UI 元素。例如,我想点击标签为“home Home”的按钮。

下面是我的应用程序的调试描述,显示了元素层次结构。

Element subtree:

→Application, 0x600000398bb0, pid: 18354, {{0.0, 0.0}, {414.0, 736.0}}, label: 'FastlaneHelper'
Window, 0x6000003998b0, Main Window, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000398c80, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000398d50, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
WebView, 0x600000398e20, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000398ef0, traits: 35192962023424, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000398fc0, {{0.0, 0.0}, {0.0, 0.0}}
Other, 0x600000399090, {{0.0, 0.0}, {0.0, 0.0}}
Other, 0x600000380750, traits: 146029019136, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000399230, traits: 146029019136, {{0.0, 0.0}, {414.0, 736.0}}, label: 'Ionic App'
Other, 0x6000003994a0, traits: 146029019136, {{0.0, 686.0}, {414.0, 51.0}}
Button, 0x6000003997e0, traits: 146297454600, {{0.0, 687.0}, {138.0, 49.0}}, label: 'home Home'
Button, 0x600000399640, traits: 146297454592, {{138.0, 687.0}, {138.0, 49.0}}, label: 'information circle-outline About'
Button, 0x600000399710, traits: 146297454592, {{276.0, 687.0}, {138.0, 49.0}}, label: 'contacts outline Contact'
Other, 0x600000399570, traits: 146029019136, {{0.0, 0.0}, {414.0, 736.0}}, label: 'home Home, tab panel'
Other, 0x600000399300, traits: 146029019136, {{90.0, 30.0}, {234.0, 23.0}}
StaticText, 0x6000003993d0, traits: 146029019200, {{183.0, 30.0}, {48.0, 23.0}}, label: 'Home'
Other, 0x6000003809c0, traits: 146029084672, {{16.0, 77.0}, {382.0, 28.0}}, label: 'Welcome to Ionic!', value: 2
StaticText, 0x6000003808f0, traits: 146029084736, {{16.0, 76.0}, {190.0, 29.0}}, label: 'Welcome to Ionic!', value: 2
Other, 0x600000380b60, traits: 146029019136, {{16.0, 119.0}, {382.0, 36.0}}
StaticText, 0x600000380a90, traits: 146029019200, {{16.0, 119.0}, {368.0, 36.0}}, label: 'This starter project comes with simple tabs-based layout for apps that are going to primarily use a Tabbed UI.'
Other, 0x600000380680, traits: 146029019136, {{16.0, 169.0}, {382.0, 36.0}}
StaticText, 0x600000380820, traits: 146029019200, {{16.0, 169.0}, {117.0, 18.0}}, label: 'Take a look at the'
Other, 0x600000399160, traits: 146029019136, {{133.0, 172.0}, {84.0, 15.0}}
StaticText, 0x6000003805b0, traits: 146029019200, {{132.0, 172.0}, {85.0, 15.0}}, label: 'src/pages/'
StaticText, 0x600000399a50, traits: 146029019200, {{16.0, 169.0}, {377.0, 36.0}}, label: 'directory to add or change tabs, update any existing page or create new pages.'
ScrollView, 0x60000039b790, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
Window, 0x60000039b860, {{0.0, 0.0}, {414.0, 736.0}}
StatusBar, 0x60000039b930, {{0.0, 0.0}, {414.0, 20.0}}
Other, 0x60000039ba00, {{0.0, 0.0}, {414.0, 20.0}}
Other, 0x60000039bad0, {{0.0, 0.0}, {414.0, 20.0}}
Other, 0x60000039bc70, traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
Other, 0x60000039bd40, traits: 8388608, {{50.0, 0.0}, {14.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
Other, 0x60000039be10, traits: 8389120, {{181.0, 0.0}, {56.0, 20.0}}, label: '12:32 AM'
Other, 0x60000039bee0, traits: 8388608, {{383.0, 0.0}, {26.0, 20.0}}, label: '87% battery power'

我尝试通过以下方式访问该元素,但没有成功:

let app = XCUIApplication()
let tabs = app.tabBars
tabBars.buttons["Home"].tap()

let app = XCUIApplication()
let tabs = app.windows.tabBars
tabBars.buttons["Home"].tap()

let app = XCUIApplication()
let tabs = app.windows.webViews.tabBars
tabBars.buttons["Home"].tap()

甚至尝试包含元素层次结构中的“其他”元素,但测试失败。谁能帮我们解决这个问题?

最佳答案

您不应搜索标签栏,因为您的应用中没有标签栏。可能有一些视觉上类似于标签栏的东西,但它只是 HTML 内容。您应该寻找 Web View ,然后寻找按钮或静态文本。像这样的东西:

let app = XCUIApplication()
let web = app.webViews
web.buttons["home Home"].tap()

关于iOS Webview UI 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com