Skip to content

Commit

Permalink
Add convenience methods to interact with container (#69)
Browse files Browse the repository at this point in the history
* added direct access to BrowserWebDriverContainer via getContainer().

* Added references with @see to javadoc
  • Loading branch information
sbglasius authored Nov 7, 2024
1 parent a66920f commit 23a3044
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class ContainerGebSpec extends GebSpec {
throw new IllegalStateException('Test class must be annotated with @Integration for serverPort to be injected')
}
webDriverContainer = new BrowserWebDriverContainer()
Testcontainers.exposeHostPorts(serverPort)
webDriverContainer.tap {
addExposedPort(serverPort)
withAccessToHost(true)
start()
}
Testcontainers.exposeHostPorts(serverPort)
if (hostName != DEFAULT_HOSTNAME) {
webDriverContainer.execInContainer('/bin/sh', '-c', "echo '$hostIp\t$hostName' | sudo tee -a /etc/hosts")
}
Expand All @@ -82,6 +82,18 @@ class ContainerGebSpec extends GebSpec {
webDriverContainer?.stop()
}

/**
* Get access to container running the web-driver, for convenience to execInContainer, copyFileToContainer etc.
*
* @see org.testcontainers.containers.ContainerState#execInContainer(java.lang.String ...)
* @see org.testcontainers.containers.ContainerState#copyFileToContainer(org.testcontainers.utility.MountableFile, java.lang.String)
* @see org.testcontainers.containers.ContainerState#copyFileFromContainer(java.lang.String, java.lang.String)
* @see org.testcontainers.containers.ContainerState
*/
BrowserWebDriverContainer getContainer() {
return webDriverContainer
}

/**
* Returns the protocol that the browser will use to access the server under test.
* <p>Defaults to {@code http}.
Expand Down

0 comments on commit 23a3044

Please sign in to comment.