diff --git a/IdentityCore/tests/automation/ui_tests_lib/MSIDBaseUITest.m b/IdentityCore/tests/automation/ui_tests_lib/MSIDBaseUITest.m index dbc7cd237..7a077a9e5 100644 --- a/IdentityCore/tests/automation/ui_tests_lib/MSIDBaseUITest.m +++ b/IdentityCore/tests/automation/ui_tests_lib/MSIDBaseUITest.m @@ -314,22 +314,29 @@ - (void)enterPassword:(NSString *)password app:(XCUIApplication *)application is // Enter password XCUIElement *passwordSecureTextField = [application.secureTextFields elementBoundByIndex:0]; // This is explicitly to check the new screen where to ask user to signin with the following 2 options. This caused several automation failures - // 1. Use my password - // 2. Sign in to an orgnization - XCUIElement *useMyPasswordButton = application.buttons[@"Use my password"]; - XCUIElement *currentElement = [self waitForEitherElements:passwordSecureTextField and:useMyPasswordButton]; - if (currentElement.elementType == XCUIElementTypeButton) + + XCTWaiterResult result = [self waitForElementsAndContinue:passwordSecureTextField]; + if (result == XCTWaiterResultCompleted) { - [currentElement tap]; - [self enterPassword:password - app:application - isMainApp:isMainApp]; - return; + [self tapElementAndWaitForKeyboardToAppear:passwordSecureTextField app:application]; + NSString *passwordString = [NSString stringWithFormat:@"%@\n", password]; + [self enterText:passwordSecureTextField isMainApp:isMainApp text:passwordString]; + } + else + { + // 1. Use my password + // 2. Sign in to an orgnization + XCUIElement *useMyPasswordButton = application.buttons[@"Use my password"]; + result = [self waitForElementsAndContinue:useMyPasswordButton]; + if (result == XCTWaiterResultCompleted) + { + [useMyPasswordButton tap]; + [self enterPassword:password + app:application + isMainApp:isMainApp]; + } } - [self tapElementAndWaitForKeyboardToAppear:passwordSecureTextField app:application]; - NSString *passwordString = [NSString stringWithFormat:@"%@\n", password]; - [self enterText:passwordSecureTextField isMainApp:isMainApp text:passwordString]; } - (void)adfsEnterPassword:(XCUIApplication *)application @@ -487,6 +494,14 @@ - (XCUIElement *)waitForEitherElements:(XCUIElement *)object1 and:(XCUIElement * return object1.exists ? object1 : object2; } +- (XCTWaiterResult)waitForElementsAndContinue:(XCUIElement *)object +{ + NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:@"%@.exists == 1" argumentArray:@[object]]; + + XCTestExpectation *expectation = [[XCTNSPredicateExpectation alloc] initWithPredicate:existsPredicate object:object];//[self expectationForPredicate:existsPredicate evaluatedWithObject:nil handler:nil]; + return [XCTWaiter waitForExpectations:@[expectation] timeout:10.0f enforceOrder:YES]; +} + - (void)tapElementAndWaitForKeyboardToAppear:(XCUIElement *)element { [self tapElementAndWaitForKeyboardToAppear:element app:[XCUIApplication new]];