Skip to content

Commit

Permalink
Add corner case test (#11970)
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
rishav887 authored May 2, 2023
1 parent 9ac368b commit e5805a4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
22 changes: 14 additions & 8 deletions java/test/com/thoughtworks/selenium/BaseSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,26 @@ public static void setup() {

}


@AfterAll
public static void teardown() {
// browser
log.info("Stopping browser");
log.info("Stopping browser...");
try {
InternalSelenseTestBase.destroyDriver();
} catch (SeleniumException ignored) {
// Nothing sane to do
InternalSelenseTestBase.destroyDriver();
log.info("Browser stopped successfully.");
} catch (SeleniumException e) {
log.error("Failed to stop browser: {}", e.getMessage());
}

// testEnvironment
log.info("Cleaning test environment");
GlobalTestEnvironment.stop();

}
log.info("Cleaning test environment...");
try {
GlobalTestEnvironment.stop();
log.info("Test environment cleaned successfully.");
} catch (Exception e) {
log.error("Failed to clean test environment: {}", e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ void testGetBooleanArray() {
assertEquals(boolCmdResults[1], methodResults[1]);
}

@Test
void testResourcesClosedWhenIoeOnGetOutputStream() {
IOEThrowingHttpCommandProcessor cmdProc = new IOEThrowingHttpCommandProcessor(
"localhost", 4444, "*chrome", "http://www.google.com");
cmdProc.throwIoeOnGetOutputStream = true;
try {
cmdProc.getCommandResponseAsString("testCommand");
fail();
} catch (IOException ioe) {
cmdProc.verifyClosedResources(false, true, true);
}
}


/**
* Inner class to help mock out the network and pipe connections to verify that they are closed
* regardless of where IOExceptions occur.
Expand Down
17 changes: 17 additions & 0 deletions java/test/com/thoughtworks/selenium/condition/ConditionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ public boolean isTrue(ConditionRunner.Context runner) {
}
}

@Test
void testAssertionFailureInConditionIsNotWrapped() {
Condition condition = new Condition() {
@Override
public boolean isTrue(ConditionRunner.Context runner) {
double result = 10.0 / 0.0;
return false;
}
};
try {
conditionRunner.waitFor(condition);
fail("should have thrown an assertion failed error");
} catch (AssertionError expected) {
assertTrue(expected.getMessage().contains("/ by zero"));
}
}

@Test
void testMessageWithArgs() {
final RuntimeException thrownException = new RuntimeException();
Expand Down

0 comments on commit e5805a4

Please sign in to comment.