Skip to content

Commit 5518c39

Browse files
committed
expose Firefox Function and Regex
1 parent efe17a5 commit 5518c39

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ abstract class TL(
1919

2020
@Suppress("unchecked_cast")
2121
override fun findElements(context: SearchContext): List<WebElement> {
22-
context.jsExecutor.ensureScript("testing-library.js", "screen?.queryAllByTestId")
23-
return context.jsExecutor.executeScript(
24-
buildString {
25-
append("return screen.queryAllBy$by(")
26-
append(textMatch.escaped)
27-
options
28-
.filterValues { it != null }
29-
.takeIf(Map<String, Any?>::isNotEmpty)
30-
?.escaped
31-
?.let { append(", $it") }
32-
append(")")
33-
}
34-
) as List<WebElement>
22+
context.jsExecutor.ensureScript("testing-library.js", "window.screen?.queryAllByTestId")
23+
val script = buildString {
24+
append("return window.screen.queryAllBy$by(")
25+
append(textMatch.escaped)
26+
options
27+
.filterValues { it != null }
28+
.takeIf(Map<String, Any?>::isNotEmpty)
29+
?.escaped
30+
?.let { append(", $it") }
31+
append(")")
32+
}
33+
return context.jsExecutor.executeScript(script) as List<WebElement>
3534
}
3635

3736
private val SearchContext.jsExecutor get() = (getWebDriver(this) as JavascriptExecutor)

lib/src/main/resources/testing-library.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/test/kotlin/seleniumtestinglib/driver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ fun RemoteWebDriver.render(body: String): User {
1212
}
1313

1414
fun String.asDataUrl() =
15-
"""data:text/html;charset=utf-8,<html><body>${this}</body></html>"""
15+
"""data:text/html;charset=utf-8,<html><body>$this</body></html>"""

testing-library/src/testing-library.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ import {screen, fireEvent} from '@testing-library/dom'
22

33
window.screen = screen
44
window.fireEvent = fireEvent
5+
6+
window.__TL__Function = Function
7+
window.__TL__RegExp = RegExp

0 commit comments

Comments
 (0)