访问Xcode UITest中的app.buttons,没有任何可用于引用的文本。

时间:2021-08-21 19:14:59

So I am trying to get fastlane screenshot working and that means getting Xcode UITest working...I build an Ionic app that uses a 3-bar symbol as a slide-out button and that sort of thing is trivial with webapps.

所以我试图让fastlane截图正常工作,这意味着让Xcode UITest正常工作......我构建了一个使用3条符号作为滑出按钮的Ionic应用程序,而这一点对于webapps来说是微不足道的。

However, when I use uITest record, it misinterprets the button and ends up representing like this

但是,当我使用uITest记录时,它会错误解释按钮并最终代表这样

app.buttons[""].tap()

app.buttons [ “”]。轻按()

When it tries to run the saved UI commands, it obviously chokes on this and crashes the test...is there any other way to represent the button other then using its label text like that?

当它试图运行保存的UI命令时,它显然会窒息并崩溃测试...有没有其他方式来表示按钮,然后使用其标签文本?

It would seem to be that it could use the ID or NAME for the button identifier, but I have yet to find that solution for this problem anywhere.

它似乎可以使用ID或NAME作为按钮标识符,但我还没有在任何地方找到解决此问题的方法。

2 个解决方案

#1


2  

You can give the button an AccessibilityIdentifier, which is a property that will only be read by the UI Tests and which does not require there to be any readable text.

您可以为按钮指定一个AccessibilityIdentifier,这是一个只能由UI测试读取的属性,并且不需要任何可读文本。

You can also give the button an AccessibilityLabel, which will enable your button to be used by people who are using accessibility, such as with screen readers or other such devices.

您还可以为按钮指定AccessibilityLabel,这将使您的按钮可供使用辅助功能的人使用,例如屏幕阅读器或其他此类设备。

Both of these properties can be read by the XCUIElementQuery, which means you will be able to use, e.g., app.buttons["slide_out"].tap().

XCUIElementQuery可以读取这两个属性,这意味着您可以使用例如app.buttons [“slide_out”]。tap()。

In order to do this, you set the accessibilityIdentifier / accessibilityLabel explicitly in code (button.accessibilityIdentifier = "slide_out", for example) or in the Storyboard (under properties; see screenshot).

为此,您可以在代码中明确设置accessibilityIdentifier / accessibilityLabel(例如,button.accessibilityIdentifier =“slide_out”)或在Storyboard中(在属性下;参见屏幕截图)。

访问Xcode UITest中的app.buttons,没有任何可用于引用的文本。

If, on the other hand, there's a timing issue because you need to wait for the element to appear, I recommend Joe Masilotti's blog post about custom helpers in XCUITest: http://masilotti.com/xctest-helpers/

另一方面,如果由于您需要等待元素出现而出现计时问题,我建议Joe Masilotti在XCUITest中关于自定义助手的博客文章:http://masilotti.com/xctest-helpers/

#2


0  

Tipp: In case, anyone tries to access buttons from within an IONIC app and doesn't find out about how to code the 'accessibilityIdentifier' in that IONIC .html and .ts files...

Tipp:如果有人试图从IONIC应用程序中访问按钮,并且没有找到如何在IONIC .html和.ts文件中编码'accessibilityIdentifier'...

aria-label="myLabel"
in the button element does the trick; id, name and so on don't.

#1


2  

You can give the button an AccessibilityIdentifier, which is a property that will only be read by the UI Tests and which does not require there to be any readable text.

您可以为按钮指定一个AccessibilityIdentifier,这是一个只能由UI测试读取的属性,并且不需要任何可读文本。

You can also give the button an AccessibilityLabel, which will enable your button to be used by people who are using accessibility, such as with screen readers or other such devices.

您还可以为按钮指定AccessibilityLabel,这将使您的按钮可供使用辅助功能的人使用,例如屏幕阅读器或其他此类设备。

Both of these properties can be read by the XCUIElementQuery, which means you will be able to use, e.g., app.buttons["slide_out"].tap().

XCUIElementQuery可以读取这两个属性,这意味着您可以使用例如app.buttons [“slide_out”]。tap()。

In order to do this, you set the accessibilityIdentifier / accessibilityLabel explicitly in code (button.accessibilityIdentifier = "slide_out", for example) or in the Storyboard (under properties; see screenshot).

为此,您可以在代码中明确设置accessibilityIdentifier / accessibilityLabel(例如,button.accessibilityIdentifier =“slide_out”)或在Storyboard中(在属性下;参见屏幕截图)。

访问Xcode UITest中的app.buttons,没有任何可用于引用的文本。

If, on the other hand, there's a timing issue because you need to wait for the element to appear, I recommend Joe Masilotti's blog post about custom helpers in XCUITest: http://masilotti.com/xctest-helpers/

另一方面,如果由于您需要等待元素出现而出现计时问题,我建议Joe Masilotti在XCUITest中关于自定义助手的博客文章:http://masilotti.com/xctest-helpers/

#2


0  

Tipp: In case, anyone tries to access buttons from within an IONIC app and doesn't find out about how to code the 'accessibilityIdentifier' in that IONIC .html and .ts files...

Tipp:如果有人试图从IONIC应用程序中访问按钮,并且没有找到如何在IONIC .html和.ts文件中编码'accessibilityIdentifier'...

aria-label="myLabel"
in the button element does the trick; id, name and so on don't.