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;
@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);
+ }
}
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();
}
}
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;
/**
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());