Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.udash.web.guide.demos.i18n

import java.{util => ju}

import io.udash.web.Implicits._
import io.udash.i18n.{Lang, ResourceBundlesTranslationTemplatesProvider, TranslationRPCEndpoint}
import io.udash.web.Implicits.*

import java.util as ju

class TranslationServer extends TranslationRPCEndpoint(
new ResourceBundlesTranslationTemplatesProvider(
TranslationServer.langs
.map(lang =>
Lang(lang) -> TranslationServer.bundlesNames.map(name => ju.ResourceBundle.getBundle(name, new ju.Locale(lang)))
Lang(lang) -> TranslationServer.bundlesNames.map(name => ju.ResourceBundle.getBundle(name, new ju.Locale.Builder().setLanguage(lang).build()))
).toMap
)
)
Expand Down
3 changes: 0 additions & 3 deletions guide/selenium/src/test/resources/logback-test.xml

This file was deleted.

11 changes: 7 additions & 4 deletions guide/selenium/src/test/scala/io/udash/web/SeleniumTest.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.udash.web

import com.typesafe.scalalogging.StrictLogging
import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.firefox.{FirefoxDriver, FirefoxOptions}
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.{By, Dimension, WebElement}
import org.scalatest.concurrent.Eventually
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Inspectors}

import java.time.Duration

Expand Down Expand Up @@ -41,13 +42,15 @@ private final class InternalServerConfig extends ServerConfig {

override def createUrl(part: String): String = {
require(part.startsWith("/"))
s"http://127.0.0.2:${server.port}$part"
s"http://localhost:${server.port}$part"
}
}

