MonkeyTalk : Verify custom UITableViewCell Label text without select the cell

*爱你&永不变心* 提交于 2019-12-11 06:06:12

问题


I have an iPhone application that has a search box and UITableView with custom UITableViewCells. This Table Loaded with search results after user enter a search word and tap search. I need to test the search results with MonkeyTalk. (using MonkeyTalk script or JavaScript version of it). I want to retrieve/verify that 2nd Label of first CustomUITableViewCell contains the search text without selecting the cell.

So far I'm able to get number of items of the each table section using

var count = app.table().get("count", "size(sectionNo)"); //java script version

and I'm able to retrieve title or detail text of default UITableViewCells successfully with

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

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

I want to Know How I do the same with custom UITableViewCell ?

MonkeyTalk Table properties reference:


回答1:


I found a way to do it.

First open the xcode project source code, in side UITableviewDelegate method "cellForRowAtIndexPath" (where we configure each cell) configure property "accessibilityLabel" for the Label you want to verify/access through automated test.

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

clean and build with test target. inside monkeytalk Script you can access the property using accessibilityLabel name

Label "cellTitleLabel" Verify "apple" ".text" #monkeytalk script

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

Note: no need to think about table or section information. it will identify a Label with monkeyId "cellTitleLabel" and if you want to access the titleLabel of the second cell of the same table you can use monkeyId "cellTitleLabel(2)" and for the third cell monkeyId "cellTitleLabel(3)" like that..

if you guys have better solutions please add it here Thanks.. Chathura



来源:https://stackoverflow.com/questions/16304129/monkeytalk-verify-custom-uitableviewcell-label-text-without-select-the-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!