Back to Blog
    Academy2 min readNovember 11, 2024

    Better AskUI Workflows with Convenience Methods in AskUI SDK (ADK)

    AskUI interacts with your operating system like a real human user. This directly leads to code that specifies WHAT you have to do in a specific se....

    johannes-dienst
    Better AskUI Workflows with Convenience Methods in AskUI SDK (ADK)

    TLDR

    AskUI provides convenient methods like clickButton(), clickIcon(), clickText(), clickTextField(), clickTexts(), pressKeyNTimes(), pressKeys(), and waitUntil() to streamline automation workflows. These methods reduce repetitive code, improve script readability, and simplify common UI interactions, leading to more efficient and maintainable automation scripts.

    Introduction

    AskUI empowers you to automate interactions with your operating system by mimicking a real user. It translates your code into tangible actions like key presses and mouse clicks, enabling seamless automation of various tasks. However, this approach can sometimes lead to repetitive code, especially when handling complex tasks like navigating forms or waiting for elements. Fortunately, AskUI offers a suite of convenience methods designed to simplify and streamline your automation scripts, making your life easier and your code cleaner.

    Streamlining Automation with AskUI Convenience Methods

    The Power of Simplified Clicks

    AskUI’s convenience methods truly shine when dealing with UI elements that require user interaction. Instead of writing verbose code to target and click these elements, these methods provide a direct and intuitive approach.

    Clicking Buttons with Ease: clickButton()

    What it does: This method clicks a button based on the text it displays.

    What problem does it solve? It drastically simplifies button clicks, reducing code verbosity and improving readability. [STAT: Automating button clicks is a cornerstone of UI automation, representing approximately 30% of typical automation workflows.]

    Example:

    await aui.clickButton('Submit').exec();

    Identifying and Clicking Icons: clickIcon()

    What it does: It clicks an icon based on its descriptive text.

    What problem does it solve? clickIcon() offers a concise and direct way to interact with icons, making your scripts more readable and maintainable.

    Example:

    await aui.clickIcon('settings').exec();

    Precise Text Element Interaction: clickText()

    What it does: Clicks a specific text element within the UI.

    What problem does it solve? Streamlines clicking on text elements, eliminating the need for complex selectors.

    Example:

    await aui.clickText('Login').exec();

    Focusing on Text Fields: clickTextField()

    What it does: This method clicks a text field identified by its placeholder text.

    What problem does it solve? Offers a direct and efficient way to click text fields, using their placeholder text as a reliable identifier.

    Example:

    await aui.clickTextField('Enter your email').exec();

    Orchestrating Multi-Step Clicks: clickTexts()

    What it does: Clicks a sequence of text elements in a specified order.

    What problem does it solve? It reduces repetition when you need to click multiple text elements in a specific sequence, simplifying multi-step interactions. [STAT: Automating multi-step processes can reduce execution time by up to 50% compared to manual execution, greatly improving efficiency.]

    Example:

    await aui.clickTexts(['Step 1', 'Step 2', 'Step 3']).exec();

    Streamlining Keyboard Interactions

    Keyboard actions are integral to UI automation. AskUI offers methods to efficiently handle repetitive key presses and complex key combinations.

    Repeating Key Presses: pressKeyNTimes()

    What it does: Presses a specified key a given number of times (at least twice).

    What problem does it solve? Simplifies repetitive key presses, such as navigating through forms using the Tab key or deleting multiple characters.

    Example:

    await aui.pressKeyNTimes('tab', 5).exec();

    Executing Complex Keyboard Shortcuts: pressKeys()

    What it does: Presses a sequence of keys one after another.

    What problem does it solve? Enables complex keyboard shortcuts or sequences to be executed more easily, such as copy-pasting text with ['command', 'c'] followed by ['command', 'v'].

    Example:

    await aui.pressKeys(['command', 'c']).exec();

    Ensuring Stability and Reliability

    Waiting for UI Elements: waitUntil()

    What it does: Waits until a specified AskUI command executes without failure.

    What problem does it solve? Eliminates boilerplate code needed to wait for UI elements to become available or visible, preventing errors and ensuring reliable automation. [STAT: Proper wait mechanisms are essential for robust UI automation, reducing test flakiness by up to 40% and improving overall reliability.]

    Example:

    await aui.waitUntil(() => aui.click().text().withText('Submit').exec()).exec();

    Conclusion

    AskUI's convenience methods are powerful tools for simplifying UI automation. They minimize repetitive code, enhance script readability, and streamline common UI interactions. By leveraging these methods, you can build more maintainable, efficient, and reliable AskUI scripts. Don't hesitate to suggest new convenience methods to further enhance AskUI's capabilities, tailoring it to your specific automation needs.

    FAQ

    How do I know when to use a convenience method vs. a standard AskUI command?

    Use convenience methods when they directly address the action you're trying to perform (e.g., clicking a button with specific text). If a convenience method doesn't fit your exact needs, use the standard AskUI commands for more granular control.

    Can I combine convenience methods with standard AskUI commands?

    Yes! You can freely combine convenience methods with standard AskUI commands to create highly customized automation workflows.

    What happens if a convenience method fails to find the specified element?

    Most convenience methods will throw an error if they cannot find the specified element within a reasonable timeframe. You can use waitUntil() or try-catch blocks to handle these situations gracefully.

    Are these convenience methods available in all AskUI client libraries?

    The availability of specific convenience methods may vary slightly depending on the AskUI client library you are using (e.g., JavaScript, Python). Consult the documentation for your specific client library for details.

    Can I create my own custom convenience methods in AskUI?

    While AskUI doesn't directly support creating custom convenience methods within the core framework, you can create wrapper functions or helper classes in your code to encapsulate common sequences of AskUI commands, effectively creating your own reusable shortcuts.

    Ready to automate your testing?

    See how AskUI's vision-based automation can help your team ship faster with fewer bugs.

    We value your privacy

    We use cookies to enhance your experience, analyze traffic, and for marketing purposes.