Test Application by looping through a pattern of values in UITextField

71 Views Asked by At

I want to test my application by entering values from 1 to 10000 in a UITextField and pressing a "Go" UIButton.

And know conditions where a segue is getting performed.

How do I define the test criteria for automating testing with values 1 - 10000 being entered into the UITextField?

enter image description here

Another situation exactly matching my problem:

While testing a calculator application, I need to check all the possible operations and numbers. Can we do automation to test random clicks on calculator and check the output?

1

There are 1 best solutions below

0
On

You can use a loop to try each value between 1 and 10000. For each value, type it into the text field, press the button and see what happens. I'm not sure what you're expecting to happen, so I have just written code which checks that a label appears - you should change this to whatever you think would assert that the correct outcome has happened.

XCUIApplication *app = [[XCUIApplication init] alloc];
XCUIElement *textField = [[app.textFields matchingIdentifier: "myTextField"] elementBoundByIndex: 0];
XCUIElement *goButton = [[app.buttons matchingIdentifier: "goButton"] elementBoundByIndex: 0];

for (NSNumber i = 1; i <= 10000; i++) {
    NSString *n = [NSString stringWithFormat:@"%d", i];
    [textField tap];
    [textField typeText: n];
    [goButton tap];

    // Define what it is you expect to happen
    BOOL expectedOutcome = [[app.staticTexts matchingIdentifier: "myLabel"] elementBoundByIndex: 0].exists;
    XCTAssert(expectedOutcome, [NSString stringWithFormat:@"Unexpected result for %d", i])
}