abstract class SeleniumTest extends AnyWordSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEach with Eventually {
abstract class SeleniumTest extends AnyWordSpec
with Matchers with BeforeAndAfterAll with BeforeAndAfterEach with Eventually with StrictLogging with Inspectors {
override implicit val patienceConfig: PatienceConfig = PatienceConfig(scaled(Span(10, Seconds)), scaled(Span(50, Millis)))

logger.info("Setting up WebDriver")
private val driverManager = WebDriverManager.firefoxdriver()
driverManager.config().setServerPort(0)
driverManager.setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package io.udash.web.guide.demos.frontend

import io.udash.web.SeleniumTest
import org.openqa.selenium.By.{ByClassName, ByCssSelector, ByTagName}
import org.openqa.selenium.{By, Keys}

import com.avsystem.commons._
import scala.util.Random

class FrontendFormsTest extends SeleniumTest {
Expand All @@ -19,12 +17,12 @@ class FrontendFormsTest extends SeleniumTest {
val checkbox = checkboxes.findElement(new ByClassName(s"checkbox-demo-$propertyName"))
checkbox.click()
eventually {
checkboxes.findElements(new ByCssSelector(s"[data-bind=$propertyName]")).asScala.forall(el => {
el.getText == expect
}) should be(true)
checkboxes.findElements(new ByClassName(s"checkbox-demo-$propertyName")).asScala.forall(el => {
el.getAttribute("selected") == checkbox.getAttribute("selected")
}) should be(true)
forAll(checkboxes.findElements(new ByCssSelector(s"[data-bind=$propertyName]")))(el =>
el.getText shouldBe expect
)
forAll(checkboxes.findElements(new ByClassName(s"checkbox-demo-$propertyName")))(el =>
el.isSelected shouldBe checkbox.isSelected
)
}
}

Expand All @@ -45,13 +43,13 @@ class FrontendFormsTest extends SeleniumTest {
val checkbox = checkButtons.findElement(new ByCssSelector(s"[data-label=$propertyName]")).findElement(new ByTagName("input"))
checkbox.click()
eventually {
checkButtons.findElements(new ByClassName("check-buttons-demo-fruits")).asScala.forall(el => {
forAll(checkButtons.findElements(new ByClassName("check-buttons-demo-fruits")))(el => {
val contains = el.getText.contains(propertyName)
if (checkbox.getAttribute("selected") != null) contains else !contains
}) should be(true)
checkButtons.findElements(new ByCssSelector(s"[data-label=$propertyName]")).asScala.forall(el => {
el.findElement(new ByTagName("input")).getAttribute("selected") == checkbox.getAttribute("selected")
}) should be(true)
assert(if (checkbox.isSelected) contains else !contains)
})
forAll(checkButtons.findElements(new ByCssSelector(s"[data-label=$propertyName]")))(el =>
el.findElement(new ByTagName("input")).isSelected shouldBe checkbox.isSelected
)
}
}

Expand All @@ -68,13 +66,13 @@ class FrontendFormsTest extends SeleniumTest {
val option = select.findElement(new ByCssSelector(s"[value='$propertyIdx']"))
option.click()
eventually {
multiSelect.findElements(new ByClassName("multi-select-demo-fruits")).asScala.forall(el => {
forAll(multiSelect.findElements(new ByClassName("multi-select-demo-fruits")))(el => {
val contains = el.getText.contains(propertyName)
if (option.getAttribute("selected") != null) contains else !contains
}) should be(true)
multiSelect.findElements(new ByTagName("select")).asScala.forall(el => {
el.findElement(new ByCssSelector(s"[value='$propertyIdx']")).getAttribute("selected") == option.getAttribute("selected")
}) should be(true)
assert(if (option.isSelected) contains else !contains)
})
forAll(multiSelect.findElements(new ByTagName("select")))(el => {
el.findElement(new ByCssSelector(s"[value='$propertyIdx']")).isSelected shouldBe option.isSelected
})
}
}

Expand All @@ -92,13 +90,13 @@ class FrontendFormsTest extends SeleniumTest {
val radio = radioButtons.findElement(new ByCssSelector(s"[data-label=$propertyName]")).findElement(new ByTagName("input"))
driver.executeScript("arguments[0].click();", radio)
eventually {
radioButtons.findElements(new ByClassName("radio-buttons-demo-fruits")).asScala.forall(el => {
el.getText == propertyName
}) should be(true)
radioButtons.findElements(new ByCssSelector(s"input")).asScala.forall(el => {
val eq = el.getAttribute("selected") == radio.getAttribute("selected")
if (el.getAttribute("value").toInt == propertyIdx) eq else !eq
}) should be(true)
forAll(radioButtons.findElements(new ByClassName("radio-buttons-demo-fruits")))(el =>
el.getText shouldBe propertyName
)
forAll(radioButtons.findElements(new ByCssSelector(s"input")))(el => {
val eq = el.isSelected == radio.isSelected
assert(if (el.getDomProperty("value").toInt == propertyIdx) eq else !eq)
})
}
}

Expand All @@ -117,12 +115,12 @@ class FrontendFormsTest extends SeleniumTest {
val option = select.findElement(new ByCssSelector(s"[value='$propertyIdx']"))
option.click()
eventually {
selectDemo.findElements(new ByClassName("select-demo-fruits")).asScala.forall(el => {
el.getText == propertyName
}) should be(true)
selectDemo.findElements(new ByTagName(s"select")).asScala.forall(el => {
el.findElement(new ByCssSelector(s"[value='$propertyIdx']")).getAttribute("selected") == option.getAttribute("selected")
}) should be(true)
forAll(selectDemo.findElements(new ByClassName("select-demo-fruits")))(el => {
el.getText shouldBe propertyName
})
forAll(selectDemo.findElements(new ByTagName(s"select")))(el => {
el.findElement(new ByCssSelector(s"[value='$propertyIdx']")).isSelected shouldBe option.isSelected
})
}
}

Expand All @@ -141,9 +139,9 @@ class FrontendFormsTest extends SeleniumTest {
textArea.clear()
textArea.sendKeys(text)
eventually {
textAreaDemo.findElements(new ByTagName(s"textarea")).asScala.forall(el => {
el.getAttribute("value") == text
}) should be(true)
forAll(textAreaDemo.findElements(new ByTagName(s"textarea")))(el => {
el.getDomProperty("value") shouldBe text
})
}
}

Expand All @@ -160,9 +158,9 @@ class FrontendFormsTest extends SeleniumTest {
input.clear()
input.sendKeys(text)
eventually {
inputsDemo.findElements(new ByCssSelector(s"input[type=$tpe]")).asScala.forall(el => {
el.getAttribute("value") == text
}) should be(true)
forAll(inputsDemo.findElements(new ByCssSelector(s"input[type=$tpe]")))(el => {
el.getDomProperty("value") shouldBe text
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ class FrontendIntroTest extends SeleniumTest {
val between = demo.findElement(new ById("between"))
val maximum = demo.findElement(new ById("maximum"))

var lastMinimum = minimum.getAttribute("value")
var lastBetween = between.getAttribute("value")
var lastMaximum = maximum.getAttribute("value")
var lastMinimum = minimum.getDomProperty("value")
var lastBetween = between.getDomProperty("value")
var lastMaximum = maximum.getDomProperty("value")

for (_ <- 1 to 5) {
randomizeButton.click()
eventually {
(lastMinimum != minimum.getAttribute("value") ||
lastBetween != between.getAttribute("value") ||
lastMaximum != maximum.getAttribute("value")) should be(true)
(lastMinimum != minimum.getDomProperty("value") ||
lastBetween != between.getDomProperty("value") ||
lastMaximum != maximum.getDomProperty("value")) should be(true)
}

lastMinimum = minimum.getAttribute("value")
lastBetween = between.getAttribute("value")
lastMaximum = maximum.getAttribute("value")
lastMinimum = minimum.getDomProperty("value")
lastBetween = between.getDomProperty("value")
lastMaximum = maximum.getDomProperty("value")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.udash.web.guide.demos.frontend

import io.udash.web.SeleniumTest
import org.openqa.selenium.By

class FrontendRoutingTest extends SeleniumTest {
override protected final val url = "/frontend/routing"
Expand Down Expand Up @@ -51,7 +50,7 @@ class FrontendRoutingTest extends SeleniumTest {
link.getText should be("/frontend/routing/pizza")
}

input.getAttribute("value") should be("It should not disappear... Selenium")
input.getDomProperty("value") should be("It should not disappear... Selenium")
}

"change URL basing on input without view redraw" in {
Expand Down Expand Up @@ -81,7 +80,7 @@ class FrontendRoutingTest extends SeleniumTest {
}

init.getText should be("/frontend/routing")
input.getAttribute("value") should be("It should not disappear... Selenium")
input.getDomProperty("value") should be("It should not disappear... Selenium")
}
}
}
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Dependencies {

val scalaLoggingVersion = "3.9.5"

val jettyVersion = "12.0.15"
val jettyVersion = "12.0.16"
val typesafeConfigVersion = "1.4.3"
val flexmarkVersion = "0.64.8"
val logbackVersion = "1.3.14"
Expand All @@ -42,7 +42,7 @@ object Dependencies {
val bootstrap4DatepickerVersion = "5.39.0"
val momentJsVersion = "2.30.1"

val seleniumVersion = "4.26.0"
val seleniumVersion = "4.27.0"
val webDriverManagerVersion = "5.9.2"
val scalaJsBenchmarkVersion = "0.10.0"

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# suppress inspection "UnusedProperty"
sbt.version=1.10.5
sbt.version=1.10.6
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ addSbtPlugin("com.github.sbt" % "sbt-less" % "2.0.1")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.4")

// Deployment configuration
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")