Real interactivity is what characterizes what an end-user is doing on a User Interface (UI). This is why it is important to extract data from your UI into your tool and use it later, for assertions for example 🔧.
We will show two ways to use askui for real interactivity by extracting text out of your UI and use it for assertions:
- askui assertions
- Jest assertions
- askui installed: Follow our Getting Started or try it in Gitpod
- A browser to open this page
Explaining the Use Case
When you open the page linked above it takes you to an interactive login form.
We will do the following steps to create a real end-user workflow:
- Enter the E-Mail and Password
- Extract the captcha value
- Enter it into the designated captcha textfield
- Click the Login-button
- Verify the login succeeded by searching for the text Login Success
Enter E-Mail and Password
The first thing we need to do is enter the given values for E-Mail and Password.
Extract the CAPTCHA Value
Now we start with the interactive part 🥳. Extract the value of the text CAPTCHA with get(). We find the text above the textfield that contains the value 123456 and match the CAPTCHA with some TypeScript-RegEx-magic.
Enter the CAPTCHA Value Into the Designated Textfield
Feed the extracted value back to the textfield designated for it. Also lose the focus so we do not interfere with Optical Character Recognition (OCR) when we want to assert the value is really there.
Assert with Jest-Assertions That the Value was Entered Correctly
To assert if the CAPTCHA was entered successfully we will show you two approaches to find the correct textfield and extract its value:
Click the Login-Button
If the assertions do not fail we get to click the Log in-button.
Verify Success with askui Assertions
When developing the code we noticed that sometimes the success window opened in a new browser tab. But sometimes not 😋
So we had to wrap our assertion in a try/catch-block to account for this scenario. If the Success-Page shows in the same browser tab the first instruction will succeed. If not it will throw an error.
In the catch-clause we will then try to switch to the next browser tab and find the Success-message there. If we fail again the login must have failed.
In this tutorial, you learned how to assert values in your UI
With this knowledge, you can now craft your own interactive UI-workflows 😎.
If you have a recurring or persisting issue, don’t hesitate to ask the Discord community for help!
More to explore
Automating WebGL-/Canvas-based Website
WebGL-based websites are becoming increasingly popular among web developers looking to create immersive and interactive user experiences. By drawing graphics and animations directly on the canvas, they offer developers a high degree of creative control over the user interface, providing a more flexible and dynamic platform for graphical compositions. They also offer a more interactive user experience, allowing users to interact with graphics and animations in real-time.
Take a Screenshot with askui - Also on Fail!
When you develop UI-Automations you often run into the problem that they fail inexplicably 😥. This leads to frustration and oftentimes stops the effort entirely! We will show you how can level up your debugging skills by teaching you a way to take screenshots during an askui execution and when on fail of an execution. With this knowledge you can lower your frustration and become faster when developing UI-Workflows because you see what askui sees.