WIP
authorKai Moritz <kai@juplo.de>
Wed, 22 Jan 2020 22:57:48 +0000 (23:57 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 7 Apr 2023 11:15:40 +0000 (13:15 +0200)
src/test/java/de/juplo/demo/DemoControllerIT.java
src/test/java/de/juplo/demo/WebDriverExtension.java

index 4873566..bd9dcd2 100644 (file)
@@ -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();
   }
 }
index 9de61bb..bbbe82b 100644 (file)
@@ -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());