uiXCUITest - 如何从Google Mobile Ads SDK访问WebView屏幕上的UI元素



我正在使用XCUITest进行UI测试自动化,大多数应用程序只是本机的,我可以通过accessibilityIdentifiers或简单地通过label访问元素。我在测试广告打开时遇到问题,因为我无法访问广告 WebView 屏幕上的关闭按钮。Web 视图来自 Google Mobile Ads SDK for iOS。

我尝试使用app..buttons["Close Advertisement"].tap()访问该元素,但它不起作用,它从未点击关闭按钮。

当我在调试器中尝试时po XCUIApplication().buttons["Close Advertisement"].tap()返回我:

t =    67.80s     Tap "Close Advertisement" Button
t =    67.80s         Wait for ios.development to idle
t =    67.82s         Find the "Close Advertisement" Button
t =    67.86s         Check for interrupting elements affecting "Close Advertisement" Button
t =    67.89s         Synthesize event
t =    67.98s         Wait for ios.development to idle
0 elements

这是我执行po XCUIApplication().debugDescription时屏幕的完整层次结构

Window (Main), 0x600003cd47e0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630778878896.4>
Other, 0x600003cd4700, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630742447520.6>
Other, 0x600003cd4620, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630742449600.8>
Other, 0x600003cd4540, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630742912976.229>
Other, 0x600003cd4460, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630739951984.230>
Button, 0x600003cd4380, {{0.0, 0.0}, {42.0, 42.0}}, label: 'Close Advertisement', Disabled <AX element pid: 67431, elementOrHash.elementID: 140630739216816.231>
Other, 0x600003cd42a0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630777385136.232>
WebView, 0x600003cd40e0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630769439744.233>
WebView, 0x600003cd4000, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630768846336.236>
WebView, 0x600003cd4e00, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630769495040.237>
Other, 0x600003cd4ee0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 5843420293174919168.9999>
Other, 0x600003cd4fc0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233423230208.3>
Other, 0x600003cd50a0, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421369008.4>
Other, 0x600003cd5180, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421369040.5>
Other, 0x600003cd5260, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421402864.6>
Other, 0x600003cd5340, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421478464.7>
Other, 0x600003cd5420, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421481056.9>
Other, 0x600003cd5500, {{159.0, 303.0}, {57.0, 61.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421480800.10>
Other, 0x600003cd55e0, {{327.0, 0.0}, {48.0, 48.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421483680.11>
Other, 0x600003cd56c0, {{327.0, 0.0}, {48.0, 48.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421488304.19>
Other, 0x600003cd57a0, {{339.0, 12.0}, {24.0, 24.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421489808.22>
Other, 0x600003cd5880, {{339.0, 12.0}, {24.0, 24.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421486112.23>
Other, 0x600003cd5960, {{0.0, 0.0}, {375.0, 24.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421483712.12>
Other, 0x600003cd5a40, {{8.0, 635.0}, {24.0, 28.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421482512.13>
Other, 0x600003cd5b20, {{40.0, 627.0}, {8.0, 40.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421482544.14>
Other, 0x600003cd5c00, {{0.0, 0.0}, {0.0, 0.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421492128.20>
Other, 0x600003cd5ce0, {{34.0, 662.0}, {6.0, 5.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421482608.15>
Other, 0x600003cd5dc0, {{0.0, 662.0}, {48.0, 5.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421484160.16>
Other, 0x600003cd5ea0, {{253.0, 624.0}, {111.0, 31.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421484192.17>
Other, 0x600003cd5f80, {{253.0, 624.0}, {111.0, 31.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421496224.21>
StaticText, 0x600003cd6060, {{277.0, 632.0}, {62.0, 15.0}}, label: 'Learn More' <AX element pid: 67437, elementOrHash.elementID: 140233421493056.24>
Other, 0x600003cd6140, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421484256.18>
Other, 0x600003cd6220, {{0.0, 0.0}, {25.0, 20.0}} <AX element pid: 67437, elementOrHash.elementID: 140233421478944.8>
Other, 0x600003cc9180, {{342.0, 0.0}, {30.0, 667.0}}, label: 'Vertical scroll bar, 1 page', value: 0% <AX element pid: 67431, elementOrHash.elementID: 140630777539728.238>
Other, 0x600003cc9260, {{0.0, 634.0}, {375.0, 30.0}}, label: 'Horizontal scroll bar, 1 page', value: 0% <AX element pid: 67431, elementOrHash.elementID: 140630777538944.239>
Other, 0x600003ce32c0, {{0.0, 0.0}, {376.0, 668.0}} <AX element pid: 67431, elementOrHash.elementID: 140630826768976.234>
StaticText, 0x600003ce31e0, {{160.0, 0.0}, {55.5, 22.0}}, label: 'Test Ad' <AX element pid: 67431, elementOrHash.elementID: 140630826625872.235>
Window, 0x600003ce3100, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630783264592.5>
Other, 0x600003cf4540, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630777978208.7>
Other, 0x600003cd6300, {{0.0, 0.0}, {375.0, 667.0}} <AX element pid: 67431, elementOrHash.elementID: 140630742527888.9>```

嗨,有几个解决方案。

  1. 您想测试广告吗?如果没有,那么您可以做的是使用 launchArguments 禁用广告。这样,您就不必担心处理广告。
  2. 如果您无法禁用广告,则获取广告关闭按钮的屏幕坐标。这可以通过获取 Web 视图容器并相对计算关闭按钮点击区域的坐标来完成。然后它只是屏幕上的点击功能调用。

相关内容

  • 没有找到相关文章

最新更新