[iOS ] Fix errors in unittest and scenario tests running against iOS 17 simulators (details in the description) (flutter/engine#45391)

1. New Mac version seems to have updated the locale data, to match the mac change, we can dynamically read the data when testing instead of hard coding.

2. "we are sending a UIImage type as parameter to `XCTAttachment attachmentWithScreenshot:`, which takes a `XCUIScreenshot` as parameter, this is not supposed to pass in old iOS versions." In this PR we updated the parameter to use the `XCUIScreenshot` type.

Fixes https://github.com/flutter/flutter/issues/133783

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Chris Yang
2023-09-05 15:45:22 -07:00
committed by GitHub
parent 702d8bce4f
commit a101546179
2 changed files with 11 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ NSDictionary* launchArgsMap;
- (void)checkGoldenForTest:(XCTestCase*)test {
XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot];
if (!_goldenImage.image) {
XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot.image];
XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
attachment.name = [_goldenImage.goldenName stringByAppendingString:@"_new.png"];
attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
[test addAttachment:attachment];

View File

@@ -26,10 +26,17 @@ FLUTTER_ASSERT_ARC
NSTimeInterval timeout = 10.0;
// The locales received by dart:ui are exposed onBeginFrame via semantics label.
// There should only be one locale, since the default iOS app only has en_US as
// the locale. The list should consist of just the en locale.
// There should only be one locale. The list should consist of the default
// locale provided by the iOS app.
NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
XCTAssertEqual(preferredLocales.count, 1);
// Dart connects the locale parts with `_` while iOS connects them with `-`.
// Converts to dart format before comparing.
NSString* localeDart = [preferredLocales.firstObject stringByReplacingOccurrencesOfString:@"-"
withString:@"_"];
NSString* expectedIdentifier = [NSString stringWithFormat:@"[%@]", localeDart];
XCUIElement* textInputSemanticsObject =
[self.application.textFields matchingIdentifier:@"[en]"].element;
[self.application.textFields matchingIdentifier:expectedIdentifier].element;
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
[textInputSemanticsObject tap];