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. 64
      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-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
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.waitTextToBe
import org.junit.jupiter.api.Test
import org.openqa.selenium.By
import org.openqa.selenium.Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions
class InputsTests : BaseIntegrationTests() {
@Test
fun `text area input gets printed`() {
openTestPage("textAreaInputGetsPrinted")
@ResolveDrivers
fun `text area input gets printed`(driver: WebDriver) {
driver.openTestPage("textAreaInputGetsPrinted")
val input = driver.findElement(By.id("input"))
input.sendKeys("Hello textArea!")
waitTextToBe(textId = "txt", value = "Hello textArea!")
driver.waitTextToBe(textId = "txt", value = "Hello textArea!")
}
@Test
fun `text input gets printed`() {
openTestPage("textInputGetsPrinted")
@ResolveDrivers
fun `text input gets printed`(driver: WebDriver) {
driver.openTestPage("textInputGetsPrinted")
val input = driver.findElement(By.id("input"))
input.sendKeys("Hello World!")
waitTextToBe(textId = "txt", value = "Hello World!")
driver.waitTextToBe(textId = "txt", value = "Hello World!")
}
@Test
fun `checkbox changes the text`() {
openTestPage("checkBoxChangesText")
@ResolveDrivers
fun `checkbox changes the text`(driver: WebDriver) {
driver.openTestPage("checkBoxChangesText")
waitTextToBe(textId = "txt", value = "not checked")
driver.waitTextToBe(textId = "txt", value = "not checked")
val checkbox = driver.findElement(By.id("checkbox"))
checkbox.click()
waitTextToBe(textId = "txt", value = "checked")
driver.waitTextToBe(textId = "txt", value = "checked")
checkbox.click()
waitTextToBe(textId = "txt", value = "not checked")
driver.waitTextToBe(textId = "txt", value = "not checked")
}
@Test
fun `radio buttons change the text`() {
openTestPage("radioButtonsChangeText")
@ResolveDrivers
fun `radio buttons change the text`(driver: WebDriver) {
driver.openTestPage("radioButtonsChangeText")
waitTextToBe(textId = "txt", value = "-")
driver.waitTextToBe(textId = "txt", value = "-")
val r1 = driver.findElement(By.id("r1"))
val r2 = driver.findElement(By.id("r2"))
r1.click()
waitTextToBe(textId = "txt", "r1")
driver.waitTextToBe(textId = "txt", "r1")
r2.click()
waitTextToBe(textId = "txt", "r2")
driver.waitTextToBe(textId = "txt", "r2")
r1.click()
waitTextToBe(textId = "txt", "r1")
driver.waitTextToBe(textId = "txt", "r1")
r2.click()
waitTextToBe(textId = "txt", "r2")
driver.waitTextToBe(textId = "txt", "r2")
}
@Test
fun `range updates the text`() {
openTestPage("rangeInputChangesText")
waitTextToBe(value = "0")
@ResolveDrivers
fun `range updates the text`(driver: WebDriver) {
driver.openTestPage("rangeInputChangesText")
driver.waitTextToBe(value = "0")
val slider = driver.findElement(By.id("slider"))
@ -82,22 +83,22 @@ class InputsTests : BaseIntegrationTests() {
.sendKeys(Keys.RIGHT, Keys.RIGHT)
.perform()
waitTextToBe(value = "10")
driver.waitTextToBe(value = "10")
}
@Test
fun `time input updates the text`() {
openTestPage("timeInputChangesText")
@ResolveDrivers
fun `time input updates the text`(driver: WebDriver) {
driver.openTestPage("timeInputChangesText")
waitTextToBe(value = "")
driver.waitTextToBe(value = "")
val timeInput = driver.findElement(By.id("time"))
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`() {
// openTestPage("dateInputChangesText")
//
@ -109,7 +110,7 @@ class InputsTests : BaseIntegrationTests() {
// 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
// openTestPage("dateTimeLocalInputChangesText")
//
@ -121,16 +122,16 @@ class InputsTests : BaseIntegrationTests() {
// waitTextToBe(value = "2021-10-12T09:25")
// }
@Test
fun `file input updates the text`() {
openTestPage("fileInputChangesText")
waitTextToBe(value = "")
@ResolveDrivers
fun `file input updates the text`(driver: WebDriver) {
driver.openTestPage("fileInputChangesText")
driver.waitTextToBe(value = "")
val fileInput = driver.findElement(By.id("file"))
val homePath = System.getProperty("COMPOSE_WEB_INTEGRATION_TESTS_DISTRIBUTION")
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
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.waitTextToBe
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.openqa.selenium.By
import org.openqa.selenium.Dimension
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions
import org.openqa.selenium.remote.RemoteWebDriver
class IntegrationTests : BaseIntegrationTests() {
@Test
fun `text contains Hello World`() {
openTestPage("helloWorldText")
@ResolveDrivers
fun `text contains Hello World`(driver: RemoteWebDriver) {
driver.openTestPage("helloWorldText")
assertEquals(
"Hello World!",
driver.findElementByTagName("div").text
)
}
@Test
fun `multiple clicks on button update the counter after every click`() {
openTestPage("buttonClicksUpdateCounterValue")
@ResolveDrivers
fun `multiple clicks on button update the counter after every click`(driver: WebDriver) {
driver.openTestPage("buttonClicksUpdateCounterValue")
val button = driver.findElement(By.id("btn"))
waitTextToBe(textId = "txt", value = "0")
driver.waitTextToBe(textId = "txt", value = "0")
repeat(3) {
button.click()
waitTextToBe(textId = "txt", value = (it + 1).toString())
driver.waitTextToBe(textId = "txt", value = (it + 1).toString())
}
}
@Test
fun `hovering the box updates the text`() {
openTestPage("hoverOnDivUpdatesText")
@ResolveDrivers
fun `hovering the box updates the text`(driver: WebDriver) {
driver.openTestPage("hoverOnDivUpdatesText")
val box = driver.findElement(By.id("box"))
waitTextToBe(textId = "txt", value = "not hovered")
driver.waitTextToBe(textId = "txt", value = "not hovered")
val actions = Actions(driver)
actions.moveToElement(box).perform()
waitTextToBe(textId = "txt", value = "hovered")
driver.waitTextToBe(textId = "txt", value = "hovered")
actions.moveByOffset(300, 0).perform()
waitTextToBe(textId = "txt", value = "not hovered")
driver.waitTextToBe(textId = "txt", value = "not hovered")
}
@Test
fun `making screen width less than 400px changes the text color`() {
openTestPage("smallWidthChangesTheTextColor")
@ResolveDrivers
fun `making screen width less than 400px changes the text color`(driver: WebDriver) {
driver.openTestPage("smallWidthChangesTheTextColor")
val initialWindowSize = driver.manage().window().size
try {
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)
assertEquals("rgba(0, 0, 0, 1)", span.getCssValue("color"))
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"))
} finally {

64
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
import org.junit.jupiter.api.DisplayNameGeneration
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.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
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 {
override val driver: RemoteWebDriver = ChromeDriver(
private val PATH = "http://localhost:${ServerLauncher.port}"
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 {
setHeadless(true)
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