-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests based on the Browserless container
- Loading branch information
1 parent
5bdbf75
commit dbeb9fc
Showing
4 changed files
with
172 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import org.testcontainers.containers.* | ||
import org.testcontainers.junit.jupiter.* | ||
import org.testcontainers.junit.jupiter.Container | ||
import org.testcontainers.utility.* | ||
import kotlin.test.* | ||
|
||
@Testcontainers | ||
class BrowserlessLocalIntegrationTests : IntegrationTestBase() { | ||
|
||
/** | ||
* A container running the Browserless with Chromium support. | ||
* It is meant to be used mostly with the web socket API, which is accessible directly at `ws://localhost:{port}` | ||
* (no need for an intermediate HTTP call). | ||
* | ||
* It provides a bridge to the JSON HTTP API of the DevTools protocol as well, but only for a subset of the | ||
* endpoints. See [Browser REST APIs](https://docs.browserless.io/open-api#tag/Browser-REST-APIs) in the docs. | ||
* | ||
* Also, there is [a bug](https://github.com/browserless/browserless/issues/4566) with the `/json/new` endpoint. | ||
*/ | ||
@Container | ||
var browserlessChromium: GenericContainer<*> = GenericContainer("ghcr.io/browserless/chromium:latest") | ||
.withExposedPorts(3000) | ||
.withCopyFileToContainer(MountableFile.forClasspathResource("/test-server-pages/"), "/test-server-pages/") | ||
|
||
override val httpUrl: String | ||
get() = "http://localhost:${browserlessChromium.firstMappedPort}" | ||
|
||
override val wsConnectUrl: String | ||
get() = "ws://localhost:${browserlessChromium.firstMappedPort}" | ||
|
||
@Ignore("The /json/new endpoint doesn't work with the HTTP API of Browserless: " + | ||
"https://github.com/browserless/browserless/issues/4566") | ||
override fun httpTabEndpoints() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import org.hildan.chrome.devtools.domains.dom.* | ||
import org.hildan.chrome.devtools.sessions.* | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.* | ||
|
||
abstract class LocalIntegrationTestBase : IntegrationTestBase() { | ||
|
||
private suspend fun PageSession.gotoTestPageResource(resourcePath: String) { | ||
goto("file:///test-server-pages/$resourcePath") | ||
} | ||
|
||
@Test | ||
fun attributesAccess() { | ||
runBlockingWithTimeout { | ||
chromeWebSocket().use { browser -> | ||
browser.newPage().use { page -> | ||
page.gotoTestPageResource("select.html") | ||
|
||
val nodeId = page.dom.findNodeBySelector("select[name=pets] option[selected]") | ||
assertNull(nodeId, "No option is selected in this <select>") | ||
|
||
val attributes1 = page.dom.getTypedAttributes("select[name=pets] option[selected]") | ||
assertNull(attributes1, "No option is selected in this <select>") | ||
|
||
val attributes2 = page.dom.getTypedAttributes("select[name=pets-selected] option[selected]") | ||
assertNotNull(attributes2, "There should be a selected option") | ||
assertEquals(true, attributes2.selected) | ||
assertEquals("cat", attributes2.value) | ||
val value = page.dom.getAttributeValue("select[name=pets-selected] option[selected]", "value") | ||
assertEquals("cat", value) | ||
// Attributes without value (e.g. "selected" in <option name="x" selected />) are returned as empty | ||
// strings by the protocol. | ||
val selected = page.dom.getAttributeValue("select[name=pets-selected] option[selected]", "selected") | ||
assertEquals("", selected) | ||
|
||
val absentValue = page.dom.getAttributeValue("select[name=pets-selected-without-value] option[selected]", "value") | ||
assertNull(absentValue, "There is no 'value' attribute in this select option") | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.