Skip to content

Commit 1bf3ff5

Browse files
gonenghannesa2
authored andcommitted
Fix the screenshot tests all photographing the same view (issue #676)
Have each screenshot test reach its view and prove it arrived, so the suite covers three screens instead of one screen three times. - Switch views through the View menu, which is where the Stage view is reachable from. The toolbar button the staging test looked for has never existed, so that test always fell through and photographed the history view under the staging name. - Assert the destination is on screen before the shutter, so a missed switch fails the run instead of quietly yielding a duplicate. - Drop the capture from testMainWindowExists and keep it as a launch assertion, the main window being the history view already. - Select the history view in the context menu test too, since reaching the Stage view persists PBShowStageView and so decides what the next launch opens on.
1 parent 686e721 commit 1bf3ff5

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

‎GitXUITests/GitXScreenshotTests.m‎

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ - (BOOL)waitForWindow {
6464
return [self.app.windows.firstMatch waitForExistenceWithTimeout:10];
6565
}
6666

67+
- (BOOL)selectViewMenuItem:(NSString *)title {
68+
XCUIElement *viewMenu = self.app.menuBars.menuBarItems[@"View"];
69+
if (![viewMenu waitForExistenceWithTimeout:10]) {
70+
NSLog(@"[GitXScreenshotTests] The View menu never appeared");
71+
return NO;
72+
}
73+
[viewMenu click];
74+
75+
XCUIElement *item = viewMenu.menus.menuItems[title];
76+
if (![item waitForExistenceWithTimeout:5]) {
77+
NSLog(@"[GitXScreenshotTests] View > %@ was not offered", title);
78+
[self.app typeKey:XCUIKeyboardKeyEscape modifierFlags:0];
79+
return NO;
80+
}
81+
82+
NSLog(@"[GitXScreenshotTests] Switching to View > %@", title);
83+
[item click];
84+
[NSThread sleepForTimeInterval:0.5];
85+
return YES;
86+
}
87+
6788
- (void)saveScreenshotNamed:(NSString *)name {
6889
XCUIScreenshot *screenshot = [[XCUIScreen mainScreen] screenshot];
6990
XCTAttachment *attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
@@ -90,28 +111,28 @@ - (void)saveWindowScreenshotNamed:(NSString *)name {
90111
- (void)testMainWindowExists {
91112
XCTAssertTrue([self waitForWindow],
92113
@"Main window should appear within 30 seconds");
93-
[self saveWindowScreenshotNamed:@"main-window"];
94114
}
95115

96116
- (void)testHistoryTabScreenshot {
97-
if (![self waitForWindow]) { return; }
117+
XCTAssertTrue([self waitForWindow], @"Main window should appear");
118+
XCTAssertTrue([self selectViewMenuItem:@"History"],
119+
@"View > History should be reachable");
120+
121+
XCUIElement *table = self.app.windows.firstMatch.tables.firstMatch;
122+
XCTAssertTrue([table waitForExistenceWithTimeout:10],
123+
@"The history view should show its commit list");
124+
98125
[self saveWindowScreenshotNamed:@"history-view"];
99126
}
100127

101128
- (void)testStagingTabScreenshot {
102-
if (![self waitForWindow]) { return; }
103-
104-
// Click the Stage tab / toolbar button if present
105-
XCUIElement *stageButton = self.app.toolbars.buttons[@"Stage"];
106-
if (!stageButton.exists) {
107-
// Try as a tab or segmented control
108-
stageButton = [self.app.windows.firstMatch.buttons elementMatchingType:XCUIElementTypeButton
109-
identifier:@"Stage"];
110-
}
111-
if (stageButton.exists) {
112-
[stageButton click];
113-
[NSThread sleepForTimeInterval:0.5];
114-
}
129+
XCTAssertTrue([self waitForWindow], @"Main window should appear");
130+
XCTAssertTrue([self selectViewMenuItem:@"Commit"],
131+
@"View > Commit should be reachable");
132+
133+
XCUIElement *commitButton = self.app.windows.firstMatch.buttons[@"Commit"];
134+
XCTAssertTrue([commitButton waitForExistenceWithTimeout:10],
135+
@"The staging view should show its Commit button");
115136

116137
[self saveWindowScreenshotNamed:@"staging-view"];
117138
}
@@ -123,7 +144,9 @@ - (void)testStagingTabScreenshot {
123144
// }
124145

125146
- (void)testCommitContextMenuScreenshot {
126-
if (![self waitForWindow]) { return; }
147+
XCTAssertTrue([self waitForWindow], @"Main window should appear");
148+
XCTAssertTrue([self selectViewMenuItem:@"History"],
149+
@"View > History should be reachable");
127150

128151
// The commit list is a table — find the first (most recent) commit row
129152
XCUIElement *window = self.app.windows.firstMatch;

0 commit comments

Comments
 (0)