In an earlier blog post we explained how convenience methods could be used to write more expressive AskUI code.
Those were based on common use cases we noticed and already brought improvements.
But we also discovered they needed to be more streamlined and include relations, to be useful in every scenario. That is why we went back to the drawing board to redesign the API and also include more elements like switches and checkboxes.
We think this update will be very useful for your efficiency!
Prerequisites
- AskUI installed and configured on your system (Windows, Linux, macOS)
- Check package.json for askui in version 0.18.0
The Idea Behind the Update
We wanted to have a more expressive method signature with better code completion. Also the method signatures should be more alike, so using does not feel like "Oh I have to read the docs every time!?".
That is why we chose to use objects with properties, so you can leverage "names" for parameters and also better Intellisense. Generally, the objects look nearly the same for every method and now also include an optional relation, so you can target elements that normally have a label or text nearest to them in some way:
- Example: await aui.clickCheckbox({label: 'Toggle', relation: {type: 'leftOf'}})
Breaking Changes
We introduced two breaking changes for existing convenience methods clickText() and clickButton(). This was necessary to align the method signatures with the newly implemented convenience methods presented later in this post.
clickText()
What it does: Clicks a text.
What does it solve: More concise code for clicking a specific text.
clickButton()
What it does: Clicks a button that has a text on it.
What does it solve: More concise code for clicking a button.
clickCheckbox()
What it does: Clicks a checkbox that has a label nearest to it.
What does it solve: More concise code for finding and clicking a checkbox.
Example code:
clickSwitch
What it does: Clicks a switch that has a label nearest to it.
What does it solve: More concise code for finding and clicking a switch.
Example code:
typeIntoTextfield()
What it does: Types text into a textfield which is specified in relation to a label.
What does it solve: More concise code for typing text into a textfield, where the textfield can be specified through a relation.
API docs for typeIntoTextfield()
Example code:
Conclusion
The update for the convenience methods unifies most of the common use cases. It also introduces objects as parameters that feel like named parameters.
Please let us know if you find them useful or if you need a convenience method for a specific purpose.