【问题标题】:MonkeyTalk : Verify custom UITableViewCell Label text without select the cellMonkeyTalk:验证自定义 UITableViewCell 标签文本而不选择单元格
【发布时间】:2013-04-30 15:57:45
【问题描述】:

我有一个 iPhone 应用程序,它有一个搜索框和带有自定义 UITableViewCells 的 UITableView。此表在用户输入搜索词并点击搜索后加载搜索结果。 我需要用 MonkeyTalk 测试搜索结果。 (使用 MonkeyTalk 脚本或它的 JavaScript 版本)。我想检索/验证第一个 CustomUITableViewCell 的第二个标签是否包含搜索文本而不选择单元格。

到目前为止,我能够使用

获取每个表格部分的项目数
var count = app.table().get("count", "size(sectionNo)"); //java script version

并且我能够成功检索默认 UITableViewCells 的标题或详细信息

var data = app.table().get("data","item(CellNo)"); //java script version

Table * Verify "searchTerm" item(CellNo)   #monkey script version

我想知道如何使用自定义 UITableViewCell 做同样的事情?

MonkeyTalk 表属性reference

【问题讨论】:

    标签: iphone uitableview automated-tests custom-view monkeytalk


    【解决方案1】:

    我找到了办法。

    首先打开xcode项目源代码,在侧面UITableviewDelegate方法“cellForRowAtIndexPath”(我们配置每个单元格的地方)为您要通过自动化测试验证/访问的标签配置属性“accessibilityLabel”。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ........
    ........
    cell.searchItemTitle.text = item.title;
    cell.searchItemDescription.text = item.description;
    cell.searchItemTitle.accessibilityLabel = @"cellTitleLabel";
    ........
    ........
    return cell;
    }
    

    清理并使用测试目标构建。 在monkeytalk Script中,您可以使用accessibilityLabel名称访问该属性

    Label "cellTitleLabel" Verify "apple" ".text" #monkeytalk script
    
    app.label("cellTitleLabel").verify("apple", ".text"); //java script version
    

    注意:无需考虑表格或部分信息。它将识别一个带有 monkeyId "cellTitleLabel" 的标签,如果你想访问同一个表的第二个单元格的 titleLabel,你可以使用 monkeyId "cellTitleLabel(2)" 和第三个单元格 monkeyId "cellTitleLabel(3)" 像这样..

    如果你们有更好的解决方案,请在此处添加 谢谢.. 查图拉

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多