Skip to content

Commit

Permalink
Take screenshots by always passing afterScreenUpdates:YES.
Browse files Browse the repository at this point in the history
Motivation: a lot of tests use `[GREYScreenshotter snapshotElement]` method to take screenshots which currently uses `afterScreenUpdates:NO`. This means that changes done in the current run loop iteration won't be visible in the screenshot. This can cause flakiness and it's better to always use `afterScreenUpdates:YES` to get the most accurate current UI state.
PiperOrigin-RevId: 570316525
  • Loading branch information
mobile-devx-github-bot committed Oct 3, 2023
1 parent 7bad4a3 commit 8dd5438
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion UILib/GREYScreenshotter.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ + (UIImage *)snapshotElement:(id)element {
UIScreen *mainScreen = MainScreen();
if (!mainScreen) return nil;
UIGraphicsBeginImageContextWithOptions(elementAXFrame.size, NO, mainScreen.scale);
// We want to capture the most up-to-date version of the screen here, including the updates that
// have been made in the current runloop iteration. Therefore we use `afterScreenUpdates:YES`.
[self drawViewInContext:UIGraphicsGetCurrentContext()
view:viewToSnapshot
bounds:elementAXFrame
afterScreenUpdates:NO];
afterScreenUpdates:YES];
UIImage *orientedScreenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Expand Down

0 comments on commit 8dd5438

Please sign in to comment.