Skip to content

Commit e5805a4

Browse files
authored
Add corner case test (#11970)
Add some tests
1 parent 9ac368b commit e5805a4

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

java/test/com/thoughtworks/selenium/BaseSuite.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,26 @@ public static void setup() {
3838

3939
}
4040

41+
4142
@AfterAll
4243
public static void teardown() {
4344
// browser
44-
log.info("Stopping browser");
45+
log.info("Stopping browser...");
4546
try {
46-
InternalSelenseTestBase.destroyDriver();
47-
} catch (SeleniumException ignored) {
48-
// Nothing sane to do
47+
InternalSelenseTestBase.destroyDriver();
48+
log.info("Browser stopped successfully.");
49+
} catch (SeleniumException e) {
50+
log.error("Failed to stop browser: {}", e.getMessage());
4951
}
5052

5153
// testEnvironment
52-
log.info("Cleaning test environment");
53-
GlobalTestEnvironment.stop();
54-
55-
}
54+
log.info("Cleaning test environment...");
55+
try {
56+
GlobalTestEnvironment.stop();
57+
log.info("Test environment cleaned successfully.");
58+
} catch (Exception e) {
59+
log.error("Failed to clean test environment: {}", e.getMessage());
60+
}
61+
}
5662

5763
}

java/test/com/thoughtworks/selenium/HttpCommandProcessorUnitTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ void testGetBooleanArray() {
127127
assertEquals(boolCmdResults[1], methodResults[1]);
128128
}
129129

130+
@Test
131+
void testResourcesClosedWhenIoeOnGetOutputStream() {
132+
IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor(
133+
"localhost", 4444, "*chrome", "http://www.google.com");
134+
cmdProc.throwIoeOnGetOutputStream = true;
135+
try {
136+
cmdProc.getCommandResponseAsString("testCommand");
137+
fail();
138+
} catch (IOException ioe) {
139+
cmdProc.verifyClosedResources(false, true, true);
140+
}
141+
}
142+
143+
130144
/**
131145
* Inner class to help mock out the network and pipe connections to verify that they are closed
132146
* regardless of where IOExceptions occur.

java/test/com/thoughtworks/selenium/condition/ConditionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ public boolean isTrue(ConditionRunner.Context runner) {
188188
}
189189
}
190190

191+
@Test
192+
void testAssertionFailureInConditionIsNotWrapped() {
193+
Condition condition = new Condition() {
194+
@Override
195+
public boolean isTrue(ConditionRunner.Context runner) {
196+
double result = 10.0 / 0.0;
197+
return false;
198+
}
199+
};
200+
try {
201+
conditionRunner.waitFor(condition);
202+
fail("should have thrown an assertion failed error");
203+
} catch (AssertionError expected) {
204+
assertTrue(expected.getMessage().contains("/ by zero"));
205+
}
206+
}
207+
191208
@Test
192209
void testMessageWithArgs() {
193210
final RuntimeException thrownException = new RuntimeException();

0 commit comments

Comments
 (0)