From 3917181c2520c017f6dacac44fab3d70f627ad98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Soares?= Date: Tue, 27 Feb 2024 18:05:10 +0000 Subject: [PATCH] experiment with renewed API --- README.md | 6 - .../{locators/TL.kt => Core.kt} | 259 +++++++++++++----- .../{jestdom/Api.kt => JestDom.kt} | 2 +- .../kotlin/seleniumtestinglib/UserEvent.kt | 221 +++++++++++++++ .../seleniumtestinglib/interactions/Api.kt | 45 --- .../interactions/Clipboard.kt | 20 -- .../interactions/Keyboard.kt | 17 -- .../interactions/Pointer.kt | 62 ----- .../interactions/Utility.kt | 83 ------ .../seleniumtestinglib/locators/ByRole.kt | 118 -------- .../kotlin/seleniumtestinglib/queries/Api.kt | 85 ------ .../kotlin/seleniumtestinglib/queries/Find.kt | 30 -- .../kotlin/seleniumtestinglib/queries/Get.kt | 41 --- .../seleniumtestinglib/queries/Query.kt | 41 --- .../seleniumtestinglib/FireEventTest.kt | 4 +- .../seleniumtestinglib/TargetLocatorTest.kt | 4 +- .../test/kotlin/seleniumtestinglib/driver.kt | 2 - .../interactions/ClearTest.kt | 8 +- .../interactions/ClickTest.kt | 12 +- .../interactions/ClipboardTest.kt | 20 +- .../interactions/DeselectOptionsTest.kt | 8 +- .../interactions/DoubleClickTest.kt | 14 +- .../interactions/GeneralTest.kt | 13 +- .../interactions/HoverTest.kt | 10 +- .../interactions/KeyboardTest.kt | 8 +- .../interactions/PointerTest.kt | 22 +- .../interactions/SelectOptionsTest.kt | 8 +- .../interactions/TabTest.kt | 8 +- .../interactions/TripleClickTest.kt | 14 +- .../interactions/TypeTest.kt | 8 +- .../interactions/UnhoverTest.kt | 10 +- .../interactions/UploadTest.kt | 6 +- .../jestdom/AccessibleDescriptionTest.kt | 20 +- .../jestdom/AccessibleNameTest.kt | 26 +- .../jestdom/AttributeTest.kt | 6 +- .../seleniumtestinglib/jestdom/CheckedTest.kt | 8 +- .../seleniumtestinglib/jestdom/ClassTest.kt | 8 +- .../jestdom/ContainElementTest.kt | 10 +- .../jestdom/ContainHtmlTest.kt | 6 +- .../jestdom/DisabledTest.kt | 13 +- .../jestdom/DisplayValueTest.kt | 11 +- .../jestdom/EmptyDomElementTest.kt | 1 + .../seleniumtestinglib/jestdom/EnabledTest.kt | 9 +- .../jestdom/ErrorMessageTest.kt | 3 +- .../seleniumtestinglib/jestdom/FocusTest.kt | 8 +- .../jestdom/FormValuesTest.kt | 3 +- .../jestdom/InTheDocumentTest.kt | 8 +- .../seleniumtestinglib/jestdom/InvalidTest.kt | 8 +- .../jestdom/PartiallyCheckedTest.kt | 13 +- .../jestdom/RequiredTest.kt | 1 + .../seleniumtestinglib/jestdom/StyleTest.kt | 6 +- .../jestdom/TextContentTest.kt | 6 +- .../seleniumtestinglib/jestdom/ValidTest.kt | 1 + .../seleniumtestinglib/jestdom/ValueTest.kt | 12 +- .../seleniumtestinglib/jestdom/VisibleTest.kt | 8 +- .../locators/ByAltTextTest.kt | 4 +- .../locators/ByDisplayValueTest.kt | 6 +- .../locators/ByLabelTextTest.kt | 4 +- .../locators/ByPlaceholderTextTest.kt | 4 +- .../locators/ByRoleTestType.kt | 10 +- .../locators/ByTestIdTest.kt | 4 +- .../seleniumtestinglib/locators/ByTextTest.kt | 3 +- .../locators/ByTitleTest.kt | 4 +- .../{queries => locators}/NotFoundTest.kt | 55 +--- .../queries/ByAltTextTest.kt | 56 ---- release | 4 +- 66 files changed, 625 insertions(+), 933 deletions(-) rename lib/src/main/kotlin/seleniumtestinglib/{locators/TL.kt => Core.kt} (56%) rename lib/src/main/kotlin/seleniumtestinglib/{jestdom/Api.kt => JestDom.kt} (99%) create mode 100644 lib/src/main/kotlin/seleniumtestinglib/UserEvent.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/interactions/Api.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/interactions/Clipboard.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/interactions/Keyboard.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/interactions/Pointer.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/interactions/Utility.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/locators/ByRole.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/queries/Api.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/queries/Find.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/queries/Get.kt delete mode 100644 lib/src/main/kotlin/seleniumtestinglib/queries/Query.kt rename lib/src/test/kotlin/seleniumtestinglib/{queries => locators}/NotFoundTest.kt (51%) delete mode 100644 lib/src/test/kotlin/seleniumtestinglib/queries/ByAltTextTest.kt diff --git a/README.md b/README.md index be2b81d..24aa379 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,6 @@ driver.findElements(testId("test-id")) driver.findElements(text("present", exact = false, selector = "span")) driver.findElement(title("title 1")) driver.findElement(title(Pattern.compile("FOO"))) - -// an alternative API that does not use Selenium locators: -driver.queryBy(AltText, "alt 1", mapOf("exact" to false)) -driver.getBy(DisplayValue, "incredibles") -driver.queryAllBy(LabelText, "label x") -driver.getAllBy(Role, "listbox") ``` ## User Interactions diff --git a/lib/src/main/kotlin/seleniumtestinglib/locators/TL.kt b/lib/src/main/kotlin/seleniumtestinglib/Core.kt similarity index 56% rename from lib/src/main/kotlin/seleniumtestinglib/locators/TL.kt rename to lib/src/main/kotlin/seleniumtestinglib/Core.kt index df16fc7..30782f7 100644 --- a/lib/src/main/kotlin/seleniumtestinglib/locators/TL.kt +++ b/lib/src/main/kotlin/seleniumtestinglib/Core.kt @@ -1,23 +1,18 @@ -package seleniumtestinglib.locators +package seleniumtestinglib import org.openqa.selenium.JavascriptExecutor import org.openqa.selenium.SearchContext import org.openqa.selenium.WebElement -import seleniumtestinglib.locators.Current.CurrentAsBool -import seleniumtestinglib.locators.Current.CurrentAsType -import seleniumtestinglib.queries.LocatorType -import seleniumtestinglib.queries.LocatorType.* -import seleniumtestinglib.queries.TextMatch -import seleniumtestinglib.queries.TextMatch.Companion.asJsString -import seleniumtestinglib.queries.TextMatch.JsFunction -import seleniumtestinglib.queries.asJsExpression -import seleniumtestinglib.queries.executeTLQuery +import seleniumtestinglib.Current.CurrentAsBool +import seleniumtestinglib.Current.CurrentAsType +import seleniumtestinglib.TextMatch.Companion.asJsExpression +import seleniumtestinglib.TextMatch.Companion.asJsString import java.util.regex.Pattern import org.openqa.selenium.By as SeleniumBy abstract class TL( - private val by: LocatorType, + private val by: String, private val textMatch: TextMatch, private val options: Map = emptyMap() ) : SeleniumBy() { @@ -41,23 +36,23 @@ abstract class TL( */ fun altText(text: String, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = AltText, + by = "AltText", textMatch = text.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun altText(text: Pattern, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = AltText, + by = "AltText", textMatch = text.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun altText(text: JsFunction, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = AltText, - textMatch = text, - options = mapOf("exact" to exact, "normalizer" to normalizer), + by = "AltText", + textMatch = text.asJsExpression(), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} /** @@ -65,23 +60,23 @@ abstract class TL( */ fun displayValue(value: String, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = DisplayValue, + by = "DisplayValue", textMatch = value.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun displayValue(value: Pattern, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = DisplayValue, + by = "DisplayValue", textMatch = value.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun displayValue(value: JsFunction, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = DisplayValue, - textMatch = value, - options = mapOf("exact" to exact, "normalizer" to normalizer), + by = "DisplayValue", + textMatch = value.asJsExpression(), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} /** @@ -94,9 +89,13 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = LabelText, + by = "LabelText", textMatch = text.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer, "selector" to selector), + options = mapOf( + "exact" to exact, + "normalizer" to normalizer?.asJsExpression(), + "selector" to selector + ), ) {} fun labelText( @@ -106,9 +105,13 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = LabelText, + by = "LabelText", textMatch = text.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer, "selector" to selector), + options = mapOf( + "exact" to exact, + "normalizer" to normalizer?.asJsExpression(), + "selector" to selector + ), ) {} fun labelText( @@ -118,9 +121,13 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = LabelText, - textMatch = text, - options = mapOf("exact" to exact, "normalizer" to normalizer, "selector" to selector), + by = "LabelText", + textMatch = text.asJsExpression(), + options = mapOf( + "exact" to exact, + "normalizer" to normalizer?.asJsExpression(), + "selector" to selector + ), ) {} /** @@ -128,23 +135,23 @@ abstract class TL( */ fun placeholderText(text: String, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = PlaceholderText, + by = "PlaceholderText", textMatch = text.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun placeholderText(text: Pattern, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = PlaceholderText, + by = "PlaceholderText", textMatch = text.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun placeholderText(text: JsFunction, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = PlaceholderText, - textMatch = text, - options = mapOf("exact" to exact, "normalizer" to normalizer), + by = "PlaceholderText", + textMatch = text.asJsExpression(), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} /** @@ -152,23 +159,23 @@ abstract class TL( */ fun testId(text: String, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = TestId, + by = "TestId", textMatch = text.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun testId(text: Pattern, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = TestId, + by = "TestId", textMatch = text.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun testId(text: JsFunction, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = TestId, - textMatch = text, - options = mapOf("exact" to exact, "normalizer" to normalizer), + by = "TestId", + textMatch = text.asJsExpression(), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} @@ -183,11 +190,11 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = Text, + by = "Text", textMatch = text.asJsString(), options = mapOf( "exact" to exact, - "normalizer" to normalizer, + "normalizer" to normalizer?.asJsExpression(), "selector" to selector, "ignore" to ignore ), @@ -201,11 +208,11 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = Text, + by = "Text", textMatch = text.asJsExpression(), options = mapOf( "exact" to exact, - "normalizer" to normalizer, + "normalizer" to normalizer?.asJsExpression(), "selector" to selector, "ignore" to ignore ), @@ -219,11 +226,11 @@ abstract class TL( normalizer: JsFunction? = null ) = object : TL( - by = Text, - textMatch = text, + by = "Text", + textMatch = text.asJsExpression(), options = mapOf( "exact" to exact, - "normalizer" to normalizer, + "normalizer" to normalizer?.asJsExpression(), "selector" to selector, "ignore" to ignore ), @@ -234,23 +241,23 @@ abstract class TL( */ fun title(title: String, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = Title, + by = "Title", textMatch = title.asJsString(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun title(title: Pattern, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = Title, + by = "Title", textMatch = title.asJsExpression(), - options = mapOf("exact" to exact, "normalizer" to normalizer), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} fun title(title: JsFunction, exact: Boolean? = null, normalizer: JsFunction? = null) = object : TL( - by = Title, - textMatch = title, - options = mapOf("exact" to exact, "normalizer" to normalizer), + by = "Title", + textMatch = title.asJsExpression(), + options = mapOf("exact" to exact, "normalizer" to normalizer?.asJsExpression()), ) {} /** @@ -278,14 +285,15 @@ abstract class TL( value: Value? = null, queryFallbacks: Boolean? = null, ) = object : TL( - by = Role, + by = "Role", textMatch = role.name.lowercase().asJsString(), options = mapOf( - "name" to (name?.asJsString() ?: nameAsRegex?.asJsExpression() ?: nameAsFunction), + "name" to (name?.asJsString() ?: nameAsRegex?.asJsExpression() + ?: nameAsFunction?.asJsExpression()), "description" to (description?.asJsString() ?: descriptionAsRegex?.asJsExpression() - ?: descriptionAsFunction), + ?: descriptionAsFunction?.asJsExpression()), "hidden" to hidden, - "normalizer" to normalizer, + "normalizer" to normalizer?.asJsExpression(), "selected" to selected, "busy" to busy, "checked" to checked, @@ -301,5 +309,124 @@ abstract class TL( } } -private fun Value.toMap() = - mapOf("min" to min, "max" to max, "now" to now, "text" to text).filterValues { it != null } \ No newline at end of file +class JsFunction(val value: String) + +fun String.asJsFunction() = JsFunction(this) + +private fun JsFunction.asJsExpression() = value.asJsExpression() + + +/** + * https://testing-library.com/docs/dom-testing-library/intro + */ +private inline fun JavascriptExecutor.executeTLQuery( + by: String, + textMatch: TextMatch? = null, + options: Map = emptyMap(), +) = buildString { + append("return screen.queryAllBy") + append("$by(${textMatch.escaped}") + if (textMatch != null && options.filterValues { it != null }.isNotEmpty()) append(",") + options + .filterValues { it != null } + .takeIf(Map::isNotEmpty) + ?.escaped + ?.let { append(it) } + append(")") +}.let(::executeTLScript) as T + + +// TODO: do not expose class +sealed class TextMatch(open val value: String) { + class JsString(override val value: String) : TextMatch(value) + class JsExpression(override val value: String) : TextMatch(value) + + override fun toString() = value + + companion object { + fun String.asJsExpression() = JsExpression(this) + fun String.asJsString() = JsString(this) + } +} + +private fun Pattern.asJsExpression(): TextMatch.JsExpression { + val jsFlags = buildString { + if (flags() and Pattern.CASE_INSENSITIVE != 0) append('i') + if (flags() and RegexOption.MULTILINE.value != 0) append('m') + if (flags() and Pattern.DOTALL != 0) append('s') + if (flags() and RegexOption.COMMENTS.value != 0) append('x') + if (flags() and Pattern.UNICODE_CASE != 0) append('u') + } + return TextMatch.JsExpression("/${pattern()}/$jsFlags") +} + +private fun JavascriptExecutor.executeTLScript(script: String): Any? { + ensureScript("testing-library.js", "screen?.queryAllByTestId") + return executeScript(script) +} + +private val String.quoted get() = "'${replace("'", "\\'")}'" +private val Any?.escaped: Any? + get() = when (this) { + is TextMatch.JsString -> value.quoted + is TextMatch.JsExpression -> value + is String -> quoted + is Map<*, *> -> entries.joinToString(prefix = "{ ", postfix = " }") { + "${it.key}: ${it.value?.escaped}" + } + + else -> this + } + +// TODO: allow to receive all +class Value( + val min: Int? = null, + val max: Int? = null, + val now: Int? = null, +) { + + internal fun toMap() = + mapOf("min" to min, "max" to max, "now" to now, "text" to text).filterValues { it != null } + + private var text: TextMatch? = null + + constructor(text: String) : this() { + this.text = text.asJsString() + } + + constructor(text: Pattern) : this() { + this.text = text.asJsExpression() + } + + constructor(text: JsFunction) : this() { + this.text = text.asJsExpression() + } +} + +/* + * https://www.w3.org/TR/wai-aria-1.2/#aria-current + */ +internal sealed class Current(open val value: Any) { + override fun toString() = value.toString() + internal class CurrentAsType(value: CurrentType) : Current(value.name.lowercase().asJsString()) + internal class CurrentAsBool(value: Boolean) : Current(value) +} + +@Suppress("UNUSED") +enum class CurrentType { + Page, Step, Location, Date, Time +} + +/* + * https://www.w3.org/TR/wai-aria-1.2/#role_definitions + */ +@Suppress("UNUSED") +enum class RoleType { + Alert, AlertDialog, Application, Article, Banner, Button, Cell, CheckBox, ColumnHeader, ComboBox, Command, Comment, + Complementary, Composite, ContentInfo, Definition, Dialog, Directory, Document, Feed, Figure, Form, Generic, Grid, + GridCell, Group, Heading, Img, Input, Landmark, Link, List, ListBox, ListItem, Log, Main, Mark, Marquee, Math, Menu, + MenuBar, MenuItem, MenuItemCheckBox, MenuItemRadio, Meter, Navigation, None, Note, Option, Presentation, + ProgressBar, Radio, RadioGroup, Range, Region, RoleType, Row, RowGroup, RowHeader, ScrollBar, Search, SearchBox, + Section, SectionHead, Select, Separator, Slider, SpinButton, Status, Structure, Suggestion, Switch, Tab, Table, + TabList, TabPanel, Term, TextBox, Timer, Toolbar, Tooltip, Tree, TreeGrid, TreeItem, Widget, Window +} \ No newline at end of file diff --git a/lib/src/main/kotlin/seleniumtestinglib/jestdom/Api.kt b/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt similarity index 99% rename from lib/src/main/kotlin/seleniumtestinglib/jestdom/Api.kt rename to lib/src/main/kotlin/seleniumtestinglib/JestDom.kt index bd8e1f4..e7d4657 100644 --- a/lib/src/main/kotlin/seleniumtestinglib/jestdom/Api.kt +++ b/lib/src/main/kotlin/seleniumtestinglib/JestDom.kt @@ -1,4 +1,4 @@ -package seleniumtestinglib.jestdom +package seleniumtestinglib import org.openqa.selenium.By import org.openqa.selenium.WebElement diff --git a/lib/src/main/kotlin/seleniumtestinglib/UserEvent.kt b/lib/src/main/kotlin/seleniumtestinglib/UserEvent.kt new file mode 100644 index 0000000..43624a9 --- /dev/null +++ b/lib/src/main/kotlin/seleniumtestinglib/UserEvent.kt @@ -0,0 +1,221 @@ +package seleniumtestinglib + +import org.openqa.selenium.WebElement +import org.openqa.selenium.remote.RemoteWebDriver + +class User(val driver: RemoteWebDriver) + +// TODO: test receiving options +/** + * Obtains a custom instance of user by calling `userEvent.setup()` with the supplied arguments. + * + * https://testing-library.com/docs/user-event/options + */ +fun RemoteWebDriver.user(vararg options: Pair): User { + ensureScript("user-event.js", "window.userEvent?.setup") + executeScript( + "user = userEvent.setup(arguments[0])", + options.toMap().mapKeys { it.key.name.replaceFirstChar(Char::lowercase) } + ) + return User(this) +} + +/** + * If there's one Testing Library `user` already, it returns it. + * Else, it creates a default one (obtained with `userEvent.setup()`). + * + * https://testing-library.com/docs/user-event/intro + */ +val RemoteWebDriver.user: User + get() = if (executeScript("return typeof user != 'undefined'") as Boolean) + User(this) + else user() + +enum class UserOption { + AdvanceTimers, + ApplyAccept, + AutoModify, + Delay, + Document, + KeyboardMap, + PointerEventsCheck, + PointerMap, + SkipAutoClose, + SkipClick, + SkipHover, + WriteToClipboard, +} + +/** + * https://testing-library.com/docs/user-event/clipboard + */ +fun User.copy(): User { + driver.executeScript("await user.copy()") + return this +} + +fun User.cut(): User { + driver.executeScript("await user.cut()") + return this +} + +// TODO receive DataTransfer +fun User.paste(clipboardData: String? = null): User { + driver.executeScript("await user.paste(arguments[0])", clipboardData) + return this +} + +/** + * https://testing-library.com/docs/user-event/keyboard + */ +fun User.keyboard(input: String): User { + driver.executeScript("await user.keyboard(arguments[0])", input) + return this +} + +/** + * https://testing-library.com/docs/user-event/convenience#tab + */ +fun User.tab(shift: Boolean = false): User { + driver.executeScript("await user.tab(arguments[0])", mapOf("shift" to shift)) + return this +} + +/** + * https://testing-library.com/docs/user-event/pointer + */ +fun User.pointer(vararg inputs: String): User { + driver.executeScript("await user.pointer(arguments[0])", inputs) + return this +} + +fun User.pointer(vararg inputs: Map): User { + driver.executeScript( + "await user.pointer(arguments[0])", + inputs.toList().map { it.mapKeys { it.key.name.replaceFirstChar(Char::lowercase) } }) + return this +} + +enum class PointerOption { + Target, Keys, Offset, PointerName, Node +} + +/** + * https://testing-library.com/docs/user-event/convenience#click + */ +fun User.click(element: WebElement): User { + driver.executeScript("await user.click(arguments[0])", element) + return this +} + +/** + * https://testing-library.com/docs/user-event/convenience#dblclick + */ +fun User.dblClick(element: WebElement): User { + driver.executeScript("await user.dblClick(arguments[0])", element) + return this +} + +/** + * https://testing-library.com/docs/user-event/convenience#tripleclick + */ +fun User.tripleClick(element: WebElement): User { + driver.executeScript("await user.tripleClick(arguments[0])", element) + return this +} + +/** + * https://testing-library.com/docs/user-event/convenience#hover + */ +fun User.hover(element: WebElement): User { + driver.executeScript("await user.hover(arguments[0])", element) + return this +} + +/** + * https://testing-library.com/docs/user-event/convenience#unhover + */ +fun User.unhover(element: WebElement): User { + driver.executeScript("await user.unhover(arguments[0])", element) + return this +} + +/** + * https://testing-library.com/docs/user-event/utility#clear + */ +fun User.clear(element: WebElement): User { + driver.executeScript("await user.clear(arguments[0])", element) + return this +} + +fun User.selectOptions(element: WebElement, vararg values: String): User { + driver.executeScript( + "await user.selectOptions(arguments[0], arguments[1])", element, values + ) + return this +} + +fun User.selectOptions(element: WebElement, vararg values: WebElement): User { + driver.executeScript( + "await user.selectOptions(arguments[0], arguments[1])", element, values + ) + return this +} + +/** + * https://testing-library.com/docs/user-event/utility#-selectoptions-deselectoptions + */ +fun User.deselectOptions(element: WebElement, vararg values: String): User { + driver.executeScript( + "await user.deselectOptions(arguments[0], arguments[1])", element, values + ) + return this +} + +fun User.deselectOptions(element: WebElement, vararg values: WebElement): User { + driver.executeScript( + "await user.deselectOptions(arguments[0], arguments[1])", element, values + ) + return this +} + +/** + * https://testing-library.com/docs/user-event/utility#type + */ +fun User.type( + element: WebElement, + text: String, + skipClick: Boolean? = null, + skipAutoClose: Boolean? = null, + initialSelectionStart: Int? = null, + initialSelectionEnd: Int? = null, +): User { + driver.executeScript( + "await user.type(arguments[0], arguments[1], arguments[2])", + element, + text, + mapOf( + "skipClick" to skipClick, + "skipAutoClose" to skipAutoClose, + "initialSelectionStart" to initialSelectionStart, + "initialSelectionEnd" to initialSelectionEnd, + ).filterValues { it != null } + ) + return this +} + +/** + * https://testing-library.com/docs/user-event/utility#upload + */ +fun User.upload(input: WebElement, file: File): User { + driver.executeScript( + "await user.upload(arguments[0], new File(arguments[1], arguments[2], arguments[3]))", + input, + file.bits, + file.name, + file.options + ) + return this +} + +data class File(val bits: List, val name: String, val options: Map = emptyMap()) \ No newline at end of file diff --git a/lib/src/main/kotlin/seleniumtestinglib/interactions/Api.kt b/lib/src/main/kotlin/seleniumtestinglib/interactions/Api.kt deleted file mode 100644 index 2498e5e..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/interactions/Api.kt +++ /dev/null @@ -1,45 +0,0 @@ -package seleniumtestinglib.interactions - -import org.openqa.selenium.remote.RemoteWebDriver -import seleniumtestinglib.ensureScript - -class User(val driver: RemoteWebDriver) - -// TODO: test receiving options -/** - * Obtains a custom instance of user by calling `userEvent.setup()` with the supplied arguments. - * - * https://testing-library.com/docs/user-event/options - */ -fun RemoteWebDriver.user(vararg options: Pair): User { - require(options.all { it.first in validUserOptions }) - ensureScript("user-event.js", "window.userEvent?.setup") - executeScript("user = userEvent.setup(arguments[0])", options.toMap()) - return User(this) -} - -/** - * If there's one Testing Library `user` already, it returns it. - * Else, it creates a default one (obtained with `userEvent.setup()`). - * - * https://testing-library.com/docs/user-event/intro - */ -val RemoteWebDriver.user: User - get() = if (executeScript("return typeof user != 'undefined'") as Boolean) - User(this) - else user() - -private val validUserOptions = setOf( - "advanceTimers", - "applyAccept", - "autoModify", - "delay", - "document", - "keyboardMap", - "pointerEventsCheck", - "pointerMap", - "skipAutoClose", - "skipClick", - "skipHover", - "writeToClipboard", -) diff --git a/lib/src/main/kotlin/seleniumtestinglib/interactions/Clipboard.kt b/lib/src/main/kotlin/seleniumtestinglib/interactions/Clipboard.kt deleted file mode 100644 index 9076933..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/interactions/Clipboard.kt +++ /dev/null @@ -1,20 +0,0 @@ -package seleniumtestinglib.interactions - -/** - * https://testing-library.com/docs/user-event/clipboard - */ -fun User.copy(): User { - driver.executeScript("await user.copy()") - return this -} - -fun User.cut(): User { - driver.executeScript("await user.cut()") - return this -} - -// TODO receive DataTransfer -fun User.paste(clipboardData: String? = null): User { - driver.executeScript("await user.paste(arguments[0])", clipboardData) - return this -} diff --git a/lib/src/main/kotlin/seleniumtestinglib/interactions/Keyboard.kt b/lib/src/main/kotlin/seleniumtestinglib/interactions/Keyboard.kt deleted file mode 100644 index 031ce8f..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/interactions/Keyboard.kt +++ /dev/null @@ -1,17 +0,0 @@ -package seleniumtestinglib.interactions - -/** - * https://testing-library.com/docs/user-event/keyboard - */ -fun User.keyboard(input: String): User { - driver.executeScript("await user.keyboard(arguments[0])", input) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#tab - */ -fun User.tab(shift: Boolean = false): User { - driver.executeScript("await user.tab(arguments[0])", mapOf("shift" to shift)) - return this -} diff --git a/lib/src/main/kotlin/seleniumtestinglib/interactions/Pointer.kt b/lib/src/main/kotlin/seleniumtestinglib/interactions/Pointer.kt deleted file mode 100644 index ebe8e44..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/interactions/Pointer.kt +++ /dev/null @@ -1,62 +0,0 @@ -package seleniumtestinglib.interactions - -import org.openqa.selenium.WebElement - -/** - * https://testing-library.com/docs/user-event/pointer - */ -fun User.pointer(vararg inputs: String): User { - driver.executeScript("await user.pointer(arguments[0])", inputs) - return this -} - -private val pointerValidOptions = setOf("target", "keys", "offset", "pointerName", "node") -fun User.pointer(vararg inputs: Map): User { - inputs.forEach { input -> - input.forEach { - require(it.key in pointerValidOptions) { "${it.key} is not valid (valid keys are $pointerValidOptions)" } - } - } - driver.executeScript("await user.pointer(arguments[0])", inputs) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#click - */ -fun User.click(element: WebElement): User { - driver.executeScript("await user.click(arguments[0])", element) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#dblclick - */ -fun User.dblClick(element: WebElement): User { - driver.executeScript("await user.dblClick(arguments[0])", element) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#tripleclick - */ -fun User.tripleClick(element: WebElement): User { - driver.executeScript("await user.tripleClick(arguments[0])", element) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#hover - */ -fun User.hover(element: WebElement): User { - driver.executeScript("await user.hover(arguments[0])", element) - return this -} - -/** - * https://testing-library.com/docs/user-event/convenience#unhover - */ -fun User.unhover(element: WebElement): User { - driver.executeScript("await user.unhover(arguments[0])", element) - return this -} diff --git a/lib/src/main/kotlin/seleniumtestinglib/interactions/Utility.kt b/lib/src/main/kotlin/seleniumtestinglib/interactions/Utility.kt deleted file mode 100644 index e07c050..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/interactions/Utility.kt +++ /dev/null @@ -1,83 +0,0 @@ -package seleniumtestinglib.interactions - -import org.openqa.selenium.WebElement - -/** - * https://testing-library.com/docs/user-event/utility#clear - */ -fun User.clear(element: WebElement): User { - driver.executeScript("await user.clear(arguments[0])", element) - return this -} - -fun User.selectOptions(element: WebElement, vararg values: String): User { - driver.executeScript( - "await user.selectOptions(arguments[0], arguments[1])", element, values - ) - return this -} - -fun User.selectOptions(element: WebElement, vararg values: WebElement): User { - driver.executeScript( - "await user.selectOptions(arguments[0], arguments[1])", element, values - ) - return this -} - -/** - * https://testing-library.com/docs/user-event/utility#-selectoptions-deselectoptions - */ -fun User.deselectOptions(element: WebElement, vararg values: String): User { - driver.executeScript( - "await user.deselectOptions(arguments[0], arguments[1])", element, values - ) - return this -} - -fun User.deselectOptions(element: WebElement, vararg values: WebElement): User { - driver.executeScript( - "await user.deselectOptions(arguments[0], arguments[1])", element, values - ) - return this -} - -/** - * https://testing-library.com/docs/user-event/utility#type - */ -fun User.type( - element: WebElement, - text: String, - skipClick: Boolean? = null, - skipAutoClose: Boolean? = null, - initialSelectionStart: Int? = null, - initialSelectionEnd: Int? = null, -): User { - driver.executeScript( - "await user.type(arguments[0], arguments[1], arguments[2])", - element, - text, - mapOf( - "skipClick" to skipClick, - "skipAutoClose" to skipAutoClose, - "initialSelectionStart" to initialSelectionStart, - "initialSelectionEnd" to initialSelectionEnd, - ).filterValues { it != null } - ) - return this -} - -/** - * https://testing-library.com/docs/user-event/utility#upload - */ -fun User.upload(input: WebElement, file: File): User { - driver.executeScript( - "await user.upload(arguments[0], new File(arguments[1], arguments[2], arguments[3]))", - input, - file.bits, - file.name, - file.options - ) - return this -} - -data class File(val bits: List, val name: String, val options: Map = emptyMap()) diff --git a/lib/src/main/kotlin/seleniumtestinglib/locators/ByRole.kt b/lib/src/main/kotlin/seleniumtestinglib/locators/ByRole.kt deleted file mode 100644 index bc5610a..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/locators/ByRole.kt +++ /dev/null @@ -1,118 +0,0 @@ -package seleniumtestinglib.locators - -import seleniumtestinglib.queries.TextMatch -import seleniumtestinglib.queries.TextMatch.Companion.asJsString -import seleniumtestinglib.queries.asJsExpression -import java.util.regex.Pattern - -data class Value(val min: Int? = null, val max: Int? = null, val now: Int? = null, val text: TextMatch? = null) { - constructor(text: String? = null) : this(text = text?.asJsString()) - constructor(text: Pattern? = null) : this(text = text?.asJsExpression()) -} - -/* - * https://www.w3.org/TR/wai-aria-1.2/#aria-current - */ -internal sealed class Current(open val value: Any) { - override fun toString() = value.toString() - internal class CurrentAsType(value: CurrentType) : Current(value.name.lowercase().asJsString()) - internal class CurrentAsBool(value: Boolean) : Current(value) -} - -@Suppress("UNUSED") -enum class CurrentType { - Page, Step, Location, Date, Time -} - -/* - * https://www.w3.org/TR/wai-aria-1.2/#role_definitions - */ -@Suppress("UNUSED") -enum class RoleType { - Alert, - AlertDialog, - Application, - Article, - Banner, - Button, - Cell, - CheckBox, - ColumnHeader, - ComboBox, - Command, - Comment, - Complementary, - Composite, - ContentInfo, - Definition, - Dialog, - Directory, - Document, - Feed, - Figure, - Form, - Generic, - Grid, - GridCell, - Group, - Heading, - Img, - Input, - Landmark, - Link, - List, - ListBox, - ListItem, - Log, - Main, - Mark, - Marquee, - Math, - Menu, - MenuBar, - MenuItem, - MenuItemCheckBox, - MenuItemRadio, - Meter, - Navigation, - None, - Note, - Option, - Presentation, - ProgressBar, - Radio, - RadioGroup, - Range, - Region, - RoleType, - Row, - RowGroup, - RowHeader, - ScrollBar, - Search, - SearchBox, - Section, - SectionHead, - Select, - Separator, - Slider, - SpinButton, - Status, - Structure, - Suggestion, - Switch, - Tab, - Table, - TabList, - TabPanel, - Term, - TextBox, - Timer, - Toolbar, - Tooltip, - Tree, - TreeGrid, - TreeItem, - Widget, - Window, -} \ No newline at end of file diff --git a/lib/src/main/kotlin/seleniumtestinglib/queries/Api.kt b/lib/src/main/kotlin/seleniumtestinglib/queries/Api.kt deleted file mode 100644 index a9a5a6e..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/queries/Api.kt +++ /dev/null @@ -1,85 +0,0 @@ -package seleniumtestinglib.queries - -import org.openqa.selenium.JavascriptExecutor -import seleniumtestinglib.ensureScript -import java.util.regex.Pattern -import java.util.regex.Pattern.* -import kotlin.text.RegexOption.* - -/** - * https://testing-library.com/docs/dom-testing-library/intro - */ -internal inline fun JavascriptExecutor.executeTLQuery( - queryType: QueryType = QueryType.Query, - all: Boolean = true, - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = buildString { - append("return") - if (queryType == QueryType.Find) append(" await") - append(" screen.") - append(queryType.name.lowercase()) - if (all) append("All") - append("By") - append("${by.name}(${textMatch.escaped}") - options - .filterValues { it != null } - .takeIf(Map::isNotEmpty) - ?.escaped - ?.let { append(", $it") } - append(")") -}.let(::executeTLScript) as T - -enum class LocatorType { - AltText, DisplayValue, LabelText, PlaceholderText, Role, TestId, Text, Title -} - -internal enum class QueryType { - Find, Query, Get -} - -sealed class TextMatch(internal open val value: String) { - class JsFunction(override val value: String) : TextMatch(value) - internal class JsString(override val value: String) : TextMatch(value) - internal class JsExpression(override val value: String) : TextMatch(value) - - override fun toString() = value - - companion object { - fun String.asJsFunction() = JsFunction(this) - internal fun String.asJsString() = JsString(this) - } -} - -internal fun Pattern.asJsExpression(): TextMatch.JsExpression { - val flags = flags() - val jsFlags = buildString { - if (flags and CASE_INSENSITIVE != 0) append('i') - if (flags and RegexOption.MULTILINE.value != 0) append('m') - if (flags and DOTALL != 0) append('s') - if (flags and RegexOption.COMMENTS.value != 0) append('x') - if (flags and UNICODE_CASE != 0) append('u') - } - return TextMatch.JsExpression("/${pattern()}/$jsFlags") -} - -private fun JavascriptExecutor.executeTLScript(script: String): Any? { - ensureScript("testing-library.js", "screen?.queryAllByTestId") - return executeScript(script) -} - -private val String.quoted get() = "'${replace("'", "\\'")}'" - -private val Any?.escaped: Any? - get() = when (this) { - is TextMatch.JsString -> value.quoted - is TextMatch.JsFunction -> value - is TextMatch.JsExpression -> value - is String -> quoted - is Map<*, *> -> entries.joinToString(prefix = "{ ", postfix = " }") { - "${it.key}: ${it.value?.escaped}" - } - - else -> this - } diff --git a/lib/src/main/kotlin/seleniumtestinglib/queries/Find.kt b/lib/src/main/kotlin/seleniumtestinglib/queries/Find.kt deleted file mode 100644 index 024c0db..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/queries/Find.kt +++ /dev/null @@ -1,30 +0,0 @@ -package seleniumtestinglib.queries - -import org.openqa.selenium.JavascriptExecutor -import org.openqa.selenium.WebElement - -@Suppress("unused") -fun JavascriptExecutor.findBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery( - queryType = QueryType.Find, - all = false, - by = by, - textMatch = textMatch, - options = options, -) - -@Suppress("unused") -fun JavascriptExecutor.findAllBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery>( - queryType = QueryType.Find, - all = true, - by = by, - textMatch = textMatch, - options = options, -) diff --git a/lib/src/main/kotlin/seleniumtestinglib/queries/Get.kt b/lib/src/main/kotlin/seleniumtestinglib/queries/Get.kt deleted file mode 100644 index e1b95dc..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/queries/Get.kt +++ /dev/null @@ -1,41 +0,0 @@ -package seleniumtestinglib.queries - -import org.openqa.selenium.JavascriptExecutor -import org.openqa.selenium.WebElement -import seleniumtestinglib.queries.TextMatch.Companion.asJsString - -fun JavascriptExecutor.getBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery( - queryType = QueryType.Get, - all = false, - by = by, - textMatch = textMatch, - options = options, -) - -fun JavascriptExecutor.getBy( - by: LocatorType, - text: String, - options: Map = emptyMap(), -) = getBy(by, text.asJsString(), options) - -fun JavascriptExecutor.getAllBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery>( - queryType = QueryType.Get, - all = true, - by = by, - textMatch = textMatch, - options = options, -) - -fun JavascriptExecutor.getAllBy( - by: LocatorType, - text: String, - options: Map = emptyMap(), -) = getAllBy(by, text.asJsString(), options) diff --git a/lib/src/main/kotlin/seleniumtestinglib/queries/Query.kt b/lib/src/main/kotlin/seleniumtestinglib/queries/Query.kt deleted file mode 100644 index 1fa7319..0000000 --- a/lib/src/main/kotlin/seleniumtestinglib/queries/Query.kt +++ /dev/null @@ -1,41 +0,0 @@ -package seleniumtestinglib.queries - -import org.openqa.selenium.JavascriptExecutor -import org.openqa.selenium.WebElement -import seleniumtestinglib.queries.TextMatch.Companion.asJsString - -fun JavascriptExecutor.queryBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery( - queryType = QueryType.Query, - all = false, - by = by, - textMatch = textMatch, - options = options, -) - -fun JavascriptExecutor.queryBy( - by: LocatorType, - text: String, - options: Map = emptyMap(), -) = queryBy(by, text.asJsString(), options) - -fun JavascriptExecutor.queryAllBy( - by: LocatorType, - textMatch: TextMatch, - options: Map = emptyMap(), -) = executeTLQuery>( - queryType = QueryType.Query, - all = true, - by = by, - textMatch = textMatch, - options = options, -) - -fun JavascriptExecutor.queryAllBy( - by: LocatorType, - text: String, - options: Map = emptyMap(), -) = queryAllBy(by, text.asJsString(), options) diff --git a/lib/src/test/kotlin/seleniumtestinglib/FireEventTest.kt b/lib/src/test/kotlin/seleniumtestinglib/FireEventTest.kt index e885e3c..5c9c461 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/FireEventTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/FireEventTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib import seleniumtestinglib.Event.Change -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.locators.TL.By.role +import seleniumtestinglib.RoleType.TextBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertEquals diff --git a/lib/src/test/kotlin/seleniumtestinglib/TargetLocatorTest.kt b/lib/src/test/kotlin/seleniumtestinglib/TargetLocatorTest.kt index 4c6f44a..ae80dc9 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/TargetLocatorTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/TargetLocatorTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib import org.openqa.selenium.By -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.Article +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.Article import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull diff --git a/lib/src/test/kotlin/seleniumtestinglib/driver.kt b/lib/src/test/kotlin/seleniumtestinglib/driver.kt index 1bf200e..6b36120 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/driver.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/driver.kt @@ -3,8 +3,6 @@ package seleniumtestinglib import org.openqa.selenium.chrome.ChromeDriver import org.openqa.selenium.chrome.ChromeOptions import org.openqa.selenium.remote.RemoteWebDriver -import seleniumtestinglib.interactions.User -import seleniumtestinglib.interactions.user val driver = ChromeDriver(ChromeOptions().addArguments("--headless")) diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClearTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClearTest.kt index 083e2da..13eae06 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClearTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClearTest.kt @@ -1,10 +1,8 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render -import seleniumtestinglib.value +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.TextBox import kotlin.test.Test import kotlin.test.assertEquals diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClickTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClickTest.kt index c3e8510..8e3e86d 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClickTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClickTest.kt @@ -1,9 +1,9 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.isChecked -import seleniumtestinglib.locators.TL.By.labelText -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Keys +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.TL.By.labelText import kotlin.test.Test import kotlin.test.assertTrue @@ -35,8 +35,8 @@ class ClickTest { val checkbox = driver.findElement(labelText("Check")) driver.user.pointer( - mapOf("target" to checkbox), - mapOf("keys" to "[MouseLeft]", "target" to checkbox), + mapOf(Target to checkbox), + mapOf(Keys to "[MouseLeft]", Target to checkbox), ) assertTrue(checkbox.isChecked) diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClipboardTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClipboardTest.kt index 23b0cbd..63cca47 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/ClipboardTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/ClipboardTest.kt @@ -3,11 +3,11 @@ package seleniumtestinglib.interactions import org.junit.jupiter.api.Disabled import org.openqa.selenium.By.id import org.openqa.selenium.By.tagName -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render -import seleniumtestinglib.value +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.* +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.TextBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -32,8 +32,8 @@ class ClipboardTest { .render("""""") .type(driver.findElement(id("a")), "text") .pointer( - mapOf("target" to driver.findElement(role(TextBox)), "offset" to 0, "keys" to "[MouseLeft>]"), - mapOf("offset" to 5) + mapOf(Target to driver.findElement(role(TextBox)), Offset to 0, Keys to "[MouseLeft>]"), + mapOf(Offset to 5) ) assertFalse(driver.findElement(id("a")).value?.toString()?.isEmpty() ?: true) @@ -49,9 +49,9 @@ class ClipboardTest { """

