FIRVerifyIOSClientTests.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import <EarlGrey/EarlGrey.h>
  18. #import <FirebaseCore/FIRApp.h>
  19. #import "FirebaseAuth.h"
  20. static CGFloat const kShortScrollDistance = 100;
  21. static NSTimeInterval const kWaitForElementTimeOut = 15;
  22. @interface FIRVerifyIOSClientTests : XCTestCase
  23. @end
  24. /** Convenience function for EarlGrey tests. */
  25. static id<GREYMatcher> grey_scrollView(void) {
  26. return [GREYMatchers matcherForKindOfClass:[UIScrollView class]];
  27. }
  28. @implementation FIRVerifyIOSClientTests
  29. /** To reset the app so that each test sees the app in a clean state. */
  30. - (void)setUp {
  31. [super setUp];
  32. [self signOut];
  33. [[EarlGrey selectElementWithMatcher:grey_allOf(grey_scrollView(),
  34. grey_kindOfClass([UITableView class]), nil)]
  35. performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];
  36. }
  37. #pragma mark - Tests
  38. /** Test verify ios client*/
  39. - (void)testVerifyIOSClient {
  40. [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Verify iOS client"),
  41. grey_sufficientlyVisible(), nil)]
  42. usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)
  43. onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),
  44. nil)] performAction:grey_tap()];
  45. [self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];
  46. [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];
  47. }
  48. #pragma mark - Helpers
  49. /** Sign out current account. */
  50. - (void)signOut {
  51. NSError *signOutError;
  52. BOOL status = [[FIRAuth auth] signOut:&signOutError];
  53. // Just log the error because we don't want to fail the test if signing out fails.
  54. if (!status) {
  55. NSLog(@"Error signing out: %@", signOutError);
  56. }
  57. }
  58. /** Wait for an element with text to appear. */
  59. - (void)waitForElementWithText:(NSString *)text withDelay:(NSTimeInterval)maxDelay {
  60. GREYCondition *displayed =
  61. [GREYCondition conditionWithName:@"Wait for element"
  62. block:^BOOL {
  63. NSError *error = nil;
  64. [[EarlGrey selectElementWithMatcher:grey_text(text)]
  65. assertWithMatcher:grey_sufficientlyVisible()
  66. error:&error];
  67. return !error;
  68. }];
  69. GREYAssertTrue([displayed waitWithTimeout:maxDelay], @"Failed to wait for element '%@'.", text);
  70. }
  71. @end