From 029b48793ddfa1af8778b9121bf9daaa58601344 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 22 Jan 2020 23:57:48 +0100 Subject: [PATCH] WIP --- .../java/de/juplo/demo/DemoControllerIT.java | 21 +++++++++++++++++-- .../de/juplo/demo/WebDriverExtension.java | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/test/java/de/juplo/demo/DemoControllerIT.java b/src/test/java/de/juplo/demo/DemoControllerIT.java index 4873566..bd9dcd2 100644 --- a/src/test/java/de/juplo/demo/DemoControllerIT.java +++ b/src/test/java/de/juplo/demo/DemoControllerIT.java @@ -1,6 +1,10 @@ package de.juplo.demo; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketException; +import java.net.UnknownHostException; import lombok.extern.slf4j.Slf4j; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import org.junit.jupiter.api.BeforeEach; @@ -31,7 +35,19 @@ public class DemoControllerIT @BeforeEach() void generateBaseUri() { - baseUri = "http://localhost:" + port; + try (final DatagramSocket socket = new DatagramSocket()) + { + socket.connect(InetAddress.getByName("8.8.8.8"), 10002); + baseUri = + "http://" + + socket.getLocalAddress().getHostAddress() + + ":" + + port; + } + catch (SocketException | UnknownHostException e) + { + throw new RuntimeException(e); + } } @@ -39,8 +55,9 @@ public class DemoControllerIT void testSubmit(RemoteWebDriver driver) { driver.get(baseUri + "/"); + log.info("Fetched page:\n\n{}\n", driver.getPageSource()); - WebElement submit = driver.findElement(By.xpath("//*[@class=\"card-footer\"]/button")); + WebElement submit = driver.findElement(By.cssSelector(".card-footer > button")); assertThat(submit).isNotNull(); } } diff --git a/src/test/java/de/juplo/demo/WebDriverExtension.java b/src/test/java/de/juplo/demo/WebDriverExtension.java index 9de61bb..bbbe82b 100644 --- a/src/test/java/de/juplo/demo/WebDriverExtension.java +++ b/src/test/java/de/juplo/demo/WebDriverExtension.java @@ -11,6 +11,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testcontainers.containers.BrowserWebDriverContainer; +import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL; /** @@ -31,7 +32,7 @@ public class WebDriverExtension implements BeforeAllCallback, ParameterResolver chrome = new BrowserWebDriverContainer() .withCapabilities(DesiredCapabilities.chrome()) - .withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL, new File("./target/")); + .withRecordingMode(RECORD_ALL, new File("./target/")); log.info("Starting {}", chrome.getDockerImageName()); chrome.start(); log.info("Selenium-Address: {}", chrome.getSeleniumAddress()); -- 2.20.1