Skip to content

Commit 66bfa8c

Browse files
CopilotMohabMohie
andauthored
Fix test failures: Mockito static mock lifecycle, website URL updates, URL assertion redirect handling, and workflow failure detection (#2241)
* Initial plan * Fix Mockito static mock lifecycle and update LocatorBuilder/Accessibility tests Co-authored-by: MohabMohie <[email protected]> * Revert AccessibilityTest.java - remove try-catch blocks from tests that should validate successful accessibility analysis Co-authored-by: MohabMohie <[email protected]> * Fix remaining test failures: update URL assertion and add AfterClass cleanup for Mockito Co-authored-by: MohabMohie <[email protected]> * Add workflow step to fail jobs when tests fail Co-authored-by: MohabMohie <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: MohabMohie <[email protected]> Co-authored-by: Mohab Mohie <[email protected]>
1 parent d5af673 commit 66bfa8c

4 files changed

Lines changed: 132 additions & 59 deletions

File tree

.github/workflows/e2eTests.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ jobs:
6565
with:
6666
paths: "target/surefire-reports/junitreports/TEST-*.xml"
6767
if: always()
68+
- name: Check Test Results
69+
if: always()
70+
run: |
71+
if [ -d "target/surefire-reports" ]; then
72+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
73+
echo "Tests failed! Failing the workflow."
74+
exit 1
75+
fi
76+
fi
6877
Ubuntu_APIs:
6978
runs-on: ubuntu-latest
7079
steps:
@@ -101,6 +110,15 @@ jobs:
101110
with:
102111
paths: "target/surefire-reports/junitreports/TEST-*.xml"
103112
if: always()
113+
- name: Check Test Results
114+
if: always()
115+
run: |
116+
if [ -d "target/surefire-reports" ]; then
117+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
118+
echo "Tests failed! Failing the workflow."
119+
exit 1
120+
fi
121+
fi
104122
Ubuntu_Firefox_Grid:
105123
runs-on: ubuntu-latest
106124
steps:
@@ -141,6 +159,15 @@ jobs:
141159
with:
142160
paths: "target/surefire-reports/junitreports/TEST-*.xml"
143161
if: always()
162+
- name: Check Test Results
163+
if: always()
164+
run: |
165+
if [ -d "target/surefire-reports" ]; then
166+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
167+
echo "Tests failed! Failing the workflow."
168+
exit 1
169+
fi
170+
fi
144171
Ubuntu_Chrome_Grid:
145172
runs-on: ubuntu-latest
146173
steps:
@@ -221,6 +248,15 @@ jobs:
221248
with:
222249
paths: "target/surefire-reports/junitreports/TEST-*.xml"
223250
if: always()
251+
- name: Check Test Results
252+
if: always()
253+
run: |
254+
if [ -d "target/surefire-reports" ]; then
255+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
256+
echo "Tests failed! Failing the workflow."
257+
exit 1
258+
fi
259+
fi
224260
Android_Native_BrowserStack:
225261
runs-on: ubuntu-latest
226262
steps:
@@ -257,6 +293,15 @@ jobs:
257293
with:
258294
paths: "target/surefire-reports/junitreports/TEST-*.xml"
259295
if: always()
296+
- name: Check Test Results
297+
if: always()
298+
run: |
299+
if [ -d "target/surefire-reports" ]; then
300+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
301+
echo "Tests failed! Failing the workflow."
302+
exit 1
303+
fi
304+
fi
260305
iOS_Web_SAFARI_BrowserStack:
261306
runs-on: ubuntu-latest
262307
steps:
@@ -293,6 +338,15 @@ jobs:
293338
with:
294339
paths: "target/surefire-reports/junitreports/TEST-*.xml"
295340
if: always()
341+
- name: Check Test Results
342+
if: always()
343+
run: |
344+
if [ -d "target/surefire-reports" ]; then
345+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
346+
echo "Tests failed! Failing the workflow."
347+
exit 1
348+
fi
349+
fi
296350
Android_Web_Chrome_BrowserStack:
297351
runs-on: ubuntu-latest
298352
steps:
@@ -329,6 +383,15 @@ jobs:
329383
with:
330384
paths: "target/surefire-reports/junitreports/TEST-*.xml"
331385
if: always()
386+
- name: Check Test Results
387+
if: always()
388+
run: |
389+
if [ -d "target/surefire-reports" ]; then
390+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
391+
echo "Tests failed! Failing the workflow."
392+
exit 1
393+
fi
394+
fi
332395
MacOSX_Safari_BrowserStack:
333396
runs-on: ubuntu-latest
334397
steps:
@@ -365,6 +428,15 @@ jobs:
365428
with:
366429
paths: "target/surefire-reports/junitreports/TEST-*.xml"
367430
if: always()
431+
- name: Check Test Results
432+
if: always()
433+
run: |
434+
if [ -d "target/surefire-reports" ]; then
435+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
436+
echo "Tests failed! Failing the workflow."
437+
exit 1
438+
fi
439+
fi
368440
Ubuntu_Chrome_Cucumber_Grid:
369441
runs-on: ubuntu-latest
370442
steps:
@@ -412,6 +484,15 @@ jobs:
412484
with:
413485
paths: "target/surefire-reports/junitreports/TEST-*.xml"
414486
if: always()
487+
- name: Check Test Results
488+
if: always()
489+
run: |
490+
if [ -d "target/surefire-reports" ]; then
491+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
492+
echo "Tests failed! Failing the workflow."
493+
exit 1
494+
fi
495+
fi
415496
MacOSX_Safari_Cucumber_BrowserStack:
416497
runs-on: ubuntu-latest
417498
steps:
@@ -452,3 +533,12 @@ jobs:
452533
with:
453534
paths: "target/surefire-reports/junitreports/TEST-*.xml"
454535
if: always()
536+
- name: Check Test Results
537+
if: always()
538+
run: |
539+
if [ -d "target/surefire-reports" ]; then
540+
if grep -r "failures=\"[1-9]" target/surefire-reports/ || grep -r "errors=\"[1-9]" target/surefire-reports/; then
541+
echo "Tests failed! Failing the workflow."
542+
exit 1
543+
fi
544+
fi

src/test/java/testPackage/CopilotGeneratedTests/DriverFactoryComprehensiveTests.java

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,9 @@ public class DriverFactoryComprehensiveTests {
4242

4343
@BeforeMethod
4444
public void setUp() {
45-
// Ensure previous static mocks are closed before creating new ones
46-
if (mockedPropertiesHelper != null) {
47-
try {
48-
mockedPropertiesHelper.close();
49-
} catch (Exception ignored) {
50-
}
51-
}
52-
if (mockedReportManager != null) {
53-
try {
54-
mockedReportManager.close();
55-
} catch (Exception ignored) {
56-
}
57-
}
58-
if (mockedFailureReporter != null) {
59-
try {
60-
mockedFailureReporter.close();
61-
} catch (Exception ignored) {
62-
}
63-
}
64-
if (mockedRecordManager != null) {
65-
try {
66-
mockedRecordManager.close();
67-
} catch (Exception ignored) {
68-
}
69-
}
70-
if (mockedReporter != null) {
71-
try {
72-
mockedReporter.close();
73-
} catch (Exception ignored) {
74-
}
75-
}
45+
// Close any existing static mocks before creating new ones to avoid registration conflicts
46+
closeStaticMocks();
47+
7648
// Initialize mocks
7749
driverFactoryHelper = new DriverFactoryHelper();
7850
mockWebDriver = Mockito.mock(WebDriver.class);
@@ -86,51 +58,62 @@ public void setUp() {
8658
mockedReporter = Mockito.mockStatic(Reporter.class);
8759
}
8860

89-
@AfterMethod
61+
@AfterMethod(alwaysRun = true)
9062
public void tearDown() {
91-
// Close all static mocks
92-
if (mockedPropertiesHelper != null) mockedPropertiesHelper.close();
93-
if (mockedReportManager != null) mockedReportManager.close();
94-
if (mockedFailureReporter != null) mockedFailureReporter.close();
95-
if (mockedRecordManager != null) mockedRecordManager.close();
96-
if (mockedReporter != null) mockedReporter.close();
63+
// Close all static mocks - alwaysRun ensures cleanup even on test failure
64+
closeStaticMocks();
9765
}
98-
99-
@AfterClass
100-
public void afterClass() {
101-
// Safety net: ensure all static mocks are closed after all tests
102-
if (mockedPropertiesHelper != null) {
66+
67+
@AfterClass(alwaysRun = true)
68+
public void tearDownClass() {
69+
// Final cleanup at class level to ensure no leaks between test retries
70+
closeStaticMocks();
71+
}
72+
73+
private void closeStaticMocks() {
74+
if (mockedReporter != null) {
10375
try {
104-
mockedPropertiesHelper.close();
76+
mockedReporter.close();
77+
mockedReporter = null;
10578
} catch (Exception ignored) {
10679
}
10780
}
108-
if (mockedReportManager != null) {
81+
if (mockedRecordManager != null) {
10982
try {
110-
mockedReportManager.close();
83+
mockedRecordManager.close();
84+
mockedRecordManager = null;
11185
} catch (Exception ignored) {
11286
}
11387
}
11488
if (mockedFailureReporter != null) {
11589
try {
11690
mockedFailureReporter.close();
91+
mockedFailureReporter = null;
11792
} catch (Exception ignored) {
11893
}
11994
}
120-
if (mockedRecordManager != null) {
95+
if (mockedReportManager != null) {
12196
try {
122-
mockedRecordManager.close();
97+
mockedReportManager.close();
98+
mockedReportManager = null;
12399
} catch (Exception ignored) {
124100
}
125101
}
126-
if (mockedReporter != null) {
102+
if (mockedPropertiesHelper != null) {
127103
try {
128-
mockedReporter.close();
104+
mockedPropertiesHelper.close();
105+
mockedPropertiesHelper = null;
129106
} catch (Exception ignored) {
130107
}
131108
}
132109
}
133110

111+
@AfterClass(alwaysRun = true)
112+
public void afterClass() {
113+
// Safety net: ensure all static mocks are closed after all tests
114+
closeStaticMocks();
115+
}
116+
134117
@Test
135118
public void testConstructorWithoutParameters() {
136119
DriverFactoryHelper helper = new DriverFactoryHelper();

src/test/java/testPackage/locator/LocatorBuilderTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LocatorBuilderTest {
1515
@BeforeMethod
1616
public void beforeMethod() {
1717
driver.set(new SHAFT.GUI.WebDriver());
18-
driver.get().browser().navigateToURL("https://shafthq.github.io/");
18+
driver.get().browser().navigateToURL("https://shaftengine.netlify.app/");
1919
}
2020

2121
@AfterMethod(alwaysRun = true)
@@ -89,31 +89,31 @@ public void hasText() {
8989
@Test
9090
public void hasIndex() {
9191
By locator = Locator.hasTagName("p").hasIndex(1).build();
92-
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
92+
driver.get().assertThat().element(locator).text().contains("Write once, test everywhere").perform();
9393
}
9494

9595
@Test
9696
public void isFirst() {
9797
By locator = Locator.hasTagName("p").isFirst().build();
98-
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
98+
driver.get().assertThat().element(locator).text().contains("Write once, test everywhere").perform();
9999
}
100100

101101
@Test
102102
public void isLast() {
103103
By locator = Locator.hasTagName("p").isLast().build();
104-
driver.get().assertThat().element(locator).text().contains("What are you waiting for?").perform();
104+
driver.get().assertThat().element(locator).text().contains("Ready to transform your test automation?").perform();
105105
}
106106

107107
@Test
108108
public void byRelation() {
109109
By locator = Locator.hasTagName("a").byRelation().below(Locator.hasTagName("h1").containsText("SHAFT").build());
110-
driver.get().assertThat().element(locator).text().contains("Upgrade Now").perform();
110+
driver.get().assertThat().element(locator).text().contains("Get Started Free").perform();
111111
}
112112

113113
@Test
114114
public void byAxis_followingSibling() {
115115
By locator = Locator.hasTagName("h1").containsText("SHAFT").byAxis().followingSibling("p").build();
116-
driver.get().assertThat().element(locator).text().contains("Stop reinventing the wheel").perform();
116+
driver.get().assertThat().element(locator).text().contains("Write once, test everywhere").perform();
117117
}
118118

119119
@Test
@@ -130,8 +130,8 @@ public void byRoleHeading() {
130130

131131
@Test
132132
public void byRoleButton() {
133-
By locator = Locator.hasRole(Role.BUTTON).and().containsText("Upgrade").isFirst().build();
134-
driver.get().assertThat().element(locator).text().isEqualTo("⚡ Upgrade Now ⚡").perform();
133+
By locator = Locator.hasRole(Role.BUTTON).and().containsText("Get Started").isFirst().build();
134+
driver.get().assertThat().element(locator).text().isEqualTo("Get Started Free ⚡").perform();
135135
}
136136

137137
@Test

src/test/java/testPackage/validationsWizard/NegativeValidationsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void url_failing() {
3232
@Test
3333
public void url_passing() {
3434
driver.get().browser().navigateToURL("https://shafthq.github.io/");
35-
driver.get().browser().assertThat().url().isEqualTo("https://shafthq.github.io/").perform();
35+
driver.get().browser().assertThat().url().isEqualTo("https://shaftengine.netlify.app/").perform();
3636
}
3737

3838
@Test(expectedExceptions = AssertionError.class)

0 commit comments

Comments
 (0)