Search code examples
javascriptiosxcodeinstrumentsui-automation

UIAutomation script for setting textfield values in UItableView


I’m new to UIAutomation and I’m trying to enter value to two textfields in a UITabelView.

The script I tried is below

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

target.delay(1);

var tableView = window.tableViews()[0];

tableView.logElementTree();

var cellOne = tableView.cells()[0].textFields()[0].setValue(“username”);
var cellTwo = tableView.cells()[1].textFields()[0].setValue(“password”);

Textfield in first cell always gets entered but the second one always fails. And when I tried to log its element tree it returns UIElementNil

Is there something wrong with my script?


Solution

  • I went through Apple's document on Automation UI Testing and followed Recording Manual User Interface Actions into Automation Scripts and Instruments created the script for me based on my manual actions.

    If anyone was struck as mine and stupid as me to not go through Apple's document. Please don't do that and always refer Apple's document first.

    Here's the reference

    https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

    And here's my script

    var target = UIATarget.localTarget();
    
    var app = target.frontMostApp();
    
    var window = app.mainWindow();
    
    window.buttons()["Login"].tap();
    
    target.delay(1);
    
    var tableView = window.tableViews()[0];
    
    tableView.cells()[0].textFields()[0].textFields()[0].setValue("username");
    
    tableView.cells()[1].secureTextFields()[0].secureTextFields()[0].setValue("password");
    
    window.navigationBar().rightButton().tap();
    

    As you can see I failed to notice that password textfield is a securedTextField.