Flutter Engine
GoldenPlatformViewTests.m
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <sys/sysctl.h>
8 
10 
11 static const NSInteger kSecondsToWaitForPlatformView = 30;
12 
14 
15 @property(nonatomic, copy) NSString* goldenName;
16 
17 @property(nonatomic, strong) PlatformViewGoldenTestManager* manager;
18 
19 @end
20 
21 @implementation GoldenPlatformViewTests
22 
23 - (instancetype)initWithManager:(PlatformViewGoldenTestManager*)manager
24  invocation:(NSInvocation*)invocation {
25  self = [super initWithInvocation:invocation];
26  _manager = manager;
27  return self;
28 }
29 
30 - (void)setUp {
31  [super setUp];
32  self.continueAfterFailure = NO;
33 
34  self.application = [[XCUIApplication alloc] init];
35  self.application.launchArguments = @[ self.manager.launchArg, @"--enable-software-rendering" ];
36  [self.application launch];
37 }
38 
39 // Note: don't prefix with "test" or GoldenPlatformViewTests will run instead of the subclasses.
40 - (void)checkGolden {
41  XCUIElement* element = self.application.textViews.firstMatch;
42  BOOL exists = [element waitForExistenceWithTimeout:kSecondsToWaitForPlatformView];
43  if (!exists) {
44  XCTFail(@"It took longer than %@ second to find the platform view."
45  @"There might be issues with the platform view's construction,"
46  @"or with how the scenario is built.",
48  }
49 
50  GoldenImage* golden = self.manager.goldenImage;
51 
52  XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot];
53  if (!golden.image) {
54  XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
55  attachment.name = @"new_golden";
56  attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
57  [self addAttachment:attachment];
58  XCTFail(@"This test will fail - no golden named %@ found. Follow the steps in the "
59  @"README to add a new golden.",
60  golden.goldenName);
61  }
62 
63  if (![golden compareGoldenToImage:screenshot.image]) {
64  XCTAttachment* screenshotAttachment;
65  screenshotAttachment = [XCTAttachment attachmentWithImage:screenshot.image];
66  screenshotAttachment.name = golden.goldenName;
67  screenshotAttachment.lifetime = XCTAttachmentLifetimeKeepAlways;
68  [self addAttachment:screenshotAttachment];
69 
70  XCTFail(@"Goldens to not match. Follow the steps in the "
71  @"README to update golden named %@ if needed.",
72  golden.goldenName);
73  }
74 }
75 @end
static const NSInteger kSecondsToWaitForPlatformView
NSString * goldenName
Definition: GoldenImage.h:11
UIImage * image
Definition: GoldenImage.h:12