Skip to content

Commit 1ced9ad

Browse files
authored
Merge pull request #14 from elgreco247/jestdom-tests-on-firefox
Fix `jestdom` tests for Firefox
2 parents 9176076 + 007902c commit 1ced9ad

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Test in Firefox
3232
env:
3333
BROWSER: firefox
34-
run: ./gradlew test -rerun-tasks --tests "seleniumtestinglib.locators.*"
34+
run: ./gradlew test -rerun-tasks

lib/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ dependencies {
2222

2323
tasks.test {
2424
useJUnitPlatform()
25+
filter {
26+
if (System.getenv("BROWSER") == "firefox") {
27+
excludeTestsMatching("*.interactions.*")
28+
}
29+
}
2530
}
2631

2732
java {

lib/src/main/kotlin/seleniumtestinglib/JestDom.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ data class JestDomMatcher(
9595

9696
fun toHaveAccessibleName() {
9797
requireNotNull(element)
98-
validate(element.accessibleName.isNotBlank())
98+
validate(element.accessibleName.isNullOrBlank().not())
9999
}
100100

101101
fun toHaveAccessibleName(expectedAccessibleName: String) {

lib/src/main/kotlin/seleniumtestinglib/WebElement.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ val WebElement.isFocused: Boolean
6565
get() = equals(wrappedDriver.switchTo().activeElement())
6666

6767
val WebElement.isRequired
68-
get() = ((tagName == "input") and (getAttribute("type") == "file") or (ariaRole?.lowercase() in setOf(
68+
get() = ((tagName == "input") and (getAttribute("type") in setOf("file", "password", "date"))
69+
or (ariaRole?.lowercase() in setOf(
6970
"textbox",
7071
"checkbox",
7172
"radio",
7273
"email",
7374
"spinbutton",
7475
"combobox",
7576
"listbox",
76-
"date",
7777
))) and (getAttribute("required") in setOf(
7878
"",
7979
"true"
@@ -155,4 +155,4 @@ enum class Event {
155155
AnimationStart, AnimationEnd, AnimationIteration, TransitionCancel, TransitionEnd, TransitionRun, TransitionStart,
156156
PointerOver, PointerEnter, PointerDown, PointerMove, PointerUp, PointerCancel, PointerOut, PointerLeave,
157157
GotPointerCapture, LostPointerCapture, PopState, Offline, Online, DoubleClick
158-
}
158+
}

lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import seleniumtestinglib.expect
88
import seleniumtestinglib.render
99
import kotlin.test.Test
1010
import kotlin.test.assertEquals
11+
import kotlin.test.assertTrue
1112
import kotlin.text.RegexOption.IGNORE_CASE
1213

1314
class AccessibleNameTest {
@@ -19,7 +20,6 @@ class AccessibleNameTest {
1920
"""<svg data-testid="x"><title>accessible name</title></svg>""",
2021
"""<input data-testid="x" title="accessible name" />""",
2122
"""<button data-testid="x"><img src="" alt="accessible name" /></button>""",
22-
"""<button data-testid="x"><svg><title>accessible name</title></svg></p>""",
2323
]
2424
)
2525
fun `accessible name`(html: String) {
@@ -42,7 +42,7 @@ class AccessibleNameTest {
4242
fun `not accessible name`(html: String) {
4343
driver.render(html)
4444

45-
assertEquals("", driver.findElement(testId( "x")).accessibleName)
45+
assertTrue(driver.findElement(testId( "x")).accessibleName.isNullOrBlank())
4646
expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName()
4747
expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName("abc")
4848
}

lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package seleniumtestinglib.jestdom
22

3+
import org.openqa.selenium.Keys
34
import seleniumtestinglib.*
45
import seleniumtestinglib.TL.By.testId
56
import kotlin.test.Test
@@ -16,12 +17,12 @@ class FocusTest {
1617
<input type="text" />
1718
"""
1819
)
19-
driver.user.tab()
20+
driver.switchTo().activeElement().sendKeys(Keys.TAB)
2021
val element = driver.findElement(testId("element-to-focus"))
2122
assertTrue(element.isFocused)
2223
expect(element).toHaveFocus()
2324

24-
driver.user.tab()
25+
driver.switchTo().activeElement().sendKeys(Keys.TAB)
2526
assertFalse(element.isFocused)
2627
expect(element).not.toHaveFocus()
2728
}

lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ class StyleTest {
2121

2222
expect(button).toHaveStyle("display: none")
2323
expect(button).toHaveStyle(mapOf("display" to "none"))
24+
25+
val backgroundColor = when (System.getenv("BROWSER")) {
26+
"firefox" -> "rgb(255, 0, 0)"
27+
else -> "rgba(255, 0, 0, 1)"
28+
}
2429
expect(button).toHaveStyle(
2530
"""
26-
background-color: rgba(255, 0, 0, 1);
31+
background-color: ${backgroundColor};
2732
display: none;
2833
"""
2934
)
3035
expect(button).toHaveStyle(
3136
mapOf(
32-
"backgroundColor" to "rgba(255, 0, 0, 1)", // why?
37+
"backgroundColor" to backgroundColor, // why?
3338
"display" to "none",
3439
)
3540
)
@@ -39,9 +44,14 @@ class StyleTest {
3944
"display" to "none",
4045
)
4146
)
47+
48+
val wrongBackgroundColor = when (System.getenv("BROWSER")) {
49+
"firefox" -> "rgb(0, 0, 255)"
50+
else -> "rgba(0, 0, 255, 1)"
51+
}
4252
expect(button).not.toHaveStyle(
4353
mapOf(
44-
"backgroundColor" to "rgba(0, 0, 255, 1)",
54+
"backgroundColor" to wrongBackgroundColor,
4555
"display" to "none",
4656
)
4757
)

0 commit comments

Comments
 (0)