简体   繁体   English

XCode 7 UI 测试 - 可用操作

[英]XCode 7 UI Testing - Actions Available

One thing Apple talked about when introducing Xcode 7's UI testing on iOS 9 was that everything came from accessibility. Apple 在 iOS 9 上介绍 Xcode 7 的 UI 测试时谈到的一件事是,一切都来自可访问性。 I'm wondering if anyone knows how to find out if an element has "Actions Available" on it.我想知道是否有人知道如何找出元素上是否有“可用操作”。

I have a UITableView where some cells can be deleted by swiping from right to left revealing the delete button.我有一个UITableView ,其中一些单元格可以通过从右向左滑动显示删除按钮来删除。 When VoiceOver is turned on and you tap on the cell it describes the cell as a button and then says "Actions Available".当 VoiceOver 打开并且您点击单元格时,它会将单元格描述为一个按钮,然后显示“可用操作”。

I'd like to find that out from within my test so I can use to validate that some things are enabled and some things aren't.我想从我的测试中找出这一点,这样我就可以用来验证某些东西已启用,有些东西未启用。

Any ideas?有任何想法吗?

The syntax has changed in Swift 3. Swift 3 中的语法发生了变化。

let app = XCUIApplication()
let cells = app.tables.cells
cells.element(boundBy: 0).swipeLeft()
cells.element(boundBy: 0).buttons["Delete"].tap()

I don't know of a way to find out from XCUITesting whether there are any accessibility actions available, and if so, what they are.我不知道有什么方法可以从 XCUITesting 中找出是否有任何可用的可访问性操作,如果有,它们是什么。

But if you are specifically trying to detect if the "Delete" button is available after swiping right-to-left on a cell, you can use something like但是,如果您专门尝试检测在单元格上从右向左滑动后“删除”按钮是否可用,则可以使用类似

yourCellXCUIElement.buttons.count  //How many buttons are visible inside your cell.  In a standard UITableViewCell, this will be 0 unless you have exposed the "Delete" button.

You can also get the label on the button like this:您还可以像这样获取按钮上的标签:

yourCellXCUIElement.buttons.elementAtIndex(0).label //In a standard UITableViewCell that has been swiped left to expose the Delete button, this will return "Delete"

Is this what you are trying to get at, or are there different things that you are trying to validate are enabled or not?这是您想要达到的目标,还是您尝试验证是否启用了不同的东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM