Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<selenium.version>4.22.0</selenium.version>
<selenium.version>4.23.0</selenium.version>
<checkstyle.version>10.15.0</checkstyle.version>
<spotbugs.version>4.8.4</spotbugs.version>
<archunit.version>1.3.0</archunit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public Object apply(Object result) {
} catch (Exception e) {
// nothing to do here
}
return result;
}

return super.apply(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void shouldBeAbleToGetElementRect() throws Exception {
assertEquals("Failed getting element rect", HTTP_OK, response.getStatus());
Map<String, Object> elementRect = extractMap(response);
assertEquals("Element width", 1256L, elementRect.get("width"));
assertEquals("Element height", 72L, elementRect.get("height"));
assertEquals("Element height", 54L, elementRect.get("height"));
assertEquals("Element 'x' position", 5L, elementRect.get("x"));
assertEquals("Element 'y' position", 5L, elementRect.get("y"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.htmlunit.WebDriverTestCase;
Expand Down Expand Up @@ -60,6 +62,18 @@ public void setUp() {
sessionId = createDriverSession();
}

@After
public void cleanUp() {
if (sessionId != null) {
try {
closeDriverSession();
} catch (NoSuchSessionException e) {
// nothing to do here
}
sessionId = null;
}
}

@Override
protected WebDriver getWebDriver() {
return HtmlUnitDriverServer.getDriverSession(sessionId);
Expand Down Expand Up @@ -92,6 +106,21 @@ private static HttpRequest newSessionRequest(final Capabilities capabilities) {
return request;
}

private void closeDriverSession() throws NoSuchSessionException {
List<String> windowHandles = getWindowHandles(sessionId);
while ( ! windowHandles.isEmpty()) {
HttpResponse response = HtmlUnitDriverServer.closeWindow(sessionId);
assertEquals("Failed closing window", HTTP_OK, response.getStatus());
windowHandles = extractListOfStrings(response);
}
}

private List<String> getWindowHandles(final String sessionId) throws NoSuchSessionException {
HttpResponse response = HtmlUnitDriverServer.getWindowHandles(sessionId);
assertEquals("Failed getting window handles", HTTP_OK, response.getStatus());
return extractListOfStrings(response);
}

protected <T> T extractValueOfType(final HttpResponse response, final Type type) {
Map<String, T> content = fromJson(response, type);
assertTrue("Failed finding response value", content.containsKey("value"));
Expand Down