Skip to content

Commit

Permalink
stop test container in teardown and keep the option to run tests localy
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Jan 4, 2024
1 parent 082d8e4 commit 33bcc7a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ else if (canReuse(preventReuse, webDriverStateContainer))
// nothing to do here except for catching error of a second stop of the proxy
}
}
if (webDriverStateContainer.getTestcontainer() != null)
{
webDriverStateContainer.getTestcontainer().stop();
}
}

Neodymium.setWebDriverStateContainer(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
Expand Down Expand Up @@ -229,14 +230,18 @@ else if (Neodymium.configuration().useProxy())
options.addArguments(config.getArguments());
}

BrowserWebDriverContainer container = new BrowserWebDriverContainer()
.withCapabilities(options);
container.start();

wDSC.setWebDriver(
//new ChromeDriver(options)
new RemoteWebDriver(container.getSeleniumAddress(), options)
);
if (Neodymium.configuration().useTestContainers())
{
BrowserWebDriverContainer container = new BrowserWebDriverContainer()
.withCapabilities(options);
container.start();
wDSC.setTestcontainer(container);
wDSC.setWebDriver(new RemoteWebDriver(container.getSeleniumAddress(), options));
}
else
{
wDSC.setWebDriver(new ChromeDriver(options));
}
}
else if (firefoxBrowsers.contains(browserName))
{
Expand All @@ -249,7 +254,19 @@ else if (firefoxBrowsers.contains(browserName))
options.addArguments(config.getArguments());
}

wDSC.setWebDriver(new FirefoxDriver(options));
if (Neodymium.configuration().useTestContainers())
{
BrowserWebDriverContainer container = new BrowserWebDriverContainer().withCapabilities(options);
container.start();

wDSC.setTestcontainer(container);
wDSC.setWebDriver(
new RemoteWebDriver(container.getSeleniumAddress(), options));
}
else
{
wDSC.setWebDriver(new FirefoxDriver(options));
}
}
else if (internetExplorerBrowsers.contains(browserName))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xceptance.neodymium.module.statement.browser.multibrowser;

import org.openqa.selenium.WebDriver;
import org.testcontainers.containers.BrowserWebDriverContainer;

import com.browserup.bup.BrowserUpProxy;

Expand All @@ -12,6 +13,8 @@ public class WebDriverStateContainer

private BrowserUpProxy proxy;

private BrowserWebDriverContainer testcontainer;

public WebDriver getWebDriver()
{
return webDriver;
Expand Down Expand Up @@ -41,4 +44,14 @@ public void incrementUsedCount()
{
usedCount++;
}

public BrowserWebDriverContainer getTestcontainer()
{
return testcontainer;
}

public void setTestcontainer(BrowserWebDriverContainer testcontainer)
{
this.testcontainer = testcontainer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ public interface NeodymiumConfiguration extends Mutable

@Key("neodymium.testNameFilter")
public String getTestNameFilter();

@Key("neodymium.useTestContainers")
@DefaultValue("false")
public boolean useTestContainers();
}

0 comments on commit 33bcc7a

Please sign in to comment.