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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dependencies {

tasks.test {
useJUnitPlatform()
filter {
if (System.getenv("BROWSER") == "firefox") {
excludeTestsMatching("*.interactions.*")
}
}
}

java {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/kotlin/seleniumtestinglib/JestDom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ data class JestDomMatcher(

fun toHaveAccessibleName() {
requireNotNull(element)
validate(element.accessibleName.isNotBlank())
validate(element.accessibleName.isNullOrBlank().not())
}

fun toHaveAccessibleName(expectedAccessibleName: String) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/kotlin/seleniumtestinglib/WebElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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",
"email",
"spinbutton",
"combobox",
"listbox",
"date",
))) and (getAttribute("required") in setOf(
"",
"true"
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,7 +20,6 @@ class AccessibleNameTest {
"""<svg data-testid="x"><title>accessible name</title></svg>""",
"""<input data-testid="x" title="accessible name" />""",
"""<button data-testid="x"><img src="" alt="accessible name" /></button>""",
"""<button data-testid="x"><svg><title>accessible name</title></svg></p>""",
]
)
fun `accessible name`(html: String) {
Expand All @@ -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")
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seleniumtestinglib.jestdom

import org.openqa.selenium.Keys
import seleniumtestinglib.*
import seleniumtestinglib.TL.By.testId
import kotlin.test.Test
Expand All @@ -16,12 +17,12 @@ class FocusTest {
<input type="text" />
"""
)
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()
}
Expand Down
16 changes: 13 additions & 3 deletions lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)
Expand All @@ -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",
)
)
Expand Down