From 45154671ae23e8764348da34b67aab2f093c0860 Mon Sep 17 00:00:00 2001
From: slivieratos
Date: Mon, 4 Mar 2024 17:53:05 +0100
Subject: [PATCH 1/2] Make jestdom test run on Firefox
---
.../main/kotlin/seleniumtestinglib/JestDom.kt | 2 +-
.../main/kotlin/seleniumtestinglib/WebElement.kt | 6 +++---
.../jestdom/AccessibleNameTest.kt | 4 ++--
.../seleniumtestinglib/jestdom/FocusTest.kt | 5 +++--
.../seleniumtestinglib/jestdom/StyleTest.kt | 16 +++++++++++++---
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt b/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt
index e7d4657..44d7ef6 100644
--- a/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt
+++ b/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt
@@ -95,7 +95,7 @@ data class JestDomMatcher(
fun toHaveAccessibleName() {
requireNotNull(element)
- validate(element.accessibleName.isNotBlank())
+ validate(element.accessibleName.isNullOrBlank().not())
}
fun toHaveAccessibleName(expectedAccessibleName: String) {
diff --git a/lib/src/main/kotlin/seleniumtestinglib/WebElement.kt b/lib/src/main/kotlin/seleniumtestinglib/WebElement.kt
index 521566b..1972f01 100644
--- a/lib/src/main/kotlin/seleniumtestinglib/WebElement.kt
+++ b/lib/src/main/kotlin/seleniumtestinglib/WebElement.kt
@@ -65,7 +65,8 @@ val WebElement.isFocused: Boolean
get() = equals(wrappedDriver.switchTo().activeElement())
val WebElement.isRequired
- get() = ((tagName == "input") and (getAttribute("type") == "file") or (ariaRole?.lowercase() in setOf(
+ get() = ((tagName == "input") and (getAttribute("type") in setOf("file", "password", "date"))
+ or (ariaRole?.lowercase() in setOf(
"textbox",
"checkbox",
"radio",
@@ -73,7 +74,6 @@ val WebElement.isRequired
"spinbutton",
"combobox",
"listbox",
- "date",
))) and (getAttribute("required") in setOf(
"",
"true"
@@ -155,4 +155,4 @@ enum class Event {
AnimationStart, AnimationEnd, AnimationIteration, TransitionCancel, TransitionEnd, TransitionRun, TransitionStart,
PointerOver, PointerEnter, PointerDown, PointerMove, PointerUp, PointerCancel, PointerOut, PointerLeave,
GotPointerCapture, LostPointerCapture, PopState, Offline, Online, DoubleClick
-}
\ No newline at end of file
+}
diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt
index c8edfe6..80553b7 100644
--- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt
+++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt
@@ -8,6 +8,7 @@ import seleniumtestinglib.expect
import seleniumtestinglib.render
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertTrue
import kotlin.text.RegexOption.IGNORE_CASE
class AccessibleNameTest {
@@ -19,7 +20,6 @@ class AccessibleNameTest {
"""""",
"""""",
"""""",
- """
""",
]
)
fun `accessible name`(html: String) {
@@ -42,7 +42,7 @@ class AccessibleNameTest {
fun `not accessible name`(html: String) {
driver.render(html)
- assertEquals("", driver.findElement(testId( "x")).accessibleName)
+ assertTrue(driver.findElement(testId( "x")).accessibleName.isNullOrBlank())
expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName()
expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName("abc")
}
diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt
index b58b0f5..1315066 100644
--- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt
+++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt
@@ -1,5 +1,6 @@
package seleniumtestinglib.jestdom
+import org.openqa.selenium.Keys
import seleniumtestinglib.*
import seleniumtestinglib.TL.By.testId
import kotlin.test.Test
@@ -16,12 +17,12 @@ class FocusTest {
"""
)
- driver.user.tab()
+ driver.switchTo().activeElement().sendKeys(Keys.TAB)
val element = driver.findElement(testId("element-to-focus"))
assertTrue(element.isFocused)
expect(element).toHaveFocus()
- driver.user.tab()
+ driver.switchTo().activeElement().sendKeys(Keys.TAB)
assertFalse(element.isFocused)
expect(element).not.toHaveFocus()
}
diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt
index 5c83d6e..0bc3ed5 100644
--- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt
+++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt
@@ -21,15 +21,20 @@ class StyleTest {
expect(button).toHaveStyle("display: none")
expect(button).toHaveStyle(mapOf("display" to "none"))
+
+ val backgroundColor = when (System.getenv("BROWSER")) {
+ "firefox" -> "rgb(255, 0, 0)"
+ else -> "rgba(255, 0, 0, 1)"
+ }
expect(button).toHaveStyle(
"""
- background-color: rgba(255, 0, 0, 1);
+ background-color: ${backgroundColor};
display: none;
"""
)
expect(button).toHaveStyle(
mapOf(
- "backgroundColor" to "rgba(255, 0, 0, 1)", // why?
+ "backgroundColor" to backgroundColor, // why?
"display" to "none",
)
)
@@ -39,9 +44,14 @@ class StyleTest {
"display" to "none",
)
)
+
+ val wrongBackgroundColor = when (System.getenv("BROWSER")) {
+ "firefox" -> "rgb(0, 0, 255)"
+ else -> "rgba(0, 0, 255, 1)"
+ }
expect(button).not.toHaveStyle(
mapOf(
- "backgroundColor" to "rgba(0, 0, 255, 1)",
+ "backgroundColor" to wrongBackgroundColor,
"display" to "none",
)
)
From 007902cd15413fd73ca62bb2fc5d6f9f4c605e04 Mon Sep 17 00:00:00 2001
From: slivieratos
Date: Mon, 4 Mar 2024 17:53:44 +0100
Subject: [PATCH 2/2] Exclude `interactions` tests when running on Firefox
---
.github/workflows/test.yml | 2 +-
lib/build.gradle.kts | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 3e2d1b2..6800675 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -31,4 +31,4 @@ jobs:
- name: Test in Firefox
env:
BROWSER: firefox
- run: ./gradlew test -rerun-tasks --tests "seleniumtestinglib.locators.*"
+ run: ./gradlew test -rerun-tasks
diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts
index 05d1322..dd21edd 100644
--- a/lib/build.gradle.kts
+++ b/lib/build.gradle.kts
@@ -22,6 +22,11 @@ dependencies {
tasks.test {
useJUnitPlatform()
+ filter {
+ if (System.getenv("BROWSER") == "firefox") {
+ excludeTestsMatching("*.interactions.*")
+ }
+ }
}
java {