in Programming Tools

Detecting a Table Cell Checkmark with Frank Cucumber

Frank allows you to test native iOS applications using Cucumber. I’m pretty comfortable with Cucumber already from work with Rails, so I have been excited to try Frank out. It works by compiling your native application with an HTTP Server that your tests interact with to inspect the state of your application. It includes another really cool tool called Symbiote, which shows the current view of the iOS simulator and presents a view hierarchy.

UITableViewCells can have accessories which appear at the right of the cell. One of these is a checkmark. I wanted to test whether or not a checkmark would appear once a cell was clicked. Here’s the step that I used.

Then /^I should see a table cell marked "(.*?)" with a checkmark$/ do |mark|
  checkmarks = frankly_map("view marked:'#{mark}' parent tableViewCell", 'accessoryType')
  checkmarks.first.should == 3 # checkmarks are 3

It retrieves all the views with the passed text, which will be UILabels, then goes to their parent, a UITableViewCell and then asks for its accessoryType. Once that is done, a matcher checks that the first value returned is 3. This corresponds to the integer value of UITableViewCellAccessoryCheckmark. It’s an enum type as shown in the UITableViewCell Class Reference, excerpted below. I’ve added the comments with integer values.

typedef enum {
   UITableViewCellAccessoryNone, // 0
   UITableViewCellAccessoryCheckmark // 3
} UITableViewCellAccessoryType;

Although this was fairly straightforward, I should’ve been able to use the following, which is more direct:

Then /^I should see a table cell marked "(.*?)" with a checkmark$/ do |mark|
  checkmarks = frankly_map("tableViewCell marked:'#{mark}'", 'accessoryType') 
  checkmarks.first.should == 3 # checkmarks are 3

Unfortunately, I was having problems with the query, and no UITableViewCells were found. I’m currently using v0.9.4 of the frank-cucumber gem.