问题
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