FIRPerfE2EUITests.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <XCTest/XCTest.h>
  15. // Time to wait for the traces test to finish.
  16. static const NSTimeInterval kTestWaitTimeInSeconds = 12 * 60;
  17. @interface FIRPerfE2EUITests : XCTestCase
  18. @end
  19. @implementation FIRPerfE2EUITests
  20. XCUIApplication *_application;
  21. - (void)setUp {
  22. [super setUp];
  23. // In UI tests it is usually best to stop immediately when a failure occurs.
  24. self.continueAfterFailure = NO;
  25. static dispatch_once_t onceToken;
  26. dispatch_once(&onceToken, ^{
  27. _application = [[XCUIApplication alloc] init];
  28. // If the autopush environment variable is set, propagate this environment variable to the
  29. // underlying test app.
  30. NSDictionary<NSString *, NSString *> *environment = [NSProcessInfo processInfo].environment;
  31. if (environment[@"FPR_AUTOPUSH_ENV"] != nil &&
  32. [environment[@"FPR_AUTOPUSH_ENV"] isEqualToString:@"1"]) {
  33. _application.launchEnvironment = @{@"FPR_AUTOPUSH_ENV" : @"1"};
  34. }
  35. [_application launch];
  36. });
  37. }
  38. /** Runs all the tests related to traces (Traces + Network Requests + Screen traces). */
  39. - (void)testTracesAndNetworkRequests {
  40. // Tap the start traces button
  41. XCUIElement *startTracesButton = _application.buttons[@"Start traces"];
  42. [startTracesButton tap];
  43. // Label denoting the pending traces.
  44. XCUIElement *label = [[_application staticTexts] elementMatchingType:XCUIElementTypeAny
  45. identifier:@"Pending traces count - 0"];
  46. NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:@"exists == true"];
  47. XCTestExpectation *expectation = [self expectationForPredicate:existsPredicate
  48. evaluatedWithObject:label
  49. handler:^BOOL {
  50. // Add a delay for the last set of traces
  51. // to be uploaded.
  52. [NSThread sleepForTimeInterval:30.0f];
  53. return YES;
  54. }];
  55. // Wait until the pending traces 0 count text is available.
  56. [self waitForExpectations:[[NSArray alloc] initWithObjects:expectation, nil]
  57. timeout:kTestWaitTimeInSeconds];
  58. }
  59. - (void)testScreenTraces {
  60. // Tap the start screen traces button.
  61. XCUIElement *startScreenTracesButton = _application.buttons[@"Test screen traces"];
  62. [startScreenTracesButton tap];
  63. XCUIElementQuery *tablesQuery = _application.tables;
  64. // Perform 5 swipe up actions before going back.
  65. for (int i = 0; i < 5; i++) {
  66. [[tablesQuery element] swipeUp];
  67. }
  68. // Go back to main screen.
  69. [_application.navigationBars[@"PerfE2EScreenTracesView"].buttons[@"Back"] tap];
  70. }
  71. @end