Search code examples
swiftobjective-cuitestskadnetwork

Fill password field in iTunes prompt on a UITest


I am writing a UITest for my app. While the test is running I get a 'Sign In to Complete Purchase' prompt:

enter image description here

I was able to fill the 'Apple ID' text field since the keyboard is already open and ready to fill it - To do it I used:

XCUIApplication *app = [[XCUIApplication alloc] init];
[app typeText:@"My iTunes username"];

But I could not simulate a tap on the password field. I could not figure out how to find it in the UI. I tried lots of options (but not of them worked):

XCUIElementQuery *collectionViewsQuery = app.collectionViews;
[collectionViewsQuery.textFields[@"password"] tap];
[collectionViewsQuery.textFields[@"Password"] tap];
[[collectionViewsQuery.textFields firstMatch] tap];
[collectionViewsQuery.secureTextFields[@"password"] tap];
[collectionViewsQuery.secureTextFields[@"Password"] tap];
[[collectionViewsQuery.secureTextFields firstMatch] tap];

XCUIApplication *springboard = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.springboard"];
[[springboard.alerts firstMatch].textFields[@"password"] tap];
[[springboard.alerts firstMatch].textFields[@"Password"] tap];

I think that the real issue is the fact that I can't get the corresponding view (or collectionView in this case). I tried looking in Apple documentation and I could not find anything. I did see the option of adding a configuration file for In-App purchases testing but in my case I don't test In-App purchases. I download another app from within my app to check conversion value (SKAdNetwork) on AWS device farm.


Solution

  • After several hours I found the answer:

    - (void)signInToItunes {
        XCUIApplication *app = [[XCUIApplication alloc] init];
        [app typeText:@"YourAppleID"];
        sleep(2);
    
        [[app.secureTextFields firstMatch] tap];
        [app typeText:@"YourPassword"];
        sleep(2);
        
        [app.buttons[@"Sign In"] tap];
    }