heading: title

""" ) - driver.user("writeToClipboard" to true).pointer( - mapOf("target" to driver.findElement(tagName("h1")), "offset" to 7, "keys" to "[MouseLeft>]"), - mapOf("offset" to 14) + driver.user(UserOption.WriteToClipboard to true).pointer( + mapOf(Target to driver.findElement(tagName("h1")), Offset to 7, Keys to "[MouseLeft>]"), + mapOf(Offset to 14) ) driver.user.copy() driver.user.click(driver.findElement(role(TextBox))) diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/DeselectOptionsTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/DeselectOptionsTest.kt index 980cb3f..3678c4b 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/DeselectOptionsTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/DeselectOptionsTest.kt @@ -1,10 +1,8 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType -import seleniumtestinglib.locators.RoleType.ListBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.ListBox import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/DoubleClickTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/DoubleClickTest.kt index a143846..9bbfa69 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/DoubleClickTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/DoubleClickTest.kt @@ -1,10 +1,10 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.isChecked -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.CheckBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Keys +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.CheckBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertFalse @@ -26,8 +26,8 @@ class DoubleClickTest { val checkbox = driver.findElement(role(CheckBox)) driver.user.pointer( - mapOf("target" to checkbox), - mapOf("keys" to "[MouseLeft][MouseLeft]", "target" to checkbox), + mapOf(Target to checkbox), + mapOf(Keys to "[MouseLeft][MouseLeft]", Target to checkbox), ) assertFalse(checkbox.isChecked) diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/GeneralTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/GeneralTest.kt index d3ff224..aa61e17 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/GeneralTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/GeneralTest.kt @@ -4,10 +4,11 @@ import com.google.common.io.Files import org.junit.jupiter.api.Disabled import org.openqa.selenium.By import org.openqa.selenium.OutputType -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.CheckBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Keys +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.CheckBox +import seleniumtestinglib.TL.By.role import java.awt.Desktop import java.io.File import kotlin.test.Test @@ -36,8 +37,8 @@ class GeneralTest { .keyboard("{Enter}") .pointer( mapOf( - "keys" to "[MouseLeft]", - "target" to driver.findElement(By.tagName("select")), + Keys to "[MouseLeft]", + Target to driver.findElement(By.tagName("select")), ) ) val file = File.createTempFile("test", ".png") diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/HoverTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/HoverTest.kt index a2b7014..75b4174 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/HoverTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/HoverTest.kt @@ -1,10 +1,10 @@ package seleniumtestinglib.interactions import org.openqa.selenium.By -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.TextBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertEquals @@ -45,7 +45,7 @@ class HoverTest { ) val input = driver.findElement(role(TextBox)) - driver.user.pointer(mapOf("target" to input)) + driver.user.pointer(mapOf(Target to input)) assertEquals("hovered!", driver.findElement(By.id("result")).text) } diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/KeyboardTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/KeyboardTest.kt index 63a83cb..8f5df15 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/KeyboardTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/KeyboardTest.kt @@ -3,11 +3,9 @@ package seleniumtestinglib.interactions import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render -import seleniumtestinglib.value +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.TextBox import kotlin.test.assertEquals class KeyboardTest { diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/PointerTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/PointerTest.kt index eeffe22..49afd48 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/PointerTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/PointerTest.kt @@ -1,12 +1,12 @@ package seleniumtestinglib.interactions import org.openqa.selenium.By -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.Banner -import seleniumtestinglib.locators.RoleType.ContentInfo -import seleniumtestinglib.render -import seleniumtestinglib.selection +import seleniumtestinglib.* +import seleniumtestinglib.RoleType.Banner +import seleniumtestinglib.RoleType.ContentInfo +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.PointerOption.* +import seleniumtestinglib.PointerOption.Target import kotlin.test.Test import kotlin.test.assertEquals @@ -70,8 +70,8 @@ class PointerTest { driver.render("
foobar
") driver.user.pointer( - mapOf("target" to driver.findElement(By.tagName("div")), "offset" to 2, "keys" to "[MouseLeft>]"), - mapOf("offset" to 5) + mapOf(Target to driver.findElement(By.tagName("div")), Offset to 2, Keys to "[MouseLeft>]"), + mapOf(Offset to 5) ) assertEquals("oba", driver.selection) @@ -97,9 +97,9 @@ class PointerTest { ) driver.user.pointer( - mapOf("keys" to "[TouchA>]", "target" to driver.findElement(role(Banner))), - mapOf("pointerName" to "TouchA", "target" to driver.findElement(role(ContentInfo))), - mapOf("keys" to "[/TouchA]"), + mapOf(Keys to "[TouchA>]", Target to driver.findElement(role(Banner))), + mapOf(PointerName to "TouchA", Target to driver.findElement(role(ContentInfo))), + mapOf(Keys to "[/TouchA]"), ) assertEquals( diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/SelectOptionsTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/SelectOptionsTest.kt index fa674ca..e57316a 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/SelectOptionsTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/SelectOptionsTest.kt @@ -1,10 +1,12 @@ package seleniumtestinglib.interactions import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.ListBox -import seleniumtestinglib.locators.RoleType.Option +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.ListBox +import seleniumtestinglib.RoleType.Option import seleniumtestinglib.render +import seleniumtestinglib.selectOptions +import seleniumtestinglib.user import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/TabTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/TabTest.kt index 9cc0513..3a412b1 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/TabTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/TabTest.kt @@ -1,10 +1,8 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.isFocused -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.Radio -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.Radio import kotlin.test.Test import kotlin.test.assertTrue diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/TripleClickTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/TripleClickTest.kt index 8758b2b..d7c9f8b 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/TripleClickTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/TripleClickTest.kt @@ -1,10 +1,10 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.isChecked -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.CheckBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Keys +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.CheckBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertTrue @@ -26,8 +26,8 @@ class TripleClickTest { val checkbox = driver.findElement(role(CheckBox)) driver.user.pointer( - mapOf("target" to checkbox), - mapOf("keys" to "[MouseLeft]".repeat(3), "target" to checkbox), + mapOf(Target to checkbox), + mapOf(Keys to "[MouseLeft]".repeat(3), Target to checkbox), ) assertTrue(checkbox.isChecked) diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/TypeTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/TypeTest.kt index 752d133..f452625 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/TypeTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/TypeTest.kt @@ -1,11 +1,9 @@ package seleniumtestinglib.interactions import org.openqa.selenium.By -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render -import seleniumtestinglib.value +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.RoleType.TextBox import kotlin.test.Test import kotlin.test.assertEquals diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/UnhoverTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/UnhoverTest.kt index 01bd3df..8d3f378 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/UnhoverTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/UnhoverTest.kt @@ -2,10 +2,10 @@ package seleniumtestinglib.interactions import org.openqa.selenium.By.id import org.openqa.selenium.By.tagName -import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.RoleType.TextBox -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.PointerOption.Target +import seleniumtestinglib.RoleType.TextBox +import seleniumtestinglib.TL.By.role import kotlin.test.Test import kotlin.test.assertEquals @@ -48,7 +48,7 @@ class UnhoverTest { val input = driver.findElement(role(TextBox)) driver.user.hover(input) - driver.user.pointer(mapOf("target" to driver.findElement(tagName("body")))) + driver.user.pointer(mapOf(Target to driver.findElement(tagName("body")))) assertEquals("unhovered!", driver.findElement(id("result")).text) } diff --git a/lib/src/test/kotlin/seleniumtestinglib/interactions/UploadTest.kt b/lib/src/test/kotlin/seleniumtestinglib/interactions/UploadTest.kt index d2b4a62..13ab760 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/interactions/UploadTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/interactions/UploadTest.kt @@ -1,9 +1,7 @@ package seleniumtestinglib.interactions -import seleniumtestinglib.driver -import seleniumtestinglib.files -import seleniumtestinglib.locators.TL.By.labelText -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.labelText import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE import kotlin.test.Test diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleDescriptionTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleDescriptionTest.kt index 4591146..b229c98 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleDescriptionTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleDescriptionTest.kt @@ -3,10 +3,10 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.By +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.accessibleDescription import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertEquals @@ -27,10 +27,10 @@ class AccessibleDescriptionTest { fun `accessible description`(html: String) { driver.render(html) - assertEquals("accessible description", driver.getBy(TestId, "x").accessibleDescription) - expect(driver.getBy(TestId, "x")).toHaveAccessibleDescription() - expect(driver.getBy(TestId, "x")).toHaveAccessibleDescription("accessible description") - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleDescription("not this one") + assertEquals("accessible description", driver.findElement(testId("x")).accessibleDescription) + expect(driver.findElement(testId("x"))).toHaveAccessibleDescription() + expect(driver.findElement(testId("x"))).toHaveAccessibleDescription("accessible description") + expect(driver.findElement(testId("x"))).not.toHaveAccessibleDescription("not this one") } @Test @@ -40,18 +40,18 @@ class AccessibleDescriptionTest { ) - expect(driver.getBy(TestId, "x")).toHaveAccessibleDescription(Regex("accessible", IGNORE_CASE)) - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleDescription(Regex("nope", IGNORE_CASE)) + expect(driver.findElement(testId("x"))).toHaveAccessibleDescription(Regex("accessible", IGNORE_CASE)) + expect(driver.findElement(testId("x"))).not.toHaveAccessibleDescription(Regex("nope", IGNORE_CASE)) } @Test fun function() { driver.render("""""") - expect(driver.getBy(TestId, "x")).toHaveAccessibleDescription { + expect(driver.findElement(testId("x"))).toHaveAccessibleDescription { it.startsWith("access", ignoreCase = true) } - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleDescription { + expect(driver.findElement(testId("x"))).not.toHaveAccessibleDescription { it.startsWith("access", ignoreCase = false) } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt index 60e7a06..c8edfe6 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AccessibleNameTest.kt @@ -2,9 +2,9 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertEquals @@ -25,10 +25,10 @@ class AccessibleNameTest { fun `accessible name`(html: String) { driver.render(html) - assertEquals("accessible name", driver.getBy(TestId, "x").accessibleName) - expect(driver.getBy(TestId, "x")).toHaveAccessibleName() - expect(driver.getBy(TestId, "x")).toHaveAccessibleName("accessible name") - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleName("abc") + assertEquals("accessible name", driver.findElement(testId( "x")).accessibleName) + expect(driver.findElement(testId( "x"))).toHaveAccessibleName() + expect(driver.findElement(testId( "x"))).toHaveAccessibleName("accessible name") + expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName("abc") } @ParameterizedTest @@ -42,9 +42,9 @@ class AccessibleNameTest { fun `not accessible name`(html: String) { driver.render(html) - assertEquals("", driver.getBy(TestId, "x").accessibleName) - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleName() - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleName("abc") + assertEquals("", driver.findElement(testId( "x")).accessibleName) + expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName() + expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName("abc") } @Test @@ -54,18 +54,18 @@ class AccessibleNameTest { ) - expect(driver.getBy(TestId, "x")).toHaveAccessibleName(Regex("accessible", IGNORE_CASE)) - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleName(Regex("nope", IGNORE_CASE)) + expect(driver.findElement(testId( "x"))).toHaveAccessibleName(Regex("accessible", IGNORE_CASE)) + expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName(Regex("nope", IGNORE_CASE)) } @Test fun function() { driver.render("""accessible name""") - expect(driver.getBy(TestId, "x")).toHaveAccessibleName { + expect(driver.findElement(testId( "x"))).toHaveAccessibleName { it.endsWith("name") } - expect(driver.getBy(TestId, "x")).not.toHaveAccessibleName { + expect(driver.findElement(testId( "x"))).not.toHaveAccessibleName { it.endsWith("NAME") } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AttributeTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AttributeTest.kt index 115a264..c09a5bd 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/AttributeTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/AttributeTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -12,7 +12,7 @@ class AttributeTest { fun `has attribute`() { driver.render("""""") - val button = driver.getBy(TestId, "ok-button") + val button = driver.findElement(testId( "ok-button")) expect(button).toHaveAttribute("disabled") expect(button).toHaveAttribute("type", "submit") diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/CheckedTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/CheckedTest.kt index e38038d..45cc241 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/CheckedTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/CheckedTest.kt @@ -2,10 +2,10 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isChecked -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy import seleniumtestinglib.render import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -24,7 +24,7 @@ class CheckedTest { ) fun checked(html: String) { driver.render(html) - val checkbox = driver.getBy(TestId, "x") + val checkbox = driver.findElement(testId("x")) assertTrue(checkbox.isChecked) expect(checkbox).toBeChecked() @@ -42,7 +42,7 @@ class CheckedTest { ) fun `not checked`(html: String) { driver.render(html) - val checkbox = driver.getBy(TestId, "x") + val checkbox = driver.findElement(testId("x")) assertFalse(checkbox.isChecked) expect(checkbox).not.toBeChecked() diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ClassTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ClassTest.kt index 7714fe9..46da4d0 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ClassTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ClassTest.kt @@ -1,9 +1,9 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.classes import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertEquals @@ -18,7 +18,7 @@ class ClassTest { """ ) - val deleteButton = driver.getBy(TestId, "delete-button") + val deleteButton = driver.findElement(testId("delete-button")) assertEquals(setOf("btn", "btn-danger", "extra"), deleteButton.classes) expect(deleteButton).toHaveClass() expect(deleteButton).toHaveClass("extra") @@ -33,7 +33,7 @@ class ClassTest { fun `no classes`() { driver.render("""""") - val noClasses = driver.getBy(TestId, "no-classes") + val noClasses = driver.findElement(testId("no-classes")) assertEquals(emptySet(), noClasses.classes) expect(noClasses).not.toHaveClass() } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainElementTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainElementTest.kt index 5a494db..1fd02f8 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainElementTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainElementTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.queryBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -12,12 +12,10 @@ class ContainElementTest { fun `contain element`() { driver.render("""""") - val ancestor = driver.queryBy(TestId, "ancestor") - val descendant = driver.queryBy(TestId, "descendant") - val nonExistentElement = driver.queryBy(TestId, "does-not-exist") + val ancestor = driver.findElement(testId( "ancestor")) + val descendant = driver.findElement(testId( "descendant")) expect(ancestor).toContainElement(descendant) expect(descendant).not.toContainElement(ancestor) - expect(ancestor).not.toContainElement(nonExistentElement) } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainHtmlTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainHtmlTest.kt index 90ab9be..42c4d46 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainHtmlTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ContainHtmlTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.queryBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -12,7 +12,7 @@ class ContainHtmlTest { fun `contain html`() { driver.render("""""") - val element = driver.queryBy(TestId, "parent") + val element = driver.findElement(testId( "parent")) expect(element).toContainHtml("""""") expect(element).toContainHtml("") expect(element).not.toContainHtml("
") diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisabledTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisabledTest.kt index ac44dbd..97441f7 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisabledTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisabledTest.kt @@ -2,12 +2,9 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource -import seleniumtestinglib.driver -import seleniumtestinglib.isDisabled -import seleniumtestinglib.queries.LocatorType.Role -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.TL.By.testId import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -23,7 +20,7 @@ class DisabledTest { ) fun disabled(html: String) { driver.render(html) - val element = driver.getBy(TestId, "test1") + val element = driver.findElement(testId("test1")) assertTrue(element.isDisabled) expect(element).toBeDisabled() @@ -32,7 +29,7 @@ class DisabledTest { @Test fun `links cant be disabled`() { driver.render("""link""") - val element = driver.getBy(Role, "link") + val element = driver.findElement(role(RoleType.Link)) assertFalse(element.isDisabled) expect(element).not.toBeDisabled() diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisplayValueTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisplayValueTest.kt index 9f7024a..93356a5 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisplayValueTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/DisplayValueTest.kt @@ -3,11 +3,12 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments.arguments import org.junit.jupiter.params.provider.MethodSource +import seleniumtestinglib.RoleType.ListBox +import seleniumtestinglib.TL.By.labelText +import seleniumtestinglib.TL.By.role import seleniumtestinglib.displayValue import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.LabelText -import seleniumtestinglib.queries.LocatorType.Role -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import java.util.stream.Stream import kotlin.test.Test @@ -20,7 +21,7 @@ class DisplayValueTest { fun `display value`(html: String, expectedDisplayValue: String, expectedDisplayValueByRegex: Regex) { driver.render(html) - val element = driver.getBy(LabelText, "example") + val element = driver.findElement(labelText("example")) assertEquals(expectedDisplayValue, element.displayValue) expect(element).toHaveDisplayValue(expectedDisplayValue) expect(element).toHaveDisplayValue(expectedDisplayValueByRegex) @@ -63,7 +64,7 @@ class DisplayValueTest { """ ) - val element = driver.getBy(Role, "listbox") + val element = driver.findElement(role(ListBox)) expect(element).toHaveDisplayValue(listOf("Banana", "Avocado")) } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/EmptyDomElementTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/EmptyDomElementTest.kt index b4e8feb..5a81352 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/EmptyDomElementTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/EmptyDomElementTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.By import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.render class EmptyDomElementTest { diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/EnabledTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/EnabledTest.kt index 95ceb27..da8dd97 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/EnabledTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/EnabledTest.kt @@ -1,8 +1,9 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.RoleType.TextBox +import seleniumtestinglib.TL.By.role import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.Role -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -12,13 +13,13 @@ class EnabledTest { fun enabled() { driver.render("
") - expect(driver.getBy(Role, "textbox")).toBeEnabled() + expect(driver.findElement(role(TextBox))).toBeEnabled() } @Test fun `not enabled`() { driver.render("
") - expect(driver.getBy(Role, "textbox")).not.toBeEnabled() + expect(driver.findElement(role(TextBox))).not.toBeEnabled() } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ErrorMessageTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ErrorMessageTest.kt index 1d90a6b..b31ca10 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ErrorMessageTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ErrorMessageTest.kt @@ -1,8 +1,9 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.labelText import seleniumtestinglib.driver import seleniumtestinglib.errorMessage -import seleniumtestinglib.locators.TL.By.labelText +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertEquals diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt index 4b4f50e..b58b0f5 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FocusTest.kt @@ -1,11 +1,7 @@ package seleniumtestinglib.jestdom -import seleniumtestinglib.driver -import seleniumtestinglib.interactions.tab -import seleniumtestinglib.interactions.user -import seleniumtestinglib.isFocused -import seleniumtestinglib.locators.TL.By.testId -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.TL.By.testId import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FormValuesTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FormValuesTest.kt index 0444731..2fba7d3 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/FormValuesTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/FormValuesTest.kt @@ -1,9 +1,10 @@ package seleniumtestinglib.jestdom import org.openqa.selenium.By +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.formValues -import seleniumtestinglib.locators.TL.By.testId import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertEquals diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/InTheDocumentTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/InTheDocumentTest.kt index 0e2ae25..64c496f 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/InTheDocumentTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/InTheDocumentTest.kt @@ -1,9 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy -import seleniumtestinglib.queries.queryBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -15,7 +14,6 @@ class InTheDocumentTest { """Html Element""" ) - expect(driver.getBy(TestId, "html-element")).toBeInTheDocument() - expect(driver.queryBy(TestId, "not-there")).not.toBeInTheDocument() + expect(driver.findElement(testId("html-element"))).toBeInTheDocument() } } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/InvalidTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/InvalidTest.kt index daa7549..b73870a 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/InvalidTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/InvalidTest.kt @@ -2,10 +2,10 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isInvalid -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy import seleniumtestinglib.render import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -24,7 +24,7 @@ class InvalidTest { ) fun invalid(html: String) { driver.render(html) - val element = driver.getBy(TestId, "invalid") + val element = driver.findElement(testId("invalid")) assertTrue(element.isInvalid) expect(element).toBeInvalid() @@ -42,7 +42,7 @@ class InvalidTest { ) fun `not invalid`(html: String) { driver.render(html) - val element = driver.getBy(TestId, "not-invalid") + val element = driver.findElement(testId("not-invalid")) assertFalse(element.isInvalid) expect(element).not.toBeInvalid() diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/PartiallyCheckedTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/PartiallyCheckedTest.kt index 1e7d63f..0bfae88 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/PartiallyCheckedTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/PartiallyCheckedTest.kt @@ -2,11 +2,12 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource +import seleniumtestinglib.RoleType.CheckBox +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isPartiallyChecked -import seleniumtestinglib.queries.LocatorType -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy import seleniumtestinglib.render import kotlin.test.Test import kotlin.test.assertFalse @@ -17,7 +18,7 @@ class PartiallyCheckedTest { @Test fun `partially checked by aria`() { driver.render("""""") - val checkbox = driver.getBy(LocatorType.Role, "checkbox") + val checkbox = driver.findElement(role(CheckBox)) assertTrue(checkbox.isPartiallyChecked) expect(checkbox).toBePartiallyChecked() @@ -26,7 +27,7 @@ class PartiallyCheckedTest { @Test fun `partially checked by attr`() { driver.render("""""") - val checkbox = driver.getBy(LocatorType.Role, "checkbox") + val checkbox = driver.findElement(role(CheckBox)) assertFalse(checkbox.isPartiallyChecked) expect(checkbox).not.toBePartiallyChecked() @@ -46,7 +47,7 @@ class PartiallyCheckedTest { fun `not partially checked`(html: String) { driver.render(html) - val element = driver.getBy(TestId, "x") + val element = driver.findElement(testId("x")) assertFalse(element.isPartiallyChecked) expect(element).not.toBePartiallyChecked() } diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/RequiredTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/RequiredTest.kt index 4c36366..126c0e8 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/RequiredTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/RequiredTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.By import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isRequired import seleniumtestinglib.render import kotlin.test.assertFalse diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt index f9cde41..5c83d6e 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/StyleTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test @@ -17,7 +17,7 @@ class StyleTest { """ ) - val button = driver.getBy(TestId, "delete-button") + val button = driver.findElement(testId("delete-button")) expect(button).toHaveStyle("display: none") expect(button).toHaveStyle(mapOf("display" to "none")) diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/TextContentTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/TextContentTest.kt index ca75822..dffc25e 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/TextContentTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/TextContentTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import kotlin.test.Test import kotlin.text.RegexOption.IGNORE_CASE @@ -13,7 +13,7 @@ class TextContentTest { fun `text content`() { driver.render("""Text Content""") - val element = driver.getBy(TestId, "text-content") + val element = driver.findElement(testId("text-content")) expect(element).toHaveTextContent("Content") expect(element).toHaveTextContent(Regex("^Text Content$")) diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValidTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValidTest.kt index 1cb5cef..d50c5d7 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValidTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValidTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.By.id import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isValid import seleniumtestinglib.render import kotlin.test.assertFalse diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValueTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValueTest.kt index d3a2151..3d1f8c7 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValueTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/ValueTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.jestdom +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy +import seleniumtestinglib.expect import seleniumtestinglib.render import seleniumtestinglib.value import kotlin.test.Test @@ -25,10 +25,10 @@ class ValueTest { """ ) - val textInput = driver.getBy(TestId, "input-text") - val numberInput = driver.getBy(TestId, "input-number") - val emptyInput = driver.getBy(TestId, "input-empty") - val selectInput = driver.getBy(TestId, "select-number") + val textInput = driver.findElement(testId("input-text")) + val numberInput = driver.findElement(testId("input-number")) + val emptyInput = driver.findElement(testId("input-empty")) + val selectInput = driver.findElement(testId("select-number")) assertEquals("text", textInput.value) expect(textInput).toHaveValue("text") diff --git a/lib/src/test/kotlin/seleniumtestinglib/jestdom/VisibleTest.kt b/lib/src/test/kotlin/seleniumtestinglib/jestdom/VisibleTest.kt index d860453..321ea09 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/jestdom/VisibleTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/jestdom/VisibleTest.kt @@ -2,10 +2,10 @@ package seleniumtestinglib.jestdom import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource +import seleniumtestinglib.TL.By.testId import seleniumtestinglib.driver +import seleniumtestinglib.expect import seleniumtestinglib.isVisible -import seleniumtestinglib.queries.LocatorType.TestId -import seleniumtestinglib.queries.getBy import seleniumtestinglib.render import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -24,7 +24,7 @@ class VisibleTest { ) fun visible(html: String) { driver.render(html) - val element = driver.getBy(TestId, "x") + val element = driver.findElement(testId("x")) assertTrue(element.isVisible) expect(element).toBeVisible() @@ -50,7 +50,7 @@ class VisibleTest { ) fun `not visible`(html: String) { driver.render(html) - val element = driver.getBy(TestId, "x") + val element = driver.findElement(testId("x")) assertFalse(element.isVisible) expect(element).not.toBeVisible() diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByAltTextTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByAltTextTest.kt index e341dde..31b0897 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByAltTextTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByAltTextTest.kt @@ -3,9 +3,9 @@ package seleniumtestinglib.locators import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.NoSuchElementException +import seleniumtestinglib.JsFunction import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.altText -import seleniumtestinglib.queries.TextMatch.JsFunction +import seleniumtestinglib.TL.By.altText import seleniumtestinglib.render import java.util.regex.Pattern import kotlin.test.Test diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByDisplayValueTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByDisplayValueTest.kt index 4d0be18..6227f01 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByDisplayValueTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByDisplayValueTest.kt @@ -3,9 +3,9 @@ package seleniumtestinglib.locators import org.openqa.selenium.By.tagName import org.openqa.selenium.support.ui.Select import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.displayValue -import seleniumtestinglib.locators.TL.By.placeholderText -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.TL.By.displayValue +import seleniumtestinglib.TL.By.placeholderText +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByLabelTextTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByLabelTextTest.kt index 55be904..67e9247 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByLabelTextTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByLabelTextTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.locators import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.labelText -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.TL.By.labelText +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByPlaceholderTextTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByPlaceholderTextTest.kt index 9b57288..7d47121 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByPlaceholderTextTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByPlaceholderTextTest.kt @@ -4,8 +4,8 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.openqa.selenium.NoSuchElementException import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.placeholderText -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.TL.By.placeholderText +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByRoleTestType.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByRoleTestType.kt index 1866b4b..912733c 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByRoleTestType.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByRoleTestType.kt @@ -5,12 +5,10 @@ import org.junit.jupiter.params.provider.Arguments.of import org.junit.jupiter.params.provider.EnumSource import org.junit.jupiter.params.provider.MethodSource import org.openqa.selenium.WebElement -import seleniumtestinglib.driver -import seleniumtestinglib.locators.RoleType.* -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction -import seleniumtestinglib.queries.TextMatch.JsFunction -import seleniumtestinglib.render +import seleniumtestinglib.* +import seleniumtestinglib.RoleType +import seleniumtestinglib.RoleType.* +import seleniumtestinglib.TL.By.role import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE import kotlin.test.Test diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTestIdTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTestIdTest.kt index c883e71..3bccbd9 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTestIdTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTestIdTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.locators import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.testId -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.TL.By.testId +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import kotlin.test.Test diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTextTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTextTest.kt index 50b7048..3ec413d 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTextTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTextTest.kt @@ -4,8 +4,9 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments.of import org.junit.jupiter.params.provider.MethodSource import org.openqa.selenium.NoSuchElementException +import seleniumtestinglib.TL +import seleniumtestinglib.asJsFunction import seleniumtestinglib.driver -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import kotlin.test.Test diff --git a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTitleTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTitleTest.kt index bb18819..4c4081e 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/locators/ByTitleTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/ByTitleTest.kt @@ -1,8 +1,8 @@ package seleniumtestinglib.locators import seleniumtestinglib.driver -import seleniumtestinglib.locators.TL.By.title -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.TL.By.title +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern import java.util.regex.Pattern.CASE_INSENSITIVE diff --git a/lib/src/test/kotlin/seleniumtestinglib/queries/NotFoundTest.kt b/lib/src/test/kotlin/seleniumtestinglib/locators/NotFoundTest.kt similarity index 51% rename from lib/src/test/kotlin/seleniumtestinglib/queries/NotFoundTest.kt rename to lib/src/test/kotlin/seleniumtestinglib/locators/NotFoundTest.kt index 0ba0e0a..8b59c9a 100644 --- a/lib/src/test/kotlin/seleniumtestinglib/queries/NotFoundTest.kt +++ b/lib/src/test/kotlin/seleniumtestinglib/locators/NotFoundTest.kt @@ -1,42 +1,28 @@ -package seleniumtestinglib.queries +package seleniumtestinglib.locators import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments.of import org.junit.jupiter.params.provider.MethodSource import org.openqa.selenium.By -import org.openqa.selenium.JavascriptException import org.openqa.selenium.NoSuchElementException import seleniumtestinglib.driver -import seleniumtestinglib.locators.CurrentType.Page -import seleniumtestinglib.locators.RoleType.SpinButton -import seleniumtestinglib.locators.TL.By.placeholderText -import seleniumtestinglib.locators.TL.By.role -import seleniumtestinglib.locators.TL.By.text -import seleniumtestinglib.locators.Value -import seleniumtestinglib.queries.LocatorType.AltText -import seleniumtestinglib.queries.TextMatch.Companion.asJsFunction +import seleniumtestinglib.CurrentType.Page +import seleniumtestinglib.RoleType.SpinButton +import seleniumtestinglib.TL.By.altText +import seleniumtestinglib.TL.By.placeholderText +import seleniumtestinglib.TL.By.role +import seleniumtestinglib.TL.By.text +import seleniumtestinglib.Value +import seleniumtestinglib.asJsFunction import seleniumtestinglib.render import java.util.regex.Pattern.CASE_INSENSITIVE import java.util.regex.Pattern.compile import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertNull import kotlin.test.assertTrue class NotFoundTest { - @Test - fun `get but none found`() { - driver.render("
") - - val result = kotlin.runCatching { - driver.getBy(AltText, "will not work") - } - - val ex = result.exceptionOrNull() as JavascriptException - assertTrue(ex.message?.contains("Unable to find an element with the alt text: will not work")!!, ex.message) - } - private fun `findElement error cases`() = setOf( of( text(compile("a", CASE_INSENSITIVE)), @@ -65,27 +51,6 @@ class NotFoundTest { assertTrue(ex.message!!.contains("Cannot locate an element using $error"), """Actual: ${ex.message}""") } - @Test - fun `get all but none found`() { - driver.render("
") - - val result = runCatching { - driver.getAllBy(AltText, "will not work") - } - - val ex = result.exceptionOrNull() as JavascriptException - assertTrue(ex.message!!.contains("Unable to find an element with the alt text: will not work"), ex.message) - } - - @Test - fun `query returns none`() { - driver.render("
") - - val result = driver.queryBy(AltText, "will not work") - - assertNull(result?.tagName) - } - @Test fun `query all but none found`() { driver.render( @@ -95,7 +60,7 @@ class NotFoundTest { """ ) - val result = driver.queryAllBy(AltText, "incredibles", mapOf("exact" to true)) + val result = driver.findElements(altText("incredibles", exact = true)) assertEquals(emptyList(), result) } diff --git a/lib/src/test/kotlin/seleniumtestinglib/queries/ByAltTextTest.kt b/lib/src/test/kotlin/seleniumtestinglib/queries/ByAltTextTest.kt deleted file mode 100644 index f01efd0..0000000 --- a/lib/src/test/kotlin/seleniumtestinglib/queries/ByAltTextTest.kt +++ /dev/null @@ -1,56 +0,0 @@ -package seleniumtestinglib.queries - -import seleniumtestinglib.driver -import seleniumtestinglib.queries.LocatorType.AltText -import seleniumtestinglib.render -import kotlin.test.Test -import kotlin.test.assertEquals - -class ByAltTextTest { - - @Test - fun `get by alt text`() { - driver.render("") - - val result = driver.getBy(AltText, "incredibles", mapOf("exact" to false)) - - assertEquals("input", result.tagName) - } - - @Test - fun `get all by alt text`() { - driver.render( - """ - - - """ - ) - - val result = driver.getAllBy(AltText, "incredibles", mapOf("exact" to false)) - - assertEquals(2, result.count { it.tagName == "input" }) - } - - @Test - fun `query by alt text`() { - driver.render("") - - val result = driver.queryBy(AltText, "incredibles", mapOf("exact" to false)) - - assertEquals("input", result?.tagName) - } - - @Test - fun `query all by alt text`() { - driver.render( - """ - - - """ - ) - - val result = driver.queryAllBy(AltText, "incredibles", mapOf("exact" to false)) - - assertEquals(2, result.count { it.tagName == "input" }) - } -} diff --git a/release b/release index ab3fe45..df03968 100755 --- a/release +++ b/release @@ -1,11 +1,10 @@ #!/bin/sh set -e - VERSION="$1" + sed -i '' "s/version = \"\(.*\)\"/version = \"$VERSION\"/" lib/build.gradle.kts sed -i '' "s/com.luissoares:selenium-testing-library:[^\"]*/com.luissoares:selenium-testing-library:$VERSION/" README.md - git add lib/build.gradle.kts README.md || true git commit -m "Update version to $VERSION" || true git push @@ -13,5 +12,4 @@ git push git tag -l | xargs git tag -d git push --delete origin "v$VERSION" || true git tag "v$VERSION" -m "Tag release for version $VERSION" - git push origin "v$VERSION" \ No newline at end of file