I am trying to integrate selenium into test pipeline of my spring boot application.
During test i run application (using spring boot test), after that testcontainers runs selenium. After that selenium container should run test.
The problem: selenium can’t connect to the host network.
@SpringBootTest(
classes = [StatisticServer::class],
webEnvironment = RANDOM_PORTq)
@ContextConfiguration(initializers = [DbTextContextInitializer::class])
@ActiveProfiles("local", "no-security")
@Sql(executionPhase = AFTER_TEST_METHOD, scripts = ["classpath:/sql/clear_db.sql"])
class SeleniumParentTest {
@LocalServerPort
protected var port=0
class KWebDriverContainer(dockerImage: String) : BrowserWebDriverContainer<KWebDriverContainer>(dockerImage)
var chrome: BrowserWebDriverContainer<*> = KWebDriverContainer("selenium/standalone-chrome-debug:latest")
.withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL, File("build"))
.withCapabilities(ChromeOptions().setAcceptInsecureCerts(true))
.withEnv("http_host", "http://192.168.5.46:8080")
.withNetworkMode("host")
@BeforeEach
fun setUp() {
chrome.start()
val driver = chrome.getWebDriver()
WebDriverRunner.setWebDriver(driver)
}
@AfterEach
fun tearDown() {
WebDriverRunner.closeWebDriver();
}
@Test
fun shouldSuccessfullyPassThisTestUsingTheRemoteDriver() {
open("https://127.0.0.1:9200/swagger-ui.html");
// open("https://host.docker.internal:$port/swagger-ui.html");
`$`(By.className("info")).value
val link = `$`("#res .g", 0).find("a")
I tried several ways to solve such issue like adding network mode, use internal docker hostname.
During test execution I get a screenshot with “This site can’t be reached”
I can’t use getTestHostIpAdress() because I use cents.
So, my question is: how to set up testcontainers correctly to be able test web app running locally?