FIRAuthE2eTestsBase.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2019 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 "FIRAuthE2eTestsBase.h"
  17. CGFloat const kShortScrollDistance = 400;
  18. NSTimeInterval const kWaitForElementTimeOut = 15;
  19. /** Convenience function for EarlGrey tests. */
  20. id<GREYMatcher> grey_scrollView(void) {
  21. return [GREYMatchers matcherForKindOfClass:[UIScrollView class]];
  22. }
  23. @implementation FIRAuthE2eTestsBase
  24. /** To reset the app so that each test sees the app in a clean state. */
  25. - (void)setUp {
  26. [super setUp];
  27. [self signOut];
  28. [[EarlGrey selectElementWithMatcher:grey_allOf(grey_scrollView(),
  29. grey_kindOfClass([UITableView class]), nil)]
  30. performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];
  31. }
  32. - (void)tearDown {
  33. [super tearDown];
  34. }
  35. /** Sign out current account. */
  36. - (void)signOut {
  37. NSError *signOutError;
  38. BOOL status = [[FIRAuth auth] signOut:&signOutError];
  39. // Just log the error because we don't want to fail the test if signing out fails.
  40. if (!status) {
  41. NSLog(@"Error signing out: %@", signOutError);
  42. }
  43. }
  44. /** Wait for an element with text to appear. */
  45. - (void)waitForElementWithText:(NSString *)text withDelay:(NSTimeInterval)maxDelay {
  46. GREYCondition *displayed =
  47. [GREYCondition conditionWithName:@"Wait for element"
  48. block:^BOOL {
  49. NSError *error = nil;
  50. [[EarlGrey selectElementWithMatcher:grey_text(text)]
  51. assertWithMatcher:grey_sufficientlyVisible()
  52. error:&error];
  53. return !error;
  54. }];
  55. GREYAssertTrue([displayed waitWithTimeout:maxDelay], @"Failed to wait for element '%@'.", text);
  56. }
  57. @end