Frank Test : UIPickerView not Updating Value in Cell

262 views Asked by At

So, I have the following Date Picker View :

enter image description here

This is connected to a Date of Birth Cell :

enter image description here

Now, in my Frank Test, I want to move the tumblers around and then reflect the final value in the Text Box. I do the following in order to do so :

dateValue = "04.11.2002"
dateParts = dateVale.split('.')

for i in 2.downto(0) do
  frankly_map( "view:'UIPickerView' index:0", 'selectRow:inComponent:animated:', dateParts[i].to_i - 1, i, false )
end

So we loop through the tumblers and change them to the appropriate value. However, the change in the tumblers does not reflect in the UITextBox. So I decided to update it by tapping on any value in the UIPickerView :

touch("view marked:'15'")

But, this changes every single tumbler! Can someone tell me just why this is happening and how I can get the date set?

1

There are 1 answers

0
TeodorN On

Here is a method in Java I did to select a value from a picker view (the UITextField which uses the selected picker value is also updated, for that you have to generate a scroll event):

/**
 * Select row with @rowValue value for @selector UI picker view.
 *
 * @param selector
 * @param rowValue
 * @throws Exception
 */
public static void selectRowFromPicker(String selector, String rowValue) throws Exception {
    int component = 0;
    JSONArray rowsCountArray = Frank.frankly_map(selector, "numberOfRowsInComponent:", component);
    if (rowsCountArray.length() == 0) {
        throw new Exception("No rows for picker view component " + component + " were found.");
    }

    int rowsCount = rowsCountArray.getInt(0);
    String tableViewSelector = selector + " descendant tableView";
    boolean found = false;
    String initialText = "";

    for (int i = 0; i < rowsCount; i++) {
        JSONArray array = Frank.frankly_map(selector, "selectRow:inComponent:animated:", i, component, true);
        if (array.length() == 0) {
            throw new Exception("Could not select row from picker view with row value: '" + rowValue + "' selector: '" + selector + "'");
        }
        String labelSelector = tableViewSelector + " descendant label index:0";
        WaitHelper.waitFor(WaitHelper.not(WaitHelper.viewTextToHaveValue(labelSelector, initialText)), GlobalVariables.MEDIUM);
        JSONArray currentTableViewRowValue = Frank.frankly_map(labelSelector, "text");
        if (currentTableViewRowValue.length() == 0) {
            throw new Exception("Could not get the text for current row for picker view selector: " + selector);
        }
        if (currentTableViewRowValue.getString(0).equals(rowValue)) {
            found = true;
            break;
        }
        initialText = currentTableViewRowValue.getString(0);
    }

    //Need to generate a scroll event to bind data in the controls which use the picker selected value
    if (!Frank.scrollDownRows(tableViewSelector, 0) || !found) {
        throw new Exception("Could not scroll down in the picker view selector: " + selector);
    }
}

Where Frank.scrollDownRows does: Frank.frankly_map(selector, "scrollDownRows:", noOfRows);

I hope this helps.