Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
fixes #454
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Mar 31, 2023
1 parent 142e05b commit 3250ab6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 136 deletions.
4 changes: 1 addition & 3 deletions src/test/kotlin/kweb/HistoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class HistoryTest {
}

@Test
fun testBackButton(@Arguments("--headless") driver : WebDriver) {
WebDriverManager.chromedriver().setup()

fun testBackButton(driver : ChromeDriver) {
historyTestApp.reloadCount.value shouldBe 0
driver.get("http://localhost:7665/0")

Expand Down
4 changes: 4 additions & 0 deletions src/test/kotlin/kweb/HrefTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class HrefTest {
companion object {
private lateinit var hrefTestApp: HrefTestApp

init {
System.setProperty("webdriver.http.factory", "jdk-http-client")
}

@JvmStatic
@BeforeAll
fun setupServer() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/kweb/InputCheckedTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ThreadGuard

@ExtendWith(SeleniumJupiter::class)
class InputCheckedTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class InputCheckedTest {

companion object {
private lateinit var inputCheckedTestApp: InputCheckedTestApp
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/kweb/SelectInitialValueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ThreadGuard

@ExtendWith(SeleniumJupiter::class)
class SelectInitialValueTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class SelectInitialValueTest {

companion object {
private lateinit var selectInitialValueTestApp: SelectInitialValueTestApp
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/kweb/SelectValueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.openqa.selenium.support.ThreadGuard
import org.openqa.selenium.support.ui.Select

@ExtendWith(SeleniumJupiter::class)
class SelectValueTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class SelectValueTest {
companion object {
private lateinit var selectValueTestApp: SelectValueTestApp

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/kweb/StringDiffTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ThreadGuard

@ExtendWith(SeleniumJupiter::class)
class StringDiffTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class StringDiffTest {

companion object {
init {
Expand Down
115 changes: 0 additions & 115 deletions src/test/kotlin/kweb/state/render/RenderCleanupTest.kt

This file was deleted.

36 changes: 22 additions & 14 deletions src/test/kotlin/kweb/state/render/RenderEachTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kweb.state.render

import io.github.bonigarcia.seljup.Arguments
import io.github.bonigarcia.seljup.Options
import io.github.bonigarcia.seljup.SeleniumJupiter
import io.kotest.matchers.shouldBe
import kweb.*
Expand All @@ -13,15 +14,22 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.support.ThreadGuard

@ExtendWith(SeleniumJupiter::class)
class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class RenderEachTest {

//ThreadGuard.protect ensures that the ChromeDriver can only be called by the thread that created it
//This should make this test thread safe.
val driver = ThreadGuard.protect(unprotectedDriver)
companion object {
init {
System.setProperty("webdriver.http.factory", "jdk-http-client")
}

@Options
var chromeOptions = ChromeOptions().apply {
addArguments("--headless=new")
}
}

/*NOTE: Thread.sleep(50) is used throughout these tests. I had success with values as small as Thread.sleep(1)
But for consistent success, I left it at 50.
Expand All @@ -30,7 +38,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
It's an issue with Selenium, the client, clicking a button, and then giving the server literally 0 time to respond. */

@Test
fun prependItemTest() {
fun prependItemTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Horse"))

val server = Kweb(port = 1240, buildPage = {
Expand Down Expand Up @@ -63,7 +71,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun appendItemTest() {
fun appendItemTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Horse"))

val server = Kweb(port = 1241, buildPage = {
Expand Down Expand Up @@ -96,7 +104,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun insertItemTest() {
fun insertItemTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Horse"))

val server = Kweb(port = 1242, buildPage = {
Expand Down Expand Up @@ -129,7 +137,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun changeItemTest() {
fun changeItemTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear"))

val server = Kweb(port = 1243, buildPage = {
Expand Down Expand Up @@ -157,7 +165,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun deleteItemTest() {
fun deleteItemTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Aardvark", "Bear", "Cow", "Dog", "Elephant"))

val server = Kweb(port = 1244, buildPage = {
Expand Down Expand Up @@ -215,7 +223,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun moveItemFromEndToCenterTest() {
fun moveItemFromEndToCenterTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Moose", "Horse"))

val server = Kweb(port = 1245, buildPage = {
Expand Down Expand Up @@ -248,7 +256,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun moveItemFromStartToEnd() {
fun moveItemFromStartToEnd(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Moose", "Horse"))

val server = Kweb(port = 1246, buildPage = {
Expand Down Expand Up @@ -281,7 +289,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun moveItemFromEndToStart() {
fun moveItemFromEndToStart(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Moose", "Horse"))

val server = Kweb(port = 1247, buildPage = {
Expand Down Expand Up @@ -314,7 +322,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun ClearItemsTest() {
fun ClearItemsTest(driver : ChromeDriver) {
val animals = ObservableList(mutableListOf("Dog", "Cat", "Bear", "Moose", "Horse"))

val server = Kweb(port = 1248, buildPage = {
Expand Down Expand Up @@ -343,7 +351,7 @@ class RenderEachTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
}

@Test
fun nestedRenderEachTest() {
fun nestedRenderEachTest(driver : ChromeDriver) {
val planets = ObservableList(mutableListOf())
val jupiter = ObservableList(mutableListOf("Io", "Europa", "Ganymede", "Callisto"))
val saturn = ObservableList(mutableListOf("Titan", "Rhea", "Enceladus", "Mimas", "Phoebe"))
Expand Down

0 comments on commit 3250ab6

Please sign in to comment.