Skip to content

Commit

Permalink
start Grid server only once, not a new server for every test
Browse files Browse the repository at this point in the history
we are not stopping the previous servers, thus getting OutOfMemory very quickly.
  • Loading branch information
asolntsev committed Feb 22, 2024
1 parent b3d8029 commit 12ffae0
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions modules/grid/src/test/java/integration/AbstractGridTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codeborne.selenide.Configuration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.grid.Main;
import org.slf4j.Logger;
Expand All @@ -16,37 +17,37 @@
import static org.openqa.selenium.net.PortProber.findFreePort;

abstract class AbstractGridTest extends IntegrationTest {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final Logger log = LoggerFactory.getLogger(AbstractGridTest.class);

protected URL gridUrl;
protected static URL gridUrl;

@BeforeEach
final void setUpGrid() throws MalformedURLException {
@AfterEach
final void resetWebDriver() {
closeWebDriver();

for (int tries = 0; tries < 3; tries++) {
int port = findFreePort();
try {
Main.main(new String[]{"standalone",
"--port", String.valueOf(port),
"--enable-managed-downloads", "true",
"--selenium-manager", "true"
});
gridUrl = new URL("http://localhost:" + port + "/wd/hub");
break;
}
catch (UncheckedIOException portAlreadyUsed) {
log.warn("Failed to start Selenium Grid on port {}", port, portAlreadyUsed);
}
}

timeout = 4000;
Configuration.remote = null;
}

@AfterEach
final void tearDownGrid() {
closeWebDriver();
gridUrl = null;
Configuration.remote = null;
@BeforeAll
static synchronized void setUpGrid() throws MalformedURLException {
if (gridUrl == null) {
for (int tries = 0; tries < 3; tries++) {
int port = findFreePort();
try {
Main.main(new String[]{
"standalone",
"--port", String.valueOf(port),
"--enable-managed-downloads", "true",
"--selenium-manager", "true"
});
gridUrl = new URL("http://localhost:" + port + "/wd/hub");
break;
}
catch (UncheckedIOException portAlreadyUsed) {
log.warn("Failed to start Selenium Grid on port {}", port, portAlreadyUsed);
}
}
}
}
}

0 comments on commit 12ffae0

Please sign in to comment.