Browse Source

Prepare integration tests for possibility to run against Firefox

pull/833/head
Shagen Ogandzhanian 3 years ago
parent
commit
2de373c7db
  1. 1
      web/integration-core/build.gradle.kts
  2. 81
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/InputsTests.kt
  3. 42
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/IntegrationTests.kt
  4. 66
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/BaseIntegrationTests.kt
  5. 19
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/DisplayNameSimplifier.kt
  6. 20
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/WithChromeDriver.kt

1
web/integration-core/build.gradle.kts

@ -66,6 +66,7 @@ kotlin {
implementation("org.junit.jupiter:junit-jupiter-engine:5.7.1") implementation("org.junit.jupiter:junit-jupiter-engine:5.7.1")
implementation("org.junit.jupiter:junit-jupiter-api:5.7.1") implementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
implementation("org.junit.jupiter:junit-jupiter-params:5.7.1")
} }
} }
} }

81
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/InputsTests.kt

@ -1,76 +1,77 @@
package org.jetbrains.compose.web.tests.integration package org.jetbrains.compose.web.tests.integration
import org.jetbrains.compose.web.tests.integration.common.BaseIntegrationTests import org.jetbrains.compose.web.tests.integration.common.BaseIntegrationTests
import org.jetbrains.compose.web.tests.integration.common.ResolveDrivers
import org.jetbrains.compose.web.tests.integration.common.openTestPage import org.jetbrains.compose.web.tests.integration.common.openTestPage
import org.jetbrains.compose.web.tests.integration.common.waitTextToBe import org.jetbrains.compose.web.tests.integration.common.waitTextToBe
import org.junit.jupiter.api.Test
import org.openqa.selenium.By import org.openqa.selenium.By
import org.openqa.selenium.Keys import org.openqa.selenium.Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions import org.openqa.selenium.interactions.Actions
class InputsTests : BaseIntegrationTests() { class InputsTests : BaseIntegrationTests() {
@Test @ResolveDrivers
fun `text area input gets printed`() { fun `text area input gets printed`(driver: WebDriver) {
openTestPage("textAreaInputGetsPrinted") driver.openTestPage("textAreaInputGetsPrinted")
val input = driver.findElement(By.id("input")) val input = driver.findElement(By.id("input"))
input.sendKeys("Hello textArea!") input.sendKeys("Hello textArea!")
waitTextToBe(textId = "txt", value = "Hello textArea!") driver.waitTextToBe(textId = "txt", value = "Hello textArea!")
} }
@Test @ResolveDrivers
fun `text input gets printed`() { fun `text input gets printed`(driver: WebDriver) {
openTestPage("textInputGetsPrinted") driver.openTestPage("textInputGetsPrinted")
val input = driver.findElement(By.id("input")) val input = driver.findElement(By.id("input"))
input.sendKeys("Hello World!") input.sendKeys("Hello World!")
waitTextToBe(textId = "txt", value = "Hello World!") driver.waitTextToBe(textId = "txt", value = "Hello World!")
} }
@Test @ResolveDrivers
fun `checkbox changes the text`() { fun `checkbox changes the text`(driver: WebDriver) {
openTestPage("checkBoxChangesText") driver.openTestPage("checkBoxChangesText")
waitTextToBe(textId = "txt", value = "not checked") driver.waitTextToBe(textId = "txt", value = "not checked")
val checkbox = driver.findElement(By.id("checkbox")) val checkbox = driver.findElement(By.id("checkbox"))
checkbox.click() checkbox.click()
waitTextToBe(textId = "txt", value = "checked") driver.waitTextToBe(textId = "txt", value = "checked")
checkbox.click() checkbox.click()
waitTextToBe(textId = "txt", value = "not checked") driver.waitTextToBe(textId = "txt", value = "not checked")
} }
@Test @ResolveDrivers
fun `radio buttons change the text`() { fun `radio buttons change the text`(driver: WebDriver) {
openTestPage("radioButtonsChangeText") driver.openTestPage("radioButtonsChangeText")
waitTextToBe(textId = "txt", value = "-") driver.waitTextToBe(textId = "txt", value = "-")
val r1 = driver.findElement(By.id("r1")) val r1 = driver.findElement(By.id("r1"))
val r2 = driver.findElement(By.id("r2")) val r2 = driver.findElement(By.id("r2"))
r1.click() r1.click()
waitTextToBe(textId = "txt", "r1") driver.waitTextToBe(textId = "txt", "r1")
r2.click() r2.click()
waitTextToBe(textId = "txt", "r2") driver.waitTextToBe(textId = "txt", "r2")
r1.click() r1.click()
waitTextToBe(textId = "txt", "r1") driver.waitTextToBe(textId = "txt", "r1")
r2.click() r2.click()
waitTextToBe(textId = "txt", "r2") driver.waitTextToBe(textId = "txt", "r2")
} }
@Test @ResolveDrivers
fun `range updates the text`() { fun `range updates the text`(driver: WebDriver) {
openTestPage("rangeInputChangesText") driver.openTestPage("rangeInputChangesText")
waitTextToBe(value = "0") driver.waitTextToBe(value = "0")
val slider = driver.findElement(By.id("slider")) val slider = driver.findElement(By.id("slider"))
@ -82,22 +83,22 @@ class InputsTests : BaseIntegrationTests() {
.sendKeys(Keys.RIGHT, Keys.RIGHT) .sendKeys(Keys.RIGHT, Keys.RIGHT)
.perform() .perform()
waitTextToBe(value = "10") driver.waitTextToBe(value = "10")
} }
@Test @ResolveDrivers
fun `time input updates the text`() { fun `time input updates the text`(driver: WebDriver) {
openTestPage("timeInputChangesText") driver.openTestPage("timeInputChangesText")
waitTextToBe(value = "") driver.waitTextToBe(value = "")
val timeInput = driver.findElement(By.id("time")) val timeInput = driver.findElement(By.id("time"))
timeInput.sendKeys("15:00") timeInput.sendKeys("15:00")
waitTextToBe(value = "15:00") driver.waitTextToBe(value = "15:00")
} }
// @Test // @_root_ide_package_.org.jetbrains.compose.web.tests.integration.common.ResolveDrivers
// fun `date input updates the text`() { // fun `date input updates the text`() {
// openTestPage("dateInputChangesText") // openTestPage("dateInputChangesText")
// //
@ -109,7 +110,7 @@ class InputsTests : BaseIntegrationTests() {
// waitTextToBe(value = "2021-10-12") // waitTextToBe(value = "2021-10-12")
// } // }
// @Test // @_root_ide_package_.org.jetbrains.compose.web.tests.integration.common.ResolveDrivers
// fun `dateTimeLocal input updates the text`() { // WARNING: It's not supported in Firefox // fun `dateTimeLocal input updates the text`() { // WARNING: It's not supported in Firefox
// openTestPage("dateTimeLocalInputChangesText") // openTestPage("dateTimeLocalInputChangesText")
// //
@ -121,16 +122,16 @@ class InputsTests : BaseIntegrationTests() {
// waitTextToBe(value = "2021-10-12T09:25") // waitTextToBe(value = "2021-10-12T09:25")
// } // }
@Test @ResolveDrivers
fun `file input updates the text`() { fun `file input updates the text`(driver: WebDriver) {
openTestPage("fileInputChangesText") driver.openTestPage("fileInputChangesText")
waitTextToBe(value = "") driver.waitTextToBe(value = "")
val fileInput = driver.findElement(By.id("file")) val fileInput = driver.findElement(By.id("file"))
val homePath = System.getProperty("COMPOSE_WEB_INTEGRATION_TESTS_DISTRIBUTION") val homePath = System.getProperty("COMPOSE_WEB_INTEGRATION_TESTS_DISTRIBUTION")
fileInput.sendKeys("$homePath/index.html") fileInput.sendKeys("$homePath/index.html")
waitTextToBe(value = "C:\\fakepath\\index.html") driver.waitTextToBe(value = "C:\\fakepath\\index.html")
} }
} }

42
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/IntegrationTests.kt

@ -1,68 +1,72 @@
package org.jetbrains.compose.web.tests.integration package org.jetbrains.compose.web.tests.integration
import org.jetbrains.compose.web.tests.integration.common.BaseIntegrationTests import org.jetbrains.compose.web.tests.integration.common.BaseIntegrationTests
import org.jetbrains.compose.web.tests.integration.common.Drivers
import org.jetbrains.compose.web.tests.integration.common.ResolveDrivers
import org.jetbrains.compose.web.tests.integration.common.openTestPage import org.jetbrains.compose.web.tests.integration.common.openTestPage
import org.jetbrains.compose.web.tests.integration.common.waitTextToBe import org.jetbrains.compose.web.tests.integration.common.waitTextToBe
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.openqa.selenium.By import org.openqa.selenium.By
import org.openqa.selenium.Dimension import org.openqa.selenium.Dimension
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions import org.openqa.selenium.interactions.Actions
import org.openqa.selenium.remote.RemoteWebDriver
class IntegrationTests : BaseIntegrationTests() { class IntegrationTests : BaseIntegrationTests() {
@Test @ResolveDrivers
fun `text contains Hello World`() { fun `text contains Hello World`(driver: RemoteWebDriver) {
openTestPage("helloWorldText") driver.openTestPage("helloWorldText")
assertEquals( assertEquals(
"Hello World!", "Hello World!",
driver.findElementByTagName("div").text driver.findElementByTagName("div").text
) )
} }
@Test @ResolveDrivers
fun `multiple clicks on button update the counter after every click`() { fun `multiple clicks on button update the counter after every click`(driver: WebDriver) {
openTestPage("buttonClicksUpdateCounterValue") driver.openTestPage("buttonClicksUpdateCounterValue")
val button = driver.findElement(By.id("btn")) val button = driver.findElement(By.id("btn"))
waitTextToBe(textId = "txt", value = "0") driver.waitTextToBe(textId = "txt", value = "0")
repeat(3) { repeat(3) {
button.click() button.click()
waitTextToBe(textId = "txt", value = (it + 1).toString()) driver.waitTextToBe(textId = "txt", value = (it + 1).toString())
} }
} }
@Test @ResolveDrivers
fun `hovering the box updates the text`() { fun `hovering the box updates the text`(driver: WebDriver) {
openTestPage("hoverOnDivUpdatesText") driver.openTestPage("hoverOnDivUpdatesText")
val box = driver.findElement(By.id("box")) val box = driver.findElement(By.id("box"))
waitTextToBe(textId = "txt", value = "not hovered") driver.waitTextToBe(textId = "txt", value = "not hovered")
val actions = Actions(driver) val actions = Actions(driver)
actions.moveToElement(box).perform() actions.moveToElement(box).perform()
waitTextToBe(textId = "txt", value = "hovered") driver.waitTextToBe(textId = "txt", value = "hovered")
actions.moveByOffset(300, 0).perform() actions.moveByOffset(300, 0).perform()
waitTextToBe(textId = "txt", value = "not hovered") driver.waitTextToBe(textId = "txt", value = "not hovered")
} }
@Test @ResolveDrivers
fun `making screen width less than 400px changes the text color`() { fun `making screen width less than 400px changes the text color`(driver: WebDriver) {
openTestPage("smallWidthChangesTheTextColor") driver.openTestPage("smallWidthChangesTheTextColor")
val initialWindowSize = driver.manage().window().size val initialWindowSize = driver.manage().window().size
try { try {
val span = driver.findElement(By.id("span1")) val span = driver.findElement(By.id("span1"))
waitTextToBe(textId = "span1", "This a colored text") driver.waitTextToBe(textId = "span1", "This a colored text")
driver.manage().window().size = Dimension(1000, 1000) driver.manage().window().size = Dimension(1000, 1000)
assertEquals("rgba(0, 0, 0, 1)", span.getCssValue("color")) assertEquals("rgba(0, 0, 0, 1)", span.getCssValue("color"))
driver.manage().window().size = Dimension(300, 300) driver.manage().window().size = Dimension(300, 300)
waitTextToBe(textId = "span1", "This a colored text") driver.waitTextToBe(textId = "span1", "This a colored text")
assertEquals("rgba(255, 0, 0, 1)", span.getCssValue("color")) assertEquals("rgba(255, 0, 0, 1)", span.getCssValue("color"))
} finally { } finally {

66
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/BaseIntegrationTests.kt

@ -1,19 +1,75 @@
package org.jetbrains.compose.web.tests.integration.common package org.jetbrains.compose.web.tests.integration.common
import org.junit.jupiter.api.DisplayNameGeneration
import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.remote.RemoteWebDriver import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.safari.SafariDriver
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
@ExtendWith(value = [StaticServerSetupExtension::class])
abstract class BaseIntegrationTests {
companion object : WithChromeDriver { private val PATH = "http://localhost:${ServerLauncher.port}"
override val driver: RemoteWebDriver = ChromeDriver(
fun WebDriver.openTestPage(test: String) {
get("$PATH?test=$test")
}
fun WebDriver.waitTextToBe(textId: String = "txt", value: String) {
WebDriverWait(this, 1).until(ExpectedConditions.textToBe(By.id(textId), value))
}
object Drivers {
val Chrome by lazy {
object : ChromeDriver(
ChromeOptions().apply { ChromeOptions().apply {
setHeadless(true) setHeadless(true)
addArguments("--no-sandbox") addArguments("--no-sandbox")
} }
) ) {
override fun toString(): String = "chrome"
}
}
val Firefox by lazy {
object : FirefoxDriver(
FirefoxOptions().apply {
setHeadless(true)
}
) {
override fun toString(): String = "firefox"
}
}
val Safari by lazy {
object : SafariDriver() {
override fun toString(): String = "safari"
}
}
}
@Target(AnnotationTarget.FUNCTION)
@ParameterizedTest(name = "{displayName} [{0}]")
@MethodSource("resolveDrivers")
annotation class ResolveDrivers
@DisplayNameGeneration(DisplayNameSimplifier::class)
@ExtendWith(value = [StaticServerSetupExtension::class])
abstract class BaseIntegrationTests() {
companion object {
@JvmStatic
fun resolveDrivers(): Array<Array<Any>> {
return arrayOf(
arrayOf(Drivers.Chrome)
)
}
} }
} }

19
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/DisplayNameSimplifier.kt

@ -0,0 +1,19 @@
/*
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.compose.web.tests.integration.common
import org.junit.jupiter.api.DisplayNameGenerator
import java.lang.reflect.Method
class DisplayNameSimplifier : DisplayNameGenerator.Standard() {
override fun generateDisplayNameForMethod(testClass: Class<*>?, testMethod: Method?): String {
return super
.generateDisplayNameForMethod(testClass, testMethod)
.replace("WebDriver", "")
.replace("()", "")
.plus(" ")
}
}

20
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/common/WithChromeDriver.kt

@ -1,20 +0,0 @@
package org.jetbrains.compose.web.tests.integration.common
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.By
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
interface WithChromeDriver {
val driver: RemoteWebDriver
}
private val PATH = "http://localhost:${ServerLauncher.port}"
fun WithChromeDriver.openTestPage(test: String) {
driver.get("$PATH?test=$test")
}
fun WithChromeDriver.waitTextToBe(textId: String = "txt", value: String) {
WebDriverWait(driver, 1).until(ExpectedConditions.textToBe(By.id(textId), value))
}
Loading…
Cancel
